-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
300 lines (219 loc) · 6.86 KB
/
main.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
from kivymd.app import MDApp
from Imports.Packages import *
import json
try:
import requests
except:
import requests
from kivymd.uix.menu import MDDropdownMenu
from kivy.properties import ObjectProperty
from datetime import datetime, timedelta
from Lib.GPS.GpsHelper.GpsHelper import GpsHelper
class mainApp(MDApp):
dropdown_date = ObjectProperty()
dropdown_condition = ObjectProperty()
def on_start(self):
# Initialise GPS:
GpsHelper().run()
# cretate dropdown
self.dropdown_date = MDDropdownMenu(width_mult = 3)
# Get today's date
presentday = datetime.now()
# add items to drop date:
self.dropdown_date.items.append(
{"viewclass": "MDMenuItem",
"text": "{}".format(presentday.strftime('%Y-%m-%d')),
"callback": self.option_callback}
)
# adding Tomorrrow's dates :
for i in range(1,6):
# Tomorrow date :
tomorrow = presentday + timedelta(i)
self.dropdown_date.items.append(
{"viewclass": "MDMenuItem",
"text": "{}".format(tomorrow.strftime('%Y-%m-%d')),
"callback": self.option_callback}
)
#create other dropmenu :
self.dropdown_condition = MDDropdownMenu(width_mult=3)
condition_item = ['Tempreature', 'Tempreature Feel', 'Min Tempreature', 'Max Tempreature', 'Humidity',
'Pressure', 'Clouds', 'Wind SpeSed', 'ID','Icon']
for i in range(len(condition_item)):
self.dropdown_condition.items.append(
{"viewclass": "MDMenuItem",
"text": "{}".format(condition_item[i]),
"callback": self.condition_callback}
)
# Check in Profile Database :
try:
connect = sqlite3.connect('Lib\\site_packages\\Profile\\data\\data.db')
cursor = connect.cursor()
# Fentch Name :
cursor.execute("SELECT name FROM todo")
cols = cursor.fetchall()
user_name = cols[0][0]
print(user_name)
app = MDApp.get_running_app()
name = app.root.ids.content_navdrawer.ids.user_name
name.text = 'Welcome, {0}'.format(user_name)
# Fentch Mail name:
cursor.execute("SELECT email FROM todo")
mail = cursor.fetchall()
user_mail = mail[0][0]
gmail = app.root.ids.content_navdrawer.ids.user_gmail
gmail.text = 'Mail: {0}'.format(user_mail)
print(user_mail)
except:
pass
def option_callback(self, text_of_the_option):
bar = BarView()
do = bar.dates(text_of_the_option)
def condition_callback(self, text_of_the_option):
bar = BarView()
do = bar.condition(text_of_the_option)
def build(self):
pass
data = {
'home-city': 'Add City',
'crosshairs-gps': 'Use GPS',
}
def callback(self, instance):
self.task = instance.icon
task = instance.icon
#print(self.root.ids['home_screen'].ids)
if self.task == 'home-city':
self.dialog = MDDialog(title ='Enter City :', size_hint_y= None, padding=10, height='90dp',
type="custom",
content_cls=Content(),
buttons=[
MDRaisedButton(text="CANCEL", on_release= self.closeDialog),
MDRaisedButton(text="OK", on_release= self.auth_city)
]
)
self.dialog.set_normal_height()
self.dialog.open()
else :
app = MDApp.get_running_app()
app.root.ids.screen_manager.current = 'map_screen'
def closeDialog(self, inst):
self.dialog.dismiss()
def auth_city(self, inst):
self.auth = 1
self.add_city(inst)
def map_city(self, inst):
self.map_input = inst
print('map', self.map_input)
self.fentch(inst)
self.map_check_city()
def add_city(self, inst):
#print(self.root.ids['Content_dialog'].ids.city_entered.text)
if self.auth == 1:
for obj in self.dialog.content_cls.children:
if isinstance(obj, MDTextField):
self.input = obj.text
self.input_text = self.root.ids['Content_dialog'].ids['city_entered']
self.input_text.text = self.input
self.auth = 0
inst = self.input
self.fentch(self, inst)
self.check_city()
def check_city(self):
if self.process == 'Go':
print('1')
weather = self.weather
print('2')
try:
if weather['cod'] == '404':
print('1')
toast("City not Found: 404 Error")
else:
self.add_city_to_json()
self.dialog.dismiss()
except:
print('error in Go')
else:
toast('Please Connect to Internet')
def add_city_to_json(self):
self.cities = Cities(name = 'cities')
self.load_file()
def load_file(self):
with open('Lib\\site_packages\\City\\Data\\cities.json') as fd:
data = json.load(fd)
self.cities.data = data
if self.input == '':
toast("Enter Something")
else :
ids = len(self.cities.data)
self.cities.data.append({'name': '{0}'.format(self.input), 'id':'{}'.format(ids) ,'content': ''})
print(self.cities.data)
self.save_file()
def fentch(self, inst, *args):
url = URL()
value = url.get_url()
ID = url.get_id()
try:
city = args[0]
except:
print('map')
print(inst)
city= inst
print('fentch', city, inst, *args)
try :
weather_key = ID
url = value
params = {'APPID' : weather_key, 'q': city, 'units':'metric'}
response = requests.get(url, params=params)
weather=response.json()
self.weather = weather
self.process = 'Go'
print(self.process)
except:
self.process = 'Stop'
print(self.process)
def save_file(self):
with open('Lib\\site_packages\\City\\Data\\cities.json', 'w') as fd:
json.dump(self.cities.data, fd, indent=3)
city_screen = CityScreen()
add = city_screen.load_cities()
self.root.ids.screen_manager.current = 'city_screen'
# Save file Form Map View:
def map_check_city(self):
if self.process == 'Go':
print('1')
weather = self.weather
print('2')
try:
if weather['cod'] == '404':
print('3')
sm = MapDisplay()
msg = sm.message()
print('4')
else:
print('5')
self.map_add_city_to_json()
print('6')
#self.dialog.dismiss()
except:
print('error in Go')
else:
toast('Please Connect to Internet')
def map_add_city_to_json(self):
self.cities = Cities(name = 'cities')
self.map_load_file()
def map_load_file(self):
with open('Lib\\site_packages\\City\\Data\\cities.json') as fd:
data = json.load(fd)
self.cities.data = data
ids = len(self.cities.data)
self.cities.data.append({'name': '{0}'.format(self.map_input), 'id':'{}'.format(ids) ,'content': ''})
print(self.cities.data)
self.map_save_file()
def map_save_file(self):
with open('Lib\\site_packages\\City\\Data\\cities.json', 'w') as fd:
json.dump(self.cities.data, fd, indent=3)
city_screen = CityScreen()
add = city_screen.load_cities()
self.root.ids.screen_manager.current = 'city_screen'
if __name__ == '__main__':
#Window.fullscreen = 'auto'
mainApp().run()