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
/
login.py
122 lines (98 loc) · 3.94 KB
/
login.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
# ----------------------------------------- #
# login.pyw #
# Speed_Limit75 #
# Additional contributions by Henry Shires #
# #
# As the name suggests, this file manages #
# logging into the virtual airline. #
# ----------------------------------------- #
# Import libarys
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
import config
import configparser
import web
import json
def login(airline, username, key, rememberMe):
try:
getAirline = airline.get()
getKey = key.get()
getUsername = username.get()
getRememberMe = rememberMe.get()
index = config.List.index(getAirline)
config.changeVar("APIKey", getKey)
config.changeVar("airline", getAirline)
config.changeVar("website", config.websites[index])
data = web.getRaw(config.website + '/api/user')
dataParsed = web.get(config.website + '/api/user')
parser = configparser.ConfigParser()
parser.read("airlines.ini")
sections = parser.sections()
if str(data) == "<Response [200]>":
data = json.loads(data.text)
data = data["data"]["ident"]
if getRememberMe:
parser.set(str(index + 1), "rememberMe", "True")
with open('airlines.ini', 'w') as configfile:
parser.write(configfile)
return True
elif str(data) == "<Response [401]>":
tk.messagebox.showerror("xACARS Error", "Invalid API Key")
else:
data1 = str(data)
if data1.startswith("<Response [") == True:
data = str(data)
data.split("[")
data1 = data[11]
data2 = data[12]
data3 = data[13]
data = data1 + data2 + data3
tk.messagebox.showerror("xACARS Error", "HTML Error: " + data)
else:
tk.messagebox.showerror("xACARS Error", "Error when logging in: " + str(data))
return False
except Exception as e:
tk.messagebox.showerror("xACARS Error", e)
return False
def register(airline, website, username, apiKey):
getAirline = airline.get()
getKey = apiKey.get()
getUsername = username.get()
getWebsite = website.get()
index = 0
while index < len(config.List):
index += 1
accounts = configparser.ConfigParser()
accounts[str(index + 1)] = {'name': getAirline, 'url': getWebsite, 'apikey': getKey, 'username': getUsername, 'rememberMe': False}
with open('airlines.ini', 'a') as configfile:
configfile.write("\n\n")
accounts.write(configfile)
def edit(airline, website, username, apiKey):
getAirline = airline.get()
getKey = apiKey.get()
getUsername = username.get()
getWebsite = website.get()
try:
index = config.List.index(getAirline)
parser = configparser.ConfigParser()
with open('airlines.ini', 'r') as configfile:
parser.read_file(configfile)
parser[str(index + 1)] = {'name': getAirline, 'url': getWebsite, 'apikey': getKey, 'username': getUsername}
with open('airlines.ini', 'w') as configfile:
parser.write(configfile)
tk.messagebox.showinfo("xACARS - Account Updated", "Updated " + getAirline + "! New information will take affect after you sign out.")
except Exception as e:
tk.messagebox.showerror("xACARS Error", e)
def delete(airline):
airline = airline.get()
try:
index = config.List.index(airline) + 1
parser = configparser.ConfigParser()
with open('airlines.ini', 'r') as configfile:
parser.read_file(configfile)
parser.remove_section(str(index))
with open('airlines.ini', 'w') as configfile:
parser.write(configfile)
except Exception as e:
tk.messagebox.showerror("xACARS Error", e)