-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull_code.py
303 lines (244 loc) · 9.22 KB
/
full_code.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
301
302
303
#!/usr/bin/env python3
# Created by Marwan Mashaly
# Created on January 2020
# This program is a smart clock that shows news, weather, calendar and time
import pyowm
from tkinter import Tk, Frame
from tkinter.ttk import *
import tkinter as tk
from time import strftime
# import datetime
import requests
from PIL import ImageTk, Image
from tkinter import *
from tkcalendar import *
from gpiozero import Button
root = Tk()
root.title('Smart Clock')
root.geometry("+200+200")
# root.configure(background = "black")
# defining buttons
button1 = Button(26)
button2 = Button(19)
button3 = Button(6)
button4 = Button(5)
button5 = Button(16)
# creating frames for each function
news_frame = tk.Frame(root, bg='black')
news_frame.grid()
weather_frame = tk.Frame(root, bg='sky blue')
weather_frame.grid()
clock_frame = tk.Frame(root, bg='black')
clock_frame.grid()
calendar_frame = tk.Frame(root, bg='white')
calendar_frame.grid()
time_frame = tk.Frame(root, bg='black')
time_frame.grid()
def calendar():
# This function gets the calendar
cal = Calendar(calendar_frame)
cal.grid()
def news():
# This function runs the news
root.configure(background="grey")
label = Label(news_frame, text="NEWS", font=('calibri', 25),
foreground='white', background='grey')
label.grid()
url = 'https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apikey=e4ba43e5a4e54ab8a1d130127eeb888a'
# Make the request
response = requests.get(url).json()
article = response["articles"]
# Convert the response to JSON format
# creating a list to accept api calls
lstbox = Listbox(news_frame)
lstbox.config(bg='grey', fg='white', width='100', height='30',
font='Helvetica')
lstbox.grid()
# showing the list in the gui
for item in article:
lstbox.insert(END, item['title'], "\ndetails: ", item['description'])
def forecast():
# This function shows the weather through weathermap api
# creating the labels in the weather frame
root.configure(background="sky blue")
label = Label(weather_frame, text="Weather", font=('calibri', 25),
foreground='yellow', background='sky blue')
label2 = Label(weather_frame, text="Humidity (in percentage) :", font=('calibri', 16),
foreground='white', background='sky blue')
label3 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
label4 = Label(weather_frame, text="rain : ", font=('calibri', 16),
foreground='white', background='sky blue')
label5 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
label6 = Label(weather_frame, text="snow :", font=('calibri', 16),
foreground='white', background='sky blue')
label7 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
label8 = Label(weather_frame, text="fog :", font=('calibri', 16),
foreground='white', background='sky blue')
label9 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
label10 = Label(weather_frame, text="Temprature in Celsius :",
font=('calibri', 16),
foreground='white', background='sky blue')
label11 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
label12 = Label(weather_frame, text="weather details",
font=('calibri', 16),
foreground='white', background='sky blue')
label13 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
label14 = Label(weather_frame, text="Wind Speed", font=('calibri', 16),
foreground='white', background='sky blue')
label15 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
label16 = Label(weather_frame, text="Cloud coverage (in percent) :",
font=('calibri', 16), foreground='white',
background='sky blue')
label17 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
label20 = Label(weather_frame, text="location : ", font=('calibri', 16),
foreground='white', background='sky blue')
label21 = Label(weather_frame, text="", font=('calibri', 12),
foreground='white', background='sky blue')
# showing the label in the gui in a ccertain location through grid
label.grid(row=1, column=1)
label2.grid(row=13, column=0)
label3.grid(row=13, column=2)
label4.grid(row=6, column=0)
label5.grid(row=6, column=2)
label6.grid(row=7, column=0)
label7.grid(row=7, column=2)
label8.grid(row=8, column=0)
label9.grid(row=8, column=2)
label10.grid(row=9, column=0)
label11.grid(row=9, column=2)
label12.grid(row=10, column=0)
label13.grid(row=10, column=2)
label14.grid(row=11, column=0)
label15.grid(row=11, column=2)
label16.grid(row=12, column=0)
label17.grid(row=12, column=2)
label20.grid(row=5, column=0)
label21.grid(row=5, column=2)
# calling the api
owm = pyowm.OWM('3a65677897148889d39423a3ce8e1716')
# You MUST provide a valid API key
ottawa = owm.three_hours_forecast('Ottawa, Canada')
# location
loc = "Ottawa"
label21.config(text=loc)
# asks the api for weather details
fog = ottawa.will_have_fog()
rain = ottawa.will_have_rain()
snow = ottawa.will_have_snow()
# shows images depending on weather state
# if snow == 1 or clouds and snow == 1:
# load = Image.open("snow.jpeg")
# render = ImageTk.PhotoImage(load)
# img = Label(root, image=render)
# img.image = render
# img.place(x=650, y=40)
# elif clouds == 0:
# load = Image.open("sun.jpeg")
# render = ImageTk.PhotoImage(load)
# img = Label(root, image=render)
# img.image = render
# img.place(x=650, y=40)
# if snow and rain and clouds == 1:
# Image.open("mix.jpeg")
# render = ImageTk.PhotoImage(load)
# img = Label(root, image=render)
# img.image = render
# img.place(x=650, y=40)
# elif clouds == 0:
# Image.open("sun.jpeg")
# render = ImageTk.PhotoImage(load)
# img = Label(root, image=render)
# img.image = render
# img.place(x=650, y=40)
# depending on weather state show if it's happening or no
if rain == 1:
rain = "there is rain today"
else:
rain = "there is no rain today"
if snow == 1:
snow = "there is snow today"
else:
snow = "there is no snow today"
if fog == 1:
fog = "there is fog today"
else:
fog = "there is no fog today"
# if clouds == 1:
# clouds = "there is clouds today "
# else:
# clouds = "there is no clouds today"
# showing the labels
label5.config(text=rain)
label7.config(text=snow)
label9.config(text=fog)
# calling api for different funcion
ott = owm.weather_at_place('Ottawa, Canada')
weather = ott.get_weather()
humidity = weather.get_humidity()
label3.config(text=humidity)
temp = weather.get_temperature('celsius')['temp']
temp = round(temp)
label11.config(text=temp)
description = weather.get_detailed_status()
label13.config(text=description)
wind = weather.get_wind()
label15.config(text=wind)
cloud_cov = weather.get_clouds()
label17.config(text=cloud_cov)
def time():
#
labl = Label(time_frame, text="", font=('calibri', 40),
foreground='white', background='black')
labl.grid(row=1, column=0)
string = strftime('%H:%M:%S \n%d-%m-%Y')
labl .config(text=string)
labl.after(1000, main)
def main():
# This function gets the time and date and calls other function
label18 = Label(clock_frame, text="", font=('calibri', 40),
foreground='white', background='black')
label18.grid(row=0, column=0)
string = strftime('%H:%M:%S \n%d-%m-%Y')
label18.config(text=string)
label18.after(1000, main)
# if button state changes call the function associated with it
if button1.is_pressed:
weather_frame.grid_forget()
clock_frame.grid_forget()
calendar_frame.grid_forget()
time_frame.grid_forget()
news_frame.grid()
news()
if button2.is_pressed:
news_frame.grid_forget()
time_frame.grid_forget()
clock_frame.grid_forget()
weather_frame.grid()
forecast()
if button3.is_pressed:
import alarm
if button4.is_pressed:
news_frame.grid_forget()
weather_frame.grid_forget()
time_frame.grid_forget()
clock_frame.grid_forget()
calendar_frame.grid()
calendar()
if button5.is_pressed:
news_frame.grid_forget()
weather_frame.grid_forget()
clock_frame.grid_forget()
calendar_frame.grid_forget()
time_frame.grid()
time()
if __name__ == "__main__":
main()
root.mainloop()