-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolat.pyw
253 lines (221 loc) · 8.52 KB
/
solat.pyw
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
from win32com.client import DispatchEx
import pywintypes
import time
from bs4 import BeautifulSoup
import datetime
import tkinter as tk
from tkinter import messagebox
from pygame import mixer
import threading, os
mixer.init()
def cek_waktu():
global pray_time_today, pray_table, coba, pray_time_today_dt, nama_tk, waktu_tk, tg
ie = DispatchEx('InternetExplorer.Application')
ie.Visible = 0
ie.Navigate("https://jadwalsholat.pkpu.or.id/?id=308")
coba = 0
def coba_ie():
global myfilebox, coba
try:
myfile = open('data.html', 'r')
myfilebox = myfile.read()
myfile.close()
soup = BeautifulSoup(myfilebox,"html.parser")
databulan = soup.find_all('td', {"style":"width: 50%;"})
databulan = databulan[0].find_all('b')[0].contents[0]
databulanskr = datetime.datetime.now()
databulanskr = datetime.datetime.strftime(databulanskr, "%B %Y")
bulan_id = {
'January':'Januari',
'February':'Februari',
'March' : 'Maret',
'April' : 'April',
'May' : 'Mei',
'Juny' : 'Juni',
'July' : 'Juli',
'August' : 'Agustus',
'September' : 'September',
'October' : 'Oktober',
'November' : 'November',
'December' : 'Desember'
}
databulanskr = databulanskr.split(' ')
databulanskr[0] = bulan_id[databulanskr[0]]
databulanskr = ' '.join(databulanskr)
if databulan == databulanskr:
return
else:
os.remove('data.html')
myfile = open('data.html', 'r')
except FileNotFoundError:
try:
myfilebox = ie.Document.body.innerHTML
myfile = open('data.html', 'w')
myfile.write(myfilebox)
myfile.close()
except pywintypes.com_error:
time.sleep(3)
coba += 1
if coba <= 5:
coba_ie()
else:
try:
myfile = open('data.html')
myfilebox = myfile.read()
myfile.close()
except FileNotFoundError:
messagebox.showinfo('Error','Minimal 1x ada koneksi')
root.destroy()
tg = 1
return
coba_ie()
ie.Quit()
soup = BeautifulSoup(myfilebox,"html.parser")
tables = soup.find_all('tr', {"align": "center"})
day = datetime.datetime.now().day
pray_table = tables[day].findAll("td")
pray_time_today = {}
pray_time_today_dt = {}
waktu_skr = datetime.datetime.now()
tahun = waktu_skr.year
bulan = waktu_skr.month
tanggal = waktu_skr.day
shalat_name = ['Tgl', 'Shubuh', 'Dzuhur', 'Ashr', 'Maghrib', 'Isya']
for n in range(1, len(pray_table)):
pray_time_today[shalat_name[n]] = str(pray_table[n].contents[0])
time_shalat = datetime.datetime.strptime(pray_time_today[shalat_name[n]], "%H:%M")
jam = time_shalat.hour
menit = time_shalat.minute
pray_time_today_dt[shalat_name[n]] = datetime.datetime(tahun, bulan, tanggal, jam, menit)
nama_tk = {}
waktu_tk = {}
n = 0
for nama in pray_time_today:
nama_tk[nama] = tk.Label(frame_nama, text=nama, bg='lightblue', padx = 20)
nama_tk[nama].grid(row=n, column=0)
waktu_tk[nama] = tk.Label(frame_nama, text=pray_time_today[nama], padx = 20, bg='white')
waktu_tk[nama].grid(row=n, column=1)
n += 1
def ontop():
global ontop
if ontop == 0:
root.attributes("-topmost", True)
filemenu.entryconfigure(0, label="Always on Top \u2713")
root.attributes("-alpha", .70)
ontop = 1
else:
root.attributes("-topmost", False)
filemenu.entryconfigure(0, label="Always on Top")
root.attributes("-alpha", 1)
ontop = 0
def opensite():
os.startfile('https://jadwalsholat.pkpu.or.id/?id=308')
def threadmain():
global root, frame_nama, waktu_skr, stop_button, filemenu
waktu_skr = datetime.datetime.now()
root = tk.Tk()
icon = resource_path("praying-icon.ico")
root.iconbitmap(icon)
root.resizable(width=False, height=False)
root.title('Waktu Shalat')
frame_nama = tk.Frame(root, bg='lightblue')
frame_nama.grid(row=0, column=0)
frame_button = tk.Frame(root)
frame_button.grid(row=1, column=0, columnspan = 2)
stop_button = tk.Button(frame_button, text='Stop Sound', command=stopazan)
stop_button.pack()
stop_button.configure(state='disabled')
menu = tk.Menu(root)
root.config(menu=menu)
filemenu = tk.Menu(menu, tearoff=0)
menu.add_cascade(label="Help", menu=filemenu)
filemenu.add_command(label="Always on Top", command=ontop)
filemenu.add_command(label="Open Shalat site", command=opensite)
filemenu.add_command(label="Exit", command=onexit)
root.protocol("WM_DELETE_WINDOW", onexit)
root.after(1000, cek_time_shalat)
root.mainloop()
def onexit():
global tg
tg = 1
def cek_time_shalat():
global shalat_selanjut, warna, shalat_sekarang
waktu_skr = datetime.datetime.now()
try:
for waktu in pray_time_today_dt:
if pray_time_today_dt[waktu] < waktu_skr:
shalat_sekarang = waktu
warna = 'light'
if shalat_sekarang == 'Isya':
shalat_selanjut = 'Shubuh'
root.after(3000, highlight)
break
if pray_time_today_dt[waktu] > waktu_skr:
shalat_selanjut = waktu
waktu_tk[shalat_selanjut].config(bg='blue', fg='white')
root.after(3000, highlight)
break
except NameError:
root.after(1000, cek_time_shalat)
def waktu_shalat():
if shalat_sekarang == 'Shubuh':
mixer.music.load(azansubuh)
else:
mixer.music.load(azan)
mixer.music.play()
stop_button.configure(state='normal')
os.startfile(salatpng)
root.after(1000, cek_time_shalat)
def stopazan():
mixer.music.stop()
stop_button.configure(state='disabled')
def highlight():
global warna
waktu_skr = datetime.datetime.now()
waktu_nanti = pray_time_today_dt[shalat_selanjut]
jarak_30min = waktu_skr + datetime.timedelta(minutes = 30)
if waktu_skr >= waktu_nanti:
waktu_tk[shalat_sekarang].config(bg='white', fg='black')
waktu_shalat()
return
if jarak_30min < waktu_nanti:
if warna == 'light':
waktu_tk[shalat_sekarang].config(bg='green', fg='white')
warna = 'dark'
elif warna == 'dark':
waktu_tk[shalat_sekarang].config(bg='light green', fg='black')
warna = 'light'
root.after(3000, highlight)
else:
waktu_tk[shalat_selanjut].config(bg='green', fg='white')
if warna == 'light':
waktu_tk[shalat_sekarang].config(bg='red', fg='white')
warna = 'dark'
elif warna == 'dark':
waktu_tk[shalat_sekarang].config(bg='yellow', fg='black')
warna = 'light'
root.after(3000, highlight)
if shalat_sekarang == 'Shubuh' and pray_time_today_dt[shalat_sekarang]+datetime.timedelta(minutes = 30) < waktu_skr:
waktu_tk[shalat_sekarang].config(bg='white', fg='black')
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
azansubuh = resource_path('azansubuh.mp3')
azan = resource_path('azan.mp3')
salatpng = resource_path('shalat.png')
if __name__ == '__main__':
st = threading.Thread(target=threadmain)
st.daemon = True
st.start()
cek_waktu()
tg = 0
ontop = 0
while 1:
if tg == 1:
root.quit()
break