-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
525 lines (392 loc) · 10.2 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
import re
import json
import sys
import commands
import time
import datetime
import requests
from datetime import datetime
#### local time
a = time.ctime()
rg = '%s%s' %(a[11],a[12])
rg2 = '%s%s' %(a[14],a[15])
g=int(rg)
g2=int(rg2)
#### requesting riyadh prayer times from the link
#r = requests.get('http://muslimsalat.com/riyadh.json')
#### uncomment below to get global based on your location
r = requests.get('http://api.aladhan.com/timingsByCity?city=riyadh&country=sa&method=1')
### getting the data from into a varibal
p= r.text
#xx=json.load(p)
##print p
tt=p.find('timings')
tt2=p.find('}',tt)
tr=p[tt:tt2]
##print tr
tf=tr.find('Fajr')
ttf=tr.find(',',tf)
trf=tr[tf:ttf]
hrf=trf[7:9]
mrf=trf[10:12]
#print hrf
#print mrf
#print trf
td=tr.find('Dhuhr')
ttd=tr.find(',',td)
trd=tr[td:ttd]
hrd=trd[8:10]
mrd=trd[11:13]
#print trd
#print hrd
#print mrd
ts=tr.find('Asr')
tts=tr.find(',',ts)
trs=tr[ts:tts]
had=trs[6:8]
mad=trs[9:11]
#print trs
#print had
#print mad
tm=tr.find('Maghrib')
ttm=tr.find(',',tm)
trm=tr[tm:ttm]
hmd=trm[10:12]
mmd=trm[13:15]
#print trm
#print hmd
#print mmd
ti=tr.find('Isha')
tti=tr.find(',',ti)
tri=tr[ti:tti]
hid=tri[7:9]
mid=tri[10:12]
#print tri
#print hid
#print mid
tn=tr.find('Sunrise')
ttn=tr.find(',',tn)
trn=tr[tn:ttn]
hrn=trn[10:12]
mrn=trn[13:15]
#print trn
#print hrn
#print mrn
te=tr.find('Sunset')
tte=tr.find(',',te)
tre=tr[te:tte]
hren=tre[9:11]
mren=tre[12:14]
#print tre
#print hren
#print mren
fajrh=int(hrf)
fajrm=int(mrf)
duhrh=int(hrd)
duhrm=int(mrd)
asrh=int(had)
asrm=int(mad)
maghrebh=int(hmd)
maghrebm=int(mmd)
ishah=int(hid)
isham=int(mid)
sunriseh=int(hrn)
sunrisem=int(mrn)
sunseth=int(hren)
sunsetm=int(mren)
gh=int(g)
gm=int(g2)
cx=0
def grp():
vv=gh
gm2=g2
global cx
#fajr
if vv >= ishah and vv <= 24 or vv >=0 and vv <= fajrh: ## if time "vv" more or equal to 19 8 isha time or less then 12 midnight or more then 0 12 midnight and less or equal fajer 4 am
if vv == ishah and gm2 <= isham: ## if its equal 17 or 8 pm and minuets equal less then 47 ! then isha
cx=5
elif vv == ishah and gm2 <= isham:
cx=5
elif vv == ishah and gm2 > isham: ## if its equal 17 or 8 pm and minuets more then 47 ! then fajer
cx=1
elif vv == fajrh and gm2 <= fajrm: ## if vv equal 4 and minuets less then 27 ! then fajer
cx=1
else:
cx=1
#duhr
elif vv > fajrh and vv <= duhrh: ## if more then 4 and less or equal then 11 !
if vv == duhrh and gm2 <= duhrm: ## if vv equal 11 and minutes are less or equal 45 then duhr
cx=2
elif vv < duhrh: ## if its less then 11 ! duhr
cx=2
else:
cx=3
#asr
elif vv > duhrh and vv <= asrh: ## if vv more then 11 and less or equal 15
if vv == asrh and gm2 <=asrm: ## if vv eqaul 15 and minuets equal or less then 11 ! then asr
cx=3
elif vv < asrh: ## if vv less then 15
cx=3
else:
cx=4
elif vv > asrh and vv <= maghrebh: ## if vv more then 15 and vv equal or less then 17
if vv == maghrebh and gm2 <= maghrebm: ## if vv equal 17 and minuets less or equal 47! then maghreb
cx = 4
elif vv < maghrebh: ## if vv less then 17 ! then maghreeb
cx=4
else: ## else isha
cx=5
elif vv > maghrebh and vv <=ishah: ## if vv more then 17 and vv equal or less 19
if vv == ishah and gm2 <= isham: ## if vv equal 19 and minuets less or equal 02 ! then isha
cx=5
elif vv < ishah: ## if vv less then 19 ! then isha
cx=5
else: ## else fajer = not more
cx=1
return cx
tt = grp()
#print tt
if tt ==1:
pn="Fajr"
elif tt==2:
pn="Duhr"
elif tt==3:
pn="Asur"
elif tt==4:
pn="Magreeb"
elif tt==5:
pn="Esha"
had=int(had)-12
hmd=int(hmd)-12
hid=int(hid)-12
hren=int(hren)-12
def tooa():
arr = time.ctime()
rgrr = '%s%s' %(arr[11],arr[12])
rg2rr = '%s%s' %(arr[14],arr[15])
#rgrr="19"
#rg2rr="11"
xr=arr[11]
if tt>2 :
rgrr=int(rgrr)-12
#print rgrr
g=str(rgrr) + ":" + rg2rr + ":" + "00"
gfT=hrf + ":" + mrf + ":" + "00"
gdT=hrd + ":" + mrd + ":" + "00"
gaT=str(had) + ":" + mad + ":" + "00"
gmT=str(hmd) + ":" + mmd + ":" + "00"
giT=str(hid) + ":" + mid + ":" + "00"
fmt = '%H:%M:%S'
if tt==1:
pn="Fajr"
d1 = datetime.strptime(g, fmt)
d2 = datetime.strptime(gfT, fmt)
diff = d2-d1
qq=str(diff)
css="Prayer Fajr in: %s " % qq
elif tt==2:
pn="Duhr"
d1 = datetime.strptime(g, fmt)
d2 = datetime.strptime(gdT, fmt)
diff = d2-d1
qq=str(diff)
css="Prayer Duhr in: %s " % qq
elif tt==3:
pn="Asr"
d1 = datetime.strptime(g, fmt)
d2 = datetime.strptime(gaT, fmt)
diff = d2-d1
qq=str(diff)
css="Prayer Asr in: %s " % qq
elif tt==4:
pn="Maghreeb"
d1 = datetime.strptime(g, fmt)
d2 = datetime.strptime(gmT, fmt)
diff = d2-d1
qq=str(diff)
css="Prayer Maghreeb in: %s " % qq
elif tt==5:
pn="Isha"
d1 = datetime.strptime(g, fmt)
d2 = datetime.strptime(giT, fmt)
diff = d2-d1
qq=str(diff)
css="Prayer Isha in: %s " % qq
return css
cssd=tooa()
faj=str(hrf)+":" + str(mrf)
duh=str(hrd)+":" + str(mrd)
asrr=str(had)+":" + str(mad)
mage=str(hmd)+":" + str(mmd)
ish=str(hid)+":" + str(mid)
ris=str(hrn)+":" + str(mrn)
seet=str(hren)+":" + str(mren)
grgr=int(rg)
if grgr>12:
rg=grgr-12
d22=str(rg)+":"+str(rg2)
class LabelWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Prayer Times in Riyadh")
self.set_border_width(11)
hbox = Gtk.Box(spacing=12)
hbox.set_homogeneous(True)
self.add(hbox)
vbox_left = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=11)
vbox_left.set_homogeneous(False)
vbox_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=11)
vbox_right.set_homogeneous(False)
vbox_top = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
vbox_top.set_homogeneous(False)
vbox_buttom = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
vbox_buttom.set_homogeneous(False)
hbox.pack_start(vbox_left, True, True, 0)
hbox.pack_start(vbox_right, True, True, 0)
label = Gtk.Label("time now:")
label.set_justify(Gtk.Justification.LEFT)
vbox_left.pack_start(label, True, True, 1)
label = Gtk.Label("Fajer")
label.set_name('L1')
label.set_justify(Gtk.Justification.LEFT)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label("Duhr")
label.set_justify(Gtk.Justification.RIGHT)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label("Asur")
label.set_justify(Gtk.Justification.RIGHT)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label("Maghrib")
label.set_line_wrap(True)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label("Isha")
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label("UpComing Prayer")
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label("sunrise")
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label("sunset")
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_left.pack_start(label, True, True, 0)
############## start the lef vbox
label = Gtk.Label(a)
label.set_justify(Gtk.Justification.LEFT)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label(faj)
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label(duh)
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label(asrr)
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label(mage)
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label(ish)
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label(cssd)
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label(ris)
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label(seet)
label.set_line_wrap(True)
label.set_justify(Gtk.Justification.FILL)
vbox_right.pack_start(label, True, True, 0)
button = Gtk.Button("Close")
button.connect("clicked", self.onButtonPressed)
hbox.pack_end(button, True, True, 0)
def onButtonPressed(self, button):
Gtk.main_quit()
def main(argv):
def gtk_style():
css = b"""
GtkWindow {
}
L1 {
color: blue;
background-color: #BC0909;
border-style: outset;
border-color: #333;
padding: 8px 4px;
border-radius: 13px;
font-size:21px;
transition: 0.3s;
border-right: none;
}
.label {
box-shadow: 3px 5px 5px #888888;
color: white;
background-color: #525252;
border-style: outset;
border-color: #333;
padding: 18px 18px;
border-radius: 13px;
font-size:14px;
transition: 0.3s;
border-right: none;
}
.button button {
color: green;
background-color: shade (@bg_color, 1.44);
border-style: inset;
border-width: 2px 0 2px 2px;
border-color: #333;
padding: 12px 4px;
border-radius: 32px;
}
.button:first-child {
border-radius: 13px 0 0 5px;
}
.button:last-child {
border-radius: 10px 5px 5px 0;
border-width: 2px;
}
.button:hover {
padding: 12px 48px;
background-color: shade (@bg_color, 1.06);
}
.button *:hover {
color: white;
}
.button:hover:active,
.button:active {
background-color: shade (@bg_color, 0.85);
}
"""
style_provider = Gtk.CssProvider()
style_provider.load_from_data(css)
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
gtk_style()
win = LabelWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
main(sys.argv)