This repository has been archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
165 lines (139 loc) · 4.16 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# ----------------------------------------- #
# config.py #
# Speed_Limit75 #
# #
# This file read all ini files and sets the #
# variables to reflect their settings. It #
# also make sure all .ini files that are #
# needed exist, somthing that used to be #
# handled by its own file. #
# ----------------------------------------- #
# Import required libarys.
import configparser
import os
import tkinter as tk
from tkinter import messagebox
# Version
version = "v1.0.0-beta1"
# User Fields
airline = ""
website = ""
APIKey = ""
username = ""
# Airlines.ini fields
List = []
websites = []
savedAPIKeys = []
usernames = []
# Settings fields
checkUpdate = False
getPreRel = False
# Changes a variable
def changeVar(x, y):
if x == "website":
global website
website = y
elif x == "airline":
global airline
airline = y
elif x == "APIKey":
global APIKey
y.replace(" ", "")
y = y.strip()
APIKey = y
elif x == "rememberMe":
global rememberMe
rememberMe = y
# Converts a string to a boolean. Used by no external files
def stringToBool(x):
if x == "true":
return True
elif x == "True":
return True
elif x == "false":
return False
elif x == "False":
return False
else:
raise TypeError("Expected True, true, False, or false: not " + x)
# Reloads the list of airlines.
def reloadAirlines():
global List
global websites
global savedAPIKeys
global usernames
config = configparser.ConfigParser()
config.read("airlines.ini")
configSections = config.sections()
List = []
websites = []
savedAPIKeys = []
usernames = []
try:
for key in configSections:
List.append(config[key]['name'])
websites.append(config[key]['URL'])
savedAPIKeys.append(config[key]['apikey'])
usernames.append(config[key]['username'])
except Exception as e:
tk.messagebox.showerror("xACARS Error", e)
def reloadSettings():
global checkUpdate
global getPreRel
# Read the config file and set variables
config = configparser.ConfigParser()
config.read("settings.ini")
# Change the "True/False" variables to a boolean
checkUpdate = stringToBool(config["DEFAULT"]["checkForUpdatesOnStart"])
getPreRel = stringToBool(config["DEFAULT"]["getPreReleaseVersions"])
def reloadIni():
# Make sure all .ini files exist
if os.path.exists('airlines.ini') == False:
file = open("airlines.ini", 'w')
file.write("[DEFAULT]\n")
file.write("name=\n")
file.write("url=\n")
file.write("apikey=None Saved\n")
file.write("rememberMe=False\n")
file.close()
if os.path.exists('settings.ini') == False:
file = open("settings.ini", 'w')
file.write("[DEFAULT]\n")
file.write("checkForUpdatesOnStart = True\n")
file.write("getPreReleaseVersions = False\n")
file.close()
def rememberUser():
global airline
global website
global APIKey
global username
config = configparser.ConfigParser()
config.read("airlines.ini")
configSections = config.sections()
try:
for key in configSections:
if (stringToBool(config[key]["rememberMe"])):
airline = config[key]['name']
website = config[key]['URL']
APIKey = config[key]['apikey']
username = config[key]['username']
return True
return False
except Exception as e:
tk.messagebox.showerror("xACARS Error", e)
return False
def forgetUsers():
config = configparser.ConfigParser()
config.read("airlines.ini")
configSections = config.sections()
try:
for key in configSections:
config[key]["rememberMe"] = "False"
with open('airlines.ini', 'w') as configfile:
config.write(configfile)
except Exception as e:
tk.messagebox.showerror("xACARS Error", e)
return False
reloadIni()
reloadAirlines()
reloadSettings()