22from datetime import date
33import pyfiglet
44import requests
5+ import logging
56import os .path
67import time
78import sys
89import os
910
11+ logging .basicConfig (level = logging .INFO ,format = '%(asctime)s : %(levelname)s : %(message)s' )
12+
1013user_choice = - 1
1114user_choice_block_website = ""
1215user_choice_unlock_website = ""
1316user_confirm_choice = ""
1417
15- current_version = "1.1 "
18+ current_version = "1.2 "
1619
1720version_url = "https://raw.githubusercontent.com/Rabixx/updater/main/version.txt"
1821
1922win_path = "C:\\ Windows\\ System32\\ drivers\\ etc\\ hosts"
2023
21- if os .path .exists ("start.tmp" ):
22-
23- notification = Notify ()
24-
25- notification .application_name = "SimpleWebsiteBlocker"
26- notification .title = "First time?"
27- notification .message = "we hope you will enjoy our app!"
28- notification .icon = "assets/icons/simple_website_blocker_icon.png"
29-
30- notification .send ()
31-
32- m = open (win_path ,"w" )
33- m .truncate (0 )
34- m .close ()
35-
36- os .remove ("start.tmp" )
24+ def on_start ():
25+ if os .path .exists ("start.tmp" ):
26+ try :
27+ notification = Notify ()
28+
29+ notification .application_name = "SimpleWebsiteBlocker"
30+ notification .title = "First time?"
31+ notification .message = "we hope you will enjoy our app!"
32+ notification .icon = "assets/icons/simple_website_blocker_icon.png"
33+
34+ notification .send ()
35+
36+ m = open (win_path ,"w" )
37+ m .truncate (0 )
38+ m .close ()
39+
40+ os .remove ("start.tmp" )
41+ except PermissionError :
42+ logging .warning ("Access denied please run SimpleWebsiteBlocker with admin permissions!" )
43+ os .system ('pause' )
44+ sys .exit ()
45+ else :
46+ pass
3747
3848def main (user_choice ,user_choice_block_website ,user_choice_unlock_website ,win_path ,version_url ,current_version ,user_confirm_choice ):
3949 while user_choice != 7 :
@@ -148,6 +158,8 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
148158 print (f"[ERROR] { ex_5 } " )
149159 time .sleep (2 )
150160 os .system ('cls' )
161+ except KeyboardInterrupt :
162+ os .system ('cls' )
151163
152164 if user_choice == 6 :
153165 os .system ('cls' )
@@ -166,4 +178,10 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
166178 user_choice = int (input (">>: " ))
167179
168180if __name__ == "__main__" :
169- main (user_choice ,user_choice_block_website ,user_choice_unlock_website ,win_path ,version_url ,current_version ,user_confirm_choice )
181+ if sys .platform .startswith ("win" ):
182+ on_start ()
183+ main (user_choice ,user_choice_block_website ,user_choice_unlock_website ,win_path ,version_url ,current_version ,user_confirm_choice )
184+ else :
185+ logging .warning ("SimpleWebsiteBlocker works only on Windows operating system!" )
186+ os .system ('pause' )
187+ sys .exit ()
0 commit comments