-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueries.py
152 lines (125 loc) · 4.12 KB
/
Queries.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
import mysql.connector as mysql
from variableValues import host, user, password, port, database, table_user, table_renewables
def establishConnection():
"""
Establishes the connection with the database, sets up the database and tables, and returns the cursor.
"""
# Creating the Connection and the Cursor
mydb = mysql.connect(
host=host,
user=user,
password=password,
port=port
)
mycursor = mydb.cursor(buffered=True)
# Creating the Database
mycursor.execute(
f"CREATE DATABASE IF NOT EXISTS {database};"
)
mycursor.execute(
f"USE {database};"
)
# Creating the Tables
mycursor.execute(
f"""CREATE TABLE IF NOT EXISTS {table_user}
(NAME Varchar(50),
USERNAME Varchar(50),
PASSWORD Varchar(50),
SECURITYKEY Varchar(20),
PHONENUMBER Numeric(13));"""
)
mycursor.execute(
f"""CREATE TABLE IF NOT EXISTS {table_renewables}
(NAME varchar(20) primary key,
TEMPERATUREDEGREE int,
HUMIDITYPERCENTAGE int,
WIND int);"""
)
# Returning the Cursor
return mycursor
def loginQueries():
# creating lists for checking conditions in password check
lstusernamesandpasswords = []
mycursor = establish_connection()
mycursor.execute(
f"""CREATE TABLE IF NOT EXISTS {table_user}
(Name Varchar(50),
Username Varchar(50),
Password Varchar(50),
SecurityKey Varchar(20),
Phoneno Numeric(13));"""
)
# getting the records of the registered users
mycursor.execute(
f"SELECT * FROM {table_user}"
)
myresult = mycursor.fetchall()
for x in myresult:
lstusernamesandpasswords.append(list(x))
# making a separate list of usernames,passwords,securitykeys,and phonenos
lstusernames = []
lstfullname = []
for i in range(len(lstusernamesandpasswords)):
lstusernames.append(lstusernamesandpasswords[i][1])
lstfullname.append(lstusernamesandpasswords[i][0])
mycursor.close()
return (lstusernames, lstfullname)
def signUpQueries():
mycursor = establish_connection()
mycursor.execute(
f"""CREATE TABLE IF NOT EXISTS {table_user}
(Name Varchar(50),
Username Varchar(50),
Password Varchar(50),
SecurityKey Varchar(20),
Phoneno Numeric(13));"""
)
mycursor.execute(
f"""INSERT INTO {table_user} VALUES
("{txtfullname.get()}",
"{txtusername.get()}",
"{txtpassword.get()}",
"{txtsecuritykey.get()}",
{txtphoneno.get()});"""
)
messagebox.showinfo(
'Message title', 'Successfully signed up!'
)
mycursor.close()
def getLocationWeather(user_location):
"""According to the user's inputed location, this function interacts with the API to get info of that place"""
weather_key = APIkey
url = APIurl
params = {'APPID': weather_key, 'q': user_location, 'units': 'Metric'}
response = requests.get(url, params=params)
weather = response.json()
for weather in API_data['list']:
try:
date = weather['dt_txt']
temp = weather['main']['temp']
pressure = weather['main']['pressure']
humidity = weather['main']['humidity']
windspeed = weather['wind']['speed'] * 18 // 5
visibility = weather['visibility']
dates.append(date)
temps.append(temp)
pressures.append(pressure)
windspeeds.append(windspeed)
humidities.append(humidity)
visibilities.append(visibility)
except:
print('There was a problem retrieving that information')
root.destroy()
def settingRenewableBaseValues():
"""
Creates the databases and the table
"""
mycursor = establish_connection()
mycur.execute(
f"""INSERT INTO {table_renewables} VALUES
('SOLAR ENERGY', NULL, NULL, NULL),
('BIOMASS ENERGY', NULL, 50, NULL),
('WIND ENERGY', 15, NULL, 12),
('GEOTHERMAL ENERGY', NULL, NULL, NULL);"""
)
mycursor.close()