forked from CatalystMonish/Co-Win-Notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Co-Win Notifier v3.2.py
1555 lines (1179 loc) · 56.1 KB
/
Co-Win Notifier v3.2.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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#------------------------------------------
#Co-Win Notifier v3.2
#
#17 June 2021
#https://github.com/ashvnv/Co-Win-Notifier
"""
MIT License
Copyright (c) 2021 Ashwin Vallaban and Monish Meher
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
#Changelog v3.2:
# Plays alert tone when slot is found [sound.wav in data/]
#Changelog v3.1:
# Added Azure ttk theme [v1.3] # Copyright (c) 2021 rdbende <rdbende@gmail.com> | https://github.com/rdbende/Azure-ttk-theme
# Slot retry time reduced to 3.1 Seconds
# UI improvements
# Added start window which shows the startup operations performed by the app (checking network[1], checking for updates[2], getting vaccine data[3]). Start window operations are threaded
# App now reads the vaccine data (vaccine name, API JSON search name) from github repository [https://raw.githubusercontent.com/ashvnv/miscellaneous/main/updates/vaccinedatab.txt]
# and accordingly enables or disables the vaccine checkbox
# Added try-except block wherever the program performs networking operation and accordingly gives indication to the user if error occurs
#Changelog v3:
# [\d.]+ <- Regex updated for getting app latest version | now supports app version number in decimal
# Radio buttons changed to checkboxes (for free, paid slots options)
# Added vaccine name filter (Sputnik V, Covishield, Covaxin)
# Added back button in pinmode, district and slots retry window
# Changed slot retry time to 3.5 Seconds from 5 seconds (Now making approx. 85 calls are made in 5 minutes [100 calls limit in 5 minutes])
# Auth code digits reduced to 6 from 8
# Lot of bug fixes and UI improvements
#Changelog v2:
# Added Telegram alert
# Does auth process between user and bot and bot and user
# chatid is saved in the telcofig.txt file so that after rebooting the program, configuring the telegram is not required
# telcongif.txt saved in current program directory
# Vaccine search filer:
# Search based on Age filer [18+ and 45+]
# Search slots based on first or second dose
# Search for paid or free vaccine slots
# tkinter main frame is made inside mainf(), this was necessary because easygui could not render images so tkinter root is destroyed while easygui is called during configuring telegram alert
#
# pin wise and district wise slots find functions were updated, some redundant codes were removed
#
# some variables had to be declared global as tkinter is declared inside the mainf() and scope in python won't modifiy the global value of the variable
#
# Added update feature. When the app is launched, it checks for update from github repository. If update is available, a prompt is shown for updating the app to the latest version
#
#Data files:
#----------image------------
#these files are stored in data folder
#data/qr-code.png
#data/bot.png
#data/github.png
#data/happybot.png
#data/icon.ico
#data/instagram.png
#data/qr-code.png
#data/sadbot.png
#data/splash.png
#data/update.png
#data/nonet.png
#----------doc------------
#stored in website folder
#website/slot.html
#
#-------Azure-dark------
#All files added
#------------App version-----------------
current_ver = 3.2
base_ver = int(current_ver) #remove fractional part
#----------------------------------------
from tkinter import *
import os
import webbrowser
import datetime
from datetime import timedelta
import time
from threading import Timer
import requests
from urllib.request import urlopen, Request
import json
from threading import Thread
import sys
import threading
#-------------------
import platform
import getpass
#------------------
#-------------easygui--------------
from easygui import *
import sys
#-----------telegram---------------
import urllib.request
#used while checking updates
import re
#
from tkinter import ttk #For theme
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
def raise_issue():
webbrowser.open('https://github.com/ashvnv/miscellaneous')
#----------------------------------------App init checks---------------------------------------------------------
global INIT_DONE
INIT_DONE = False # when init done completely it is made True
def updateAppLink():
webbrowser.open('http://bit.ly/cowinnotifierIO')
def quitinit():
startroot.destroy()
sys.exit("Terminated init by user")
################################# Update App Vaccine database #############################
def vacData_file(wrt):
# if wrt = 0: file read mode
if wrt == 0:
return open('vacData.txt',"r+").readline()
else:
telconfigw = open('vacData.txt', 'w')
telconfigw.write(str(wrt))
telconfigw.close()
return True
global VacData
VacData = [] # Buttons read this list
def VaccDat(): # Update app vaccine database
print('VaccDat()')
statmsg['text'] = 'Updating vaccine data...'
statmsg['fg'] = 'gray'
#-----------------------------GitHub vac database-------------------------------
try:
update_chk = requests.get('https://raw.githubusercontent.com/ashvnv/miscellaneous/main/updates/vaccinedatab.txt').content
print('response:' + str(update_chk))
dat_temp = re.findall(r'[#][\w -]+[#]', str(update_chk))
dat_size = len(dat_temp)
print('Database size: ' + str(dat_size))
if (dat_size == 27):
vacData_file(dat_temp) # write to local file
print('Written to local database')
for dat in dat_temp:
VacData.append(re.findall(r'[\w -]+', dat)[0])
return
except:
print('Exception raised')
#-------------------------Local vac database----------------------------------
print('Error reading the vaccine database.')
if (os.path.exists('vacData.txt')):
print('Local database exits.. Reading....')
#print(vacData_file(0)) #read
dat_temp = re.findall(r'[#][\w -]+[#]', vacData_file(0))
print('Local database read')
dat_size = len(dat_temp)
print('Database size: ' + str(dat_size))
if (dat_size == 27):
for dat in dat_temp:
VacData.append(re.findall(r'[\w -]+', dat)[0])
return
print('local database... Error')
raise Exception("Vaccine database read error")
####################################### Update check ######################################
def AppUpdate():
print('AppUpdate()')
statmsg['text'] = 'Searching for updates...'
statmsg['fg'] = 'gray'
update_chk = requests.get('https://raw.githubusercontent.com/ashvnv/miscellaneous/main/updates/cowinnotifier.txt').content
print('response:' + str(update_chk))
update_ver=re.findall(r'[\d].[\d]', re.findall(r'#[\d].[\d]#', str(update_chk))[0])[0]
#update_ver=re.findall(r'[\d].[\d]', re.findall(r'#[\d].[\d]#', '5.0 #3.9# 4.0 5.6')[0])[0] #<version num>#
print('Regex: ' + str(update_ver))
print ('Latest Version: ' + update_ver)
if (current_ver < float(update_ver)): #update found
#-----------------Update available frame-------------------------------
print('Update available')
pb.place_forget()
statmsg['text'] = 'Update available | Current: v' + str(current_ver)
statmsg['fg'] = '#87CEEB'
func_button['text']='Update to v' + update_ver
func_button['command']=updateAppLink
func_button.place(x=150,y=30, anchor='center')
return True
return False
####################################### Check network ###################################
global PING_URL
google_ping = 'http://google.com'
bing_ping = 'http://bing.com' # backup ping addres
def check_conn(link):
print('check_conn()')
global PING_URL
PING_URL = link
print(PING_URL)
try:
urllib.request.urlopen(PING_URL)
return 0
except:
print('ping failed')
if PING_URL == bing_ping:
return 1
return check_conn(bing_ping)
def connection():
print('connection()')
#place progress bar
pb.place(x=150,y=30, anchor='center')
#remove func button
func_button.place_forget()
statmsg['text'] = 'Checking network...'
statmsg['fg'] = 'gray'
if check_conn(google_ping) == 1:
print('No internet')
statmsg['text'] = 'No internet!'
statmsg['fg'] = '#F7347A'
pb.place_forget()
func_button['text']='Try Again'
func_button['command']=createThreadinit # add button command, create new thread
func_button.place(x=150,y=30, anchor='center')
else:
print('Ping successful')
try:
if (AppUpdate()): #check for app updates
return
except:
print('Update check failed. skipped..')
try:
VaccDat() # update vaccine database
except:
print('Exception raised inside VaccDat()')
statmsg['text'] = 'Error occurred!'
statmsg['fg'] = '#F7347A'
pb.place_forget()
func_button['text']='Try Again'
func_button['command']=createThreadinit # add button command, create new thread
func_button.place(x=150,y=30, anchor='center')
return
#------Start app-----------
global INIT_DONE
INIT_DONE = True # make flag true
#---------------launch app------------------------
statmsg['text'] = 'launching app...'
statmsg['fg'] = 'gray'
startroot.after(1000, startroot.destroy) #init done
return
##################################### Init window #######################################
global pb, func_button, issue_button, exit_button, statmsg, startroot
def createThreadinit():
# Create a Thread with a function without any arguments
th = threading.Thread(target=connection) # check internet connectivity
# Start the thread
th.start()
def disable_event(): # close button removed
pass
def initWindow():
global pb, func_button, issue_button, exit_button, statmsg, startroot
startroot = Tk()
startroot.geometry('300x160')
startroot.title('Starting Co-Win Notifier')
startroot.resizable(width=False, height=False)
startroot.protocol("WM_DELETE_WINDOW", disable_event)
#---------------------Theme------------------------------
### Here are the three lines by which we set the theme ###
# Create a style
global style
style = ttk.Style(startroot)
# Import the tcl file
startroot.tk.call('source', 'azure-dark.tcl')
# Set the theme with the theme_use method
style.theme_use('azure-dark')
#---------------------------------------------------------
# progress bar
pb = ttk.Progressbar(
startroot,
orient='horizontal',
mode='indeterminate',
length=280
)
#progress bar placed inside connection()
pb.start([5])
# func button displayed in place of progress bar
func_button = ttk.Button(
startroot,
text='NA',
style='AccentButton',
)
# raise an issue button ##add command
issue_button = ttk.Button(
startroot,
text='Raise an issue',
command=raise_issue
)
issue_button.place(x=80, y=85, anchor='center')
# exit button
exit_button = ttk.Button(
startroot,
text='Quit',
command=quitinit
)
exit_button.place(x=220, y=85, anchor='center')
# stat message
statmsg = Label(startroot, text = "Initializing...", fg="gray")
statmsg.place(x=150, y=135, anchor="center")
createThreadinit()
startroot.mainloop()
initWindow()
#-------------------------------------------------
# check if init process completed successfully
if (INIT_DONE == False):
sys.exit("Init failed")
print('Init done')
################################ Init done ####################################
#-----------------Telegram configure------------------------------------------------------------------------------
global telegram_alert
telegram_alert = False
global telchatid
#---------------------------
#url not disclosed due to privacy concerns
telurl = 'https://api.telegram.org/' + 'bot<>' #TOKEN REMOVED
#func returns true is send successful
def send_telegram_message(msg):
# """Sends message via Telegram"""
global telchatid
data = {
"chat_id": telchatid,
"text": msg + '\n\nCo-WIN site\nhttps://selfregistration.cowin.gov.in/\n-----------------------------------\n\
This message was sent from Co-Win Notifier software running on ' + platform.system() + ' ' + platform.release() + '\nUsername: ' + getpass.getuser() + '\n\n\
Bot will never send messages automatically. If you received this message without running the Co-Win Notifier immediatety block the bot'
}
try:
response = requests.request(
"POST",
telurl + '/sendMessage',
params=data
)
print("This is the Telegram response")
print(response.text)
telegram_data = json.loads(response.text)
return True
except Exception as e:
print("An error occurred in sending the alert message via Telegram")
print(e)
return False
#---------------------------find auth code------------------------------------
#updates telchatid variable if authcode text found
def tel_find_chat_id(authcode):
tel_temp = urllib.request.urlopen(telurl + '/getUpdates')
tel_string = tel_temp.read().decode('utf-8')
tel_json_obj = json.loads(tel_string)
print(tel_json_obj)
for temp_tel in tel_json_obj['result']:
if 'message' in temp_tel: ### if no 'message key' skip!
print(temp_tel['message']['text'] + ' text found')
if temp_tel['message']['text'] == authcode:
print('found, chat id: ' + str(temp_tel['message']['chat']['id']))
global telchatid
telchatid = str(temp_tel['message']['chat']['id'])
print(str(tel_config_file(telchatid)) + ': chat id written to telconfig.txt')
return True
#------------------------send auth code---------------------------------------
#if auth code received! auth successful
def auth_code_gen():
#return 6 digit random int
return str(time.time_ns())[13:]
#---------------------------------------------------------------------------------
#----------------------------telegram configure read------------------------
#configuration saved as a txt file with chat id.
def tel_config_file(wrt):
# if wrt = 0: file read mode
if wrt == 0:
if os.path.exists('telconfig.txt'):
tel_readconfig = open('telconfig.txt',"r+")
temp = tel_readconfig.readline()
if temp.isdigit():
global telchatid
telchatid = temp # update the id
tel_readconfig.close()
return True
else:
return False
else:
return False
else:
telconfigw = open('telconfig.txt', 'w')
telconfigw.write(wrt)
telconfigw.close()
return True
#----------------------------------easygui--------------------------------------------------------------------------------------------
#using easygui for configuring telegram alert
easytitle = "Co-Win Notifier v" + str(base_ver) + " Telegram alert"
def tel_easygui1():
#-----------------easygui first frame-------------------------------
easymsg = "Welcome! The bot will send you alerts when slots are found\n\nOpen the chatbot in Telegram:\
\n*Search for the bot in Telegram search bar: Co-Win Notifier v" + str(base_ver) + "\nor\n*Open this link:\nt.me/co_win_notifier_bot \nor \n\
*Scan the QR code below using any QR code scanner\n------------------------------------------\n\
Make sure the bot profile photo matches with the one given in the QR code below\nOnce your found the bot click on 'Next' below the QR code"
#image acts as a button in easygui. clicking on the image gives invalid value, so loop makes sure image button not clicked
easybutton_list = ['Next','Raise an issue', 'Cancel']
easyclknull = True
while(easyclknull):
easyclk = buttonbox(easymsg, easytitle, image = resource_path("data/qr-code.png"), choices = easybutton_list)
if easyclk in easybutton_list:
easyclknull = False #found button
return easyclk
def tel_easygui2(auth_code):
#-----------------easygui second frame------------------------------ user to bot auth
#get unique number from telegram func and display
easymsg = "Now lets authenticate! Send this unique number to the bot: \n\n" + auth_code + "\n\n\
Once you sent the code click on 'Next' below. This window may not be visible for some seconds. The program is trying to search your message from the server and may take some time to load!!!!\n\n\
Meantime you can check your telegram to see if the bot has sent you received message"
easybutton_list = ['Next','Raise an issue', 'Cancel']
easyclknull = True
while(easyclknull):
easyclk = buttonbox(easymsg, easytitle, image = resource_path("data/bot.png"), choices = easybutton_list)
if easyclk in easybutton_list:
easyclknull = False #found button
return easyclk
#--------------------could not auth------------------------------------
def tel_easygui3(auth_code):
easymsg = "Heyyy I did not get your message! Sure you sent the correct code?\n\n" + auth_code
easybutton_list = ['Try again','Raise an issue', 'Cancel']
easyclknull = True
while(easyclknull):
easyclk = buttonbox(easymsg, easytitle, image = resource_path("data/sadbot.png"), choices = easybutton_list)
if easyclk in easybutton_list:
easyclknull = False #found button
return easyclk
def tel_easygui4():
#-----------------easygui second frame------------------------------ bot to user auth
easymsg = "Woohoo! I got your code! Let me make sure it was you only.\n\nI have sent another code to you. Enter that in the box\n\nIf code not received, keep the box blank and click OK"
easytxt = enterbox(easymsg, easytitle)
return easytxt
#---------------cound not auth-----------------------------------------------------------
def tel_easygui5():
easymsg = "Hey thats not what I sent! Try again\n\nGo back if you did not receive the code"
easybutton_list = ['Try again','Go back','Raise an issue', 'Cancel']
easyclknull = True
while(easyclknull):
easyclk = buttonbox(easymsg, easytitle, image = resource_path("data/sadbot.png"), choices = easybutton_list)
if easyclk in easybutton_list:
easyclknull = False #found button
return easyclk
#---------------------final confirm----------------------------------
def tel_easygui6():
easymsg = "Amazing! You have been authenticated. I will send you alerts as soon as slots are available!\n\nYou can send a message to me from the textbox below and I will forward the same message \
to you on Telegram. Write anything your want or you can exit the telegram configure"
easybutton_list = ['Exit','Send message','Raise an issue']
easyclknull = True
while(easyclknull):
easyclk = buttonbox(easymsg, easytitle, image = resource_path("data/happybot.png"), choices = easybutton_list)
if easyclk in easybutton_list:
easyclknull = False #found button
return easyclk
#simple msg send from user
def tel_easygui7():
easymsg = "Try sending a message. If you are not receiving the message, try configuring the the telegram alert again from the start"
easytxt = textbox(easymsg, easytitle, 'Type here')
return easytxt
#--------------------main easygui func----------------------------------------------------------
def tel_easygui_configure():
root.destroy() #tkinter throws exception when easygui renders images
tel_para = tel_easygui1() #call first frame
if (tel_para == 'Cancel'):
mainf(0) #recreate main frame
return
elif (tel_para == 'Raise an issue'):
raise_issue()
mainf(0) #recreate main frame
return
#---------------------------------------------------------------------
#auth between bot and user
tel_guiloop2 = True
while(tel_guiloop2):
auth_code = auth_code_gen()
tel_guiloop = True
while(tel_guiloop):
tel_para = tel_easygui2(auth_code) #user to bot auth
if (tel_para == 'Cancel'):
tel_config_file('NA') #clear found chat id
mainf(0) #recreate main frame
return
elif (tel_para == 'Raise an issue'):
raise_issue()
tel_config_file('NA') #clear found chat id
mainf(0) #recreate main frame
return
elif tel_find_chat_id(auth_code): #if func returned True authcode verified
tel_guiloop = False #Authcode verified
else:
tel_para = tel_easygui3(auth_code)
if (tel_para == 'Cancel'):
tel_config_file('NA') #clear found chat id
mainf(0) #recreate main frame
return
elif (tel_para == 'Raise an issue'):
raise_issue()
tel_config_file('NA') #clear found chat id
mainf(0) #recreate main frame
return
auth_code = auth_code_gen()
tel_guiloop = True
while(tel_guiloop):
send_telegram_message('Auth code: ' + auth_code + '\nEnter this code in the Co-Win Notifier software') #send the code to user
tel_para = tel_easygui4() #bot to user auth
if tel_para == auth_code:
tel_guiloop = False #auth complete
tel_guiloop2 = False #break auth loop and go to next section
else:
tel_para = tel_easygui5()
if tel_para == 'Go back':
tel_guiloop = False #repeat user to bot auth
elif tel_para == 'Cancel':
tel_config_file('NA') #clear found chat id
mainf(0) #recreate main frame
return
elif (tel_para == 'Raise an issue'):
raise_issue()
tel_config_file('NA') #clear found chat id
mainf(0) #recreate main frame
return
#---------------------------------------------------------------------------
tel_guiloop = True
while(tel_guiloop):
tel_para = tel_easygui6() #final frame
if (tel_para == 'Raise an issue'):
raise_issue()
tel_config_file('NA') #clear found chat id
mainf(0) #recreate main frame
return
elif (tel_para == 'Send message'):
tel_para = tel_easygui7()
if tel_para == None:
print('None')
else:
send_telegram_message(tel_para)
else:
tel_guiloop = False
global telegram_alert
#telegram_alert = True # turn on the telegram alerts | set in mainf()
mainf(0) #recreate main frame
#---------------------------------------------------------------------------------
global data_dir
data_dir = resource_path("data")
global website_dir
website_dir = resource_path("website")
def open_link_github():
webbrowser.open('www.github.com/CatalystMonish')
def open_link_instagram():
webbrowser.open('www.instagram.com/meher._.catalyst')
def splashWin():
canvas.destroy()
#------------
global vaccOP
def vaccinechkboxveri(): # verify checkboxes | returns false if no checkbox selected else updates vaccOP list and returns True
global vaccOP
if (vacc1.get() + vacc2.get() + vacc3.get() + vacc4.get() + vacc5.get() + vacc6.get() + vacc7.get() + vacc8.get() + vacc9.get() == '000000000'):
return False
vaccOP = f'{vacc1.get()} {vacc2.get()} {vacc3.get()} {vacc4.get()} {vacc5.get()} {vacc6.get()} {vacc7.get()} {vacc8.get()} {vacc9.get()}'.split(' ')
print(vaccOP) # updated vaccOP
return True
#---------------Back button------------------------
def backmain():
root.destroy()
mainf(0) #recreate main frame
def backbtn():
global backbtnimg
backbtnimg= PhotoImage(file=resource_path('data/back.png'))
back_btn= ttk.Button(root, text='Back', image=backbtnimg, command=backmain, compound=LEFT)
back_btn.place(x=80, y=460, anchor="center")
#---------------------------------------------------
def checkboxwarning(txt):
warning = Label(root, text=txt,fg="#F7347A", font="Ubuntu 10")
warning.place(x=190, y=375, anchor="center")
root.after(5000, warning.destroy)
def checkModePin():
global chkmode #which mode usr selected | 0: Pin, 1: District
#----------------------Checkbox verify-----------------------------------------------
global chkvac_sputnik, chkvac_covi, chkvac_cova #vaccine name buttons
global chk_free, chk_paid #free paid buttons
#-----vaccine names----------------
if (vaccinechkboxveri() == False):
checkboxwarning("Select atleast one vaccine")
return
#----Free paid---------------------
if (chk_free.get() + chk_paid.get() == '00'):
checkboxwarning("Free, Paid slots?")
return
#------------------------------------------------------------------------------------
chkmode = 0
mainf(2)
backbtn() ##add back button
seletedModePin()
def checkModeDistrict():
global chkmode #which mode usr selected | 0: Pin, 1: District
#----------------------Checkbox verify-----------------------------------------------
global vacc1,vacc2,vacc3,vacc4,vacc5,vacc6,vacc7,vacc8,vacc9 #vaccine name buttons
global chk_free, chk_paid #free paid buttons
#-----vaccine names----------------
if (vaccinechkboxveri() == False):
checkboxwarning("Select atleast one vaccine")
return
#----Free paid---------------------
if (chk_free.get() + chk_paid.get() == '00'):
checkboxwarning("Free, Paid slots?")
return
#------------------------------------------------------------------------------------
chkmode = 1
mainf(2)
backbtn() ##add back button
seletedModeDistrict()
#--------------------------------------------------------------------------------------------------------------
#---------------------------------------------------Main Frame--------------------------------------------------
print("This is an Console Window, errors if any will be printed here!")
global root
def mainf(func):
global welcomeText2,welcomeText,choiceText,buttonDistrict,buttonPin,tel_choiceText,tel_buttonPin,doseR1,doseR2, ageR1, ageR2, payR1, payR2, updatetext #elements which will be destroyed later
global enteredPin, date, variableState, variableDis,indexDistrict, selectedStateId, statesArray, idArray, districtArray, districtIdAray, dateRadio, availableDosesArray #variables
#checkbox
global vacc1,vacc2,vacc3,vacc4,vacc5,vacc6,vacc7,vacc8,vacc9
global vacc1_btn, vacc2_btn, vacc3_btn, vacc4_btn, vacc5_btn, vacc6_btn, vacc7_btn, vacc8_btn, vacc9_btn #checkbox button #destroyed
global vaccnalb #label #destroyed
if (func == 2): #destroy
welcomeText2.destroy()
welcomeText.destroy()
choiceText.destroy()
buttonDistrict.destroy()
buttonPin.destroy()
tel_choiceText.destroy()
tel_buttonPin.destroy()
doseR1.destroy()
doseR2.destroy()
ageR1.destroy()
ageR2.destroy()
payR1.destroy()
payR2.destroy()
updatetext.destroy()
vaccnalb.destroy()
vacc1_btn.destroy()
vacc2_btn.destroy()
vacc3_btn.destroy()
vacc4_btn.destroy()
vacc5_btn.destroy()
vacc6_btn.destroy()
vacc7_btn.destroy()
vacc8_btn.destroy()
vacc9_btn.destroy()
return
#Due to garbage collection, declare image variables as global
#0: no canvas
#1: show canvas
#2: destroy created objects
global website_dir
global website_dir
global root
root = Tk()
root.title("Co-Win Notifier v" + str(base_ver))
root.geometry('400x500')
root.resizable(width=False, height=False)
root.iconbitmap(resource_path("data/icon.ico"))
#---------------------Theme------------------------------
### Here are the three lines by which we set the theme ###
# Create a style
global style
style = ttk.Style(root)
# Import the tcl file
root.tk.call('source', 'azure-dark.tcl')
# Set the theme with the theme_use method
style.theme_use('azure-dark')
#---------------------------------------------------------
enteredPin = StringVar()
date = StringVar()
variableState = StringVar()
variableDis = StringVar()
indexDistrict = StringVar()
selectedStateId = StringVar()
statesArray = []
idArray = []
districtArray = []
districtIdAray = []
dateRadio = IntVar(value=1)
availableDosesArray = []
#welcome text
welcomeText = Label(root, text ="Welcome to Co-Win Notifier v" + str(base_ver), fg="white", font="Ubuntu 17")
welcomeText.place(x=200, y=30, anchor="center")
welcomeText2 = Label(root, text ="This Utility only checks for slot availability", fg="#F7347A", font="Ubuntu 10")
welcomeText2.place(x=200, y=60, anchor="center")
global github_btn, instagram_btn #### global
github_btn= PhotoImage(file=resource_path('data/github.png'))
def opensite():
webbrowser.open('https://github.com/ashvnv/Co-Win-Notifier')
creditText2 = Label(root, text ="GitHub", fg="gray", font="Ubuntu 10 bold")
creditText2.place(x=330, y=480, anchor="center")
global github_btn2 ### global
github_btn2= PhotoImage(file=resource_path('data/github.png'))
buttonGit2= Button(root, image=github_btn,command=opensite, borderwidth=0)
buttonGit2.place(x=370, y=480, anchor="center")
updatetext = Label(root, text ="No updates available | Current version " + str(current_ver), fg="gray", font="Ubuntu 8 bold")
updatetext.place(x=120, y=480, anchor='center')
#---------------------------------------------------------------------------------
#Telegram alert
global telegram_alert
if tel_config_file(0): #read the config file and get the id
telegram_alert = True
else:
telegram_alert = False
if telegram_alert == True:
tel_choiceTextSet = 'Telegram alert already configured'
tel_choicebtntext = 'configure again'
tel_xlen = 325
else:
tel_choiceTextSet = "Set-up Telegram alert"
tel_choicebtntext = 'configure'
tel_xlen = 270
tel_choiceText = Label(root, text=tel_choiceTextSet,fg="#E0DCDB", font="Ubuntu 11")
tel_choiceText.place(x=140, y=100, anchor="center")
tel_buttonPin = ttk.Button(root, text=tel_choicebtntext, style='AccentButton', command=tel_easygui_configure)
tel_buttonPin.place(x=tel_xlen, y=100, anchor="center")
#---------------------------------------------------------------------------------
#----------------------dose option----------------------
global chkdoseop
chkdoseop = StringVar(value='available_capacity_dose1')
doseR1 = ttk.Radiobutton(root,text='Dose 1',variable=chkdoseop, value='available_capacity_dose1')
doseR1.place(x=80, y=160, anchor="center")
doseR2 = ttk.Radiobutton(root,text='Dose 2',variable=chkdoseop, value='available_capacity_dose2')
doseR2.place(x=80, y=190, anchor="center")
#-------------------------------------------------------
#---------------------------age option--------------------
global chkageop
chkageop = IntVar(value=18)
ageR1 = ttk.Radiobutton(root,text='Age 18+',variable=chkageop, value=18)
ageR1.place(x=195, y=160, anchor="center")
ageR2 = ttk.Radiobutton(root,text='Age 45+',variable=chkageop, value=45)
ageR2.place(x=195, y=190, anchor="center")
#-----------------------------------------------------------
#---------------------------paid or free--------------------
#global chkpayop
#chkpayop = StringVar()
#payR1 = Radiobutton(root,text='Free',variable=chkpayop, value='Free')
#payR1.place(x=290, y=160, anchor="center")
#payR1.select()
#payR2 = Radiobutton(root,text='Paid',variable=chkpayop, value='Paid')
#payR2.place(x=290, y=180, anchor="center")
# added checkbuttons
global chk_free
global chk_paid
chk_free = StringVar(value='Free')
payR1 = ttk.Checkbutton(root, text = "Free", variable = chk_free, onvalue = 'Free', offvalue = '0')
payR1.place(x=300, y=160, anchor="center")
chk_paid = StringVar(value='Paid')
payR2 = ttk.Checkbutton(root, text = "Paid", variable = chk_paid, onvalue = 'Paid', offvalue = '0')
payR2.place(x=300, y=190, anchor="center")
#-----------------------------------------------------------
#-----------------------Vaccine names-------------------------