11from notifypy import Notify
2- from datetime import date
2+ from datetime import datetime
3+ from colorama import Fore
34import pyfiglet
5+ import colorama
46import requests
57import logging
68import os .path
9+ import dotenv
710import time
811import sys
912import os
1013
14+ colorama .init ()
15+
1116logging .basicConfig (level = logging .INFO ,format = '%(asctime)s : %(levelname)s : %(message)s' )
1217
18+ config_path = "assets/config.env"
19+ dotenv .load_dotenv (config_path )
20+
21+ COLOR = os .environ .get ("COLOR" )
22+
1323user_choice = - 1
1424user_choice_block_website = ""
1525user_choice_unlock_website = ""
1626user_confirm_choice = ""
27+ user_choice_settings = - 1
28+ user_choice_settings_confirm_color = - 1
29+ user_choice_settings_confirm_clear = - 1
1730
18- current_version = "1.2 "
31+ current_version = "1.3 "
1932
2033version_url = "https://raw.githubusercontent.com/Rabixx/updater/main/version.txt"
2134
@@ -25,39 +38,46 @@ def on_start():
2538 if os .path .exists ("start.tmp" ):
2639 try :
2740 notification = Notify ()
28-
41+
2942 notification .application_name = "SimpleWebsiteBlocker"
3043 notification .title = "First time?"
31- notification .message = "we hope you will enjoy our app!"
44+ notification .message = "Hello {} we hope you will enjoy our app!" . format ( os . getlogin ())
3245 notification .icon = "assets/icons/simple_website_blocker_icon.png"
3346
3447 notification .send ()
35-
36- m = open (win_path ,"w" )
37- m .truncate (0 )
38- m .close ()
48+
49+ with open (win_path ,"w" ) as m :
50+ m .truncate (0 )
3951
4052 os .remove ("start.tmp" )
53+
54+ CONFIG_COLOR = getattr (Fore , COLOR )
55+ print (CONFIG_COLOR )
56+ os .system ('cls' )
4157 except PermissionError :
4258 logging .warning ("Access denied please run SimpleWebsiteBlocker with admin permissions!" )
4359 os .system ('pause' )
4460 sys .exit ()
45- else :
46- pass
4761
48- def main (user_choice ,user_choice_block_website ,user_choice_unlock_website ,win_path ,version_url ,current_version ,user_confirm_choice ):
62+ def load_config ():
63+ CONFIG_COLOR = getattr (Fore , COLOR )
64+ print (CONFIG_COLOR )
65+ os .system ('cls' )
66+
67+ def main (user_choice ,user_choice_block_website ,user_choice_unlock_website ,win_path ,version_url ,current_version ,user_confirm_choice ,user_choice_settings ,user_choice_settings_confirm_clear ,user_choice_settings_confirm_color ,config_path ,COLOR ):
4968 while user_choice != 7 :
5069 if user_choice == 1 :
5170 try :
5271 os .system ('cls' )
53- c = open (win_path ,"a" )
5472 print ("what website u want to block?" )
5573 print ()
5674 print ("to cancel hold CTRL + C in the same moment" )
5775 print ()
5876 user_choice_block_website = str (input (">>: " ))
59- c .writelines ("0.0.0.0" + " " + user_choice_block_website + "\n " )
60- c .close ()
77+
78+ with open (win_path ,"a" ) as c :
79+ c .writelines ("0.0.0.0" + " " + user_choice_block_website + "\n " )
80+
6181 print ("website was successfully blocked!" )
6282 time .sleep (1 )
6383 os .system ('cls' )
@@ -96,39 +116,25 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
96116 os .system ('cls' )
97117 except KeyboardInterrupt :
98118 os .system ('cls' )
99-
119+
100120 if user_choice == 3 :
101121 try :
102122 os .system ('cls' )
103123 print ("all the websites that are currently blocked:" )
104124 print ()
105- a = open (win_path ,"r" )
106- lines = a .readlines ()
125+ with open (win_path ,"r" ) as a :
126+ lines = a .readlines ()
127+
107128 for line in lines :
108129 print (line )
109- a . close ()
130+
110131 except Exception as ex_3 :
111132 os .system ('cls' )
112133 print (f"[ERROR] { ex_3 } " )
113134 time .sleep (2 )
114135 os .system ('cls' )
115-
116- if user_choice == 4 :
117- try :
118- os .system ('cls' )
119- print ("> SimpleWebsiteBlocker" ,date .today ().year ,"copyrights" )
120- print ("> this app is really simple websiteblocker that can be used" )
121- print ("> without any time limits its free and under SimpleWebsiteBlocker license" )
122- print ("> you can find more details under this link {}" .format ("https://github.com/Rabixx/SimpleWebsiteBlocker/" ))
123- os .system ('pause' )
124- os .system ('cls' )
125- except Exception as ex_4 :
126- os .system ('cls' )
127- print (f"[ERROR] { ex_4 } " )
128- time .sleep (2 )
129- os .system ('cls' )
130136
131- if user_choice == 5 :
137+ if user_choice == 4 :
132138 try :
133139 os .system ('cls' )
134140
@@ -153,6 +159,164 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
153159 print ("Great no updates were found!" )
154160 time .sleep (2 )
155161 os .system ('cls' )
162+ except Exception as ex_4 :
163+ os .system ('cls' )
164+ print (f"[ERROR] { ex_4 } " )
165+ time .sleep (2 )
166+ os .system ('cls' )
167+ except KeyboardInterrupt :
168+ os .system ('cls' )
169+
170+ if user_choice == 5 :
171+ try :
172+ os .system ('cls' )
173+
174+ print ("1. Change app color" )
175+ print ("2. Reset all blocked websites" )
176+ print ("3. About app" )
177+ print ()
178+ print ("to cancel hold CTRL + C in the same moment" )
179+ print ()
180+ user_choice_settings = int (input (">>: " ))
181+
182+ if user_choice_settings == 1 :
183+ os .system ('cls' )
184+
185+ print (f"Current color: { COLOR } " )
186+ print ()
187+ print ("1. Red" )
188+ print ("2. Green" )
189+ print ("3. Yellow" )
190+ print ("4. Blue" )
191+ print ("5. Magenta" )
192+ print ("6. Cyan" )
193+ print ("7. Reset color" )
194+ print ()
195+ print ("to cancel hold CTRL + C in the same moment" )
196+ print ()
197+ user_choice_settings_confirm_color = int (input (">>: " ))
198+
199+ if user_choice_settings_confirm_color == 1 :
200+ os .system ('cls' )
201+
202+ os .environ ["COLOR" ] = "RED"
203+
204+ dotenv .set_key (config_path ,"COLOR" ,os .environ ["COLOR" ])
205+
206+ print ("Changed color to red!" )
207+ print ()
208+ print ("To see changes you have to restart the app" )
209+ time .sleep (3 )
210+ os .system ('cls' )
211+
212+ elif user_choice_settings_confirm_color == 2 :
213+ os .system ('cls' )
214+
215+ os .environ ["COLOR" ] = "GREEN"
216+
217+ dotenv .set_key (config_path ,"COLOR" ,os .environ ["COLOR" ])
218+
219+ print ("Changed color to green!" )
220+ print ()
221+ print ("To see changes you have to restart the app" )
222+ time .sleep (3 )
223+ os .system ('cls' )
224+
225+ elif user_choice_settings_confirm_color == 3 :
226+ os .system ('cls' )
227+
228+ os .environ ["COLOR" ] = "YELLOW"
229+
230+ dotenv .set_key (config_path ,"COLOR" ,os .environ ["COLOR" ])
231+
232+ print ("Changed color to yellow!" )
233+ print ()
234+ print ("To see changes you have to restart the app" )
235+ time .sleep (3 )
236+ os .system ('cls' )
237+
238+ elif user_choice_settings_confirm_color == 4 :
239+ os .system ('cls' )
240+
241+ os .environ ["COLOR" ] = "BLUE"
242+
243+ dotenv .set_key (config_path ,"COLOR" ,os .environ ["COLOR" ])
244+
245+ print ("Changed color to blue!" )
246+ print ()
247+ print ("To see changes you have to restart the app" )
248+ time .sleep (3 )
249+ os .system ('cls' )
250+
251+ elif user_choice_settings_confirm_color == 5 :
252+ os .system ('cls' )
253+
254+ os .environ ["COLOR" ] = "MAGENTA"
255+
256+ dotenv .set_key (config_path ,"COLOR" ,os .environ ["COLOR" ])
257+
258+ print ("Changed color to magenta!" )
259+ print ()
260+ print ("To see changes you have to restart the app" )
261+ time .sleep (3 )
262+ os .system ('cls' )
263+
264+ elif user_choice_settings_confirm_color == 6 :
265+ os .system ('cls' )
266+
267+ os .environ ["COLOR" ] = "CYAN"
268+
269+ dotenv .set_key (config_path ,"COLOR" ,os .environ ["COLOR" ])
270+
271+ print ("Changed color to cyan!" )
272+ print ()
273+ print ("To see changes you have to restart the app" )
274+ time .sleep (3 )
275+ os .system ('cls' )
276+
277+ elif user_choice_settings_confirm_color == 7 :
278+ os .system ('cls' )
279+
280+ os .environ ["COLOR" ] = "WHITE"
281+
282+ dotenv .set_key (config_path ,"COLOR" ,os .environ ["COLOR" ])
283+
284+ print ("Changed color to deafult!" )
285+ print ()
286+ print ("To see changes you have to restart the app" )
287+ time .sleep (3 )
288+ os .system ('cls' )
289+
290+ if user_choice_settings == 2 :
291+ os .system ('cls' )
292+ print ("Are you sure to reset all blocked websites?" )
293+ print ()
294+ print ("to cancel hold CTRL + C in the same moment" )
295+ print ()
296+ user_choice_settings_confirm_clear = str (input ("(yes,no): " ))
297+
298+ if user_choice_settings_confirm_clear == "yes" :
299+ with open (win_path ,"w" ) as clear_file :
300+ clear_file .truncate (0 )
301+
302+ print ("All websites were unlocked!" )
303+ time .sleep (1 )
304+ os .system ('cls' )
305+ else :
306+ os .system ('cls' )
307+
308+ if user_choice_settings == 3 :
309+ os .system ('cls' )
310+ print (f"> SimpleWebsiteBlocker { datetime .today ().year } copyrights (C)" )
311+ print ()
312+ print ("> the SimpleWebsiteBlocker as it says is simple app to block" )
313+ print ("> unwanted or annoying websites also SimpleWebsiteBlocker" )
314+ print ("> is free and under SimpleWebsiteBlocker(SBW) license you can use" )
315+ print ("> it without any time limits for more details visit {}" .format ("https://github.com/Rabixx/SimpleWebsiteBlocker" ))
316+ print ()
317+ os .system ('pause' )
318+ os .system ('cls' )
319+
156320 except Exception as ex_5 :
157321 os .system ('cls' )
158322 print (f"[ERROR] { ex_5 } " )
@@ -172,15 +336,16 @@ def main(user_choice,user_choice_block_website,user_choice_unlock_website,win_pa
172336 print ("1. Block website" )
173337 print ("2. Unlock website" )
174338 print ("3. Show all blocked websites" )
175- print ("4. About app " )
176- print ("5. Check for updates " )
339+ print ("4. Check for updates " )
340+ print ("5. Settings " )
177341 print ("6. Exit" )
178342 user_choice = int (input (">>: " ))
179343
180344if __name__ == "__main__" :
181345 if sys .platform .startswith ("win" ):
182346 on_start ()
183- main (user_choice ,user_choice_block_website ,user_choice_unlock_website ,win_path ,version_url ,current_version ,user_confirm_choice )
347+ load_config ()
348+ main (user_choice ,user_choice_block_website ,user_choice_unlock_website ,win_path ,version_url ,current_version ,user_confirm_choice ,user_choice_settings ,user_choice_settings_confirm_clear ,user_choice_settings_confirm_color ,config_path ,COLOR )
184349 else :
185350 logging .warning ("SimpleWebsiteBlocker works only on Windows operating system!" )
186351 os .system ('pause' )
0 commit comments