77
88# FOR ADGUARD HOME ONLY
99
10- # Required Packages
11- # A python package called "requests" is required to handle 403 errors (install that package first by running: python -m pip install requests)
10+ # Tested and working on Python for Windows Python 3.12.4 or later.
1211
13- # Version: 0.2
14- # Date: 2024-06-14 01:20:58AM
12+ # Required Python Packages:
13+ # - "requests" is required to handle 403 errors (install that package first by running: python -m pip install requests)
14+ # - "rich" is required for colored text output
15+
16+ # Version: 0.3
17+ # Date: 2024-07-15 05:33:16PM
1518
1619# Imports
1720from time import gmtime , strftime
21+ from datetime import datetime , timezone
1822from urllib .request import urlretrieve
1923import requests
24+ from rich import print
25+ import glob
26+ import os
27+ # from tqdm import tqdm
2028#from urllib.request import Request, urlopen
2129#import requests
2230#from random import seed
23- import glob
24- import os
2531
2632#CURRENTWORKINGDIRECTORY = os.getcwd() + "\\"
2733CURRENTWORKINGDIRECTORY = "C:\\ Users\\ Dean\\ Documents\\ Important\\ MEGASync\\ GitHub\\ CodeLibrary\\ Python\\ AdGuard-Home-AIO-List-main\\ "
2834
29- NOW = strftime ("%Y-%m-%d %H:%M:%S" , gmtime ())
35+ # NOW = strftime("%Y-%m-%d %H:%M:%S", gmtime())
3036
3137URLS = [
3238 # AdGuard Simplified Domain Names filter
218224 "https://blocklist.sefinek.net/generated/v1/adguard/tracking-and-telemetry/quidsup/trackers-hosts.fork.txt" ,
219225 "https://blocklist.sefinek.net/generated/v1/adguard/useless-websites/jarelllama/parked-domains.fork.txt" ,
220226 "https://blocklist.sefinek.net/generated/v1/adguard/useless-websites/sefinek.hosts.txt" ,
227+ "https://blocklist.sefinek.net/generated/v1/adguard/dating-services/ShadowWhisperer/dating.fork.txt" , # Testing 0.3
228+ "https://blocklist.sefinek.net/generated/v1/adguard/dating-services/sefinek.hosts.txt" , # Testing 0.3
229+ "https://blocklist.sefinek.net/generated/v1/adguard/malicious/ShadowWhisperer/malware.fork.txt" , # Testing 0.3
230+ "https://blocklist.sefinek.net/generated/v1/adguard/scam/ShadowWhisperer/scam.fork.txt" , # Testing 0.3
231+ "https://blocklist.sefinek.net/generated/v1/adguard/tracking-and-telemetry/ShadowWhisperer/tracking.fork.txt" , # Testing 0.3
221232
222233 #"https://hosts.anudeep.me/mirror/adservers.txt"
223234 # LostAd [TOO BIG]
238249 #"https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt"
239250 ]
240251
241- NOW = strftime ("%Y-%m-%d %H:%M:%S" , gmtime ())
252+ UTC_DT = datetime .now (timezone .utc ) # UTC time
253+ NOW = str (UTC_DT .astimezone ()) # local time
254+
255+ def refreshDateTimeToNow ():
256+ UTC_DT = datetime .now (timezone .utc ) # UTC time
257+ NOW = str (UTC_DT .astimezone ()) # local time
258+ return NOW
259+
260+ NOW = refreshDateTimeToNow ()
261+
262+ #pbarCollection = tqdm(URLS)
242263
243264# Downloads the individual lists
244265for URL in URLS :
245266 LIST_INDEX = URLS .index (URL )
246267 FILENAME = CURRENTWORKINGDIRECTORY + "downloaded_lists\\ blocklist" + str (LIST_INDEX ) + ".txt"
247- # print(NOW+" - "+"Downloading: " + URL + " >> " + FILENAME)
268+ # print(NOW+" - "+"Downloading: " + URL + " >> " + FILENAME)
248269# urlretrieve(URL, FILENAME)
249270# NOW = strftime("%Y-%m-%d %H:%M:%S", gmtime())
250271
272+ #pbarCollection.set_description("Downloading List " + str(LIST_INDEX))
273+ #print("\n")
274+
251275 # Uses a workaround for 403 errors by applying a better "User-Agent" header to the request
252276 if URL .startswith ("https://blocklist.sefinek.net/" ):
253- print (NOW + " - " + "Downloading: " + URL + " >> " + FILENAME )
277+ print (NOW + " - " + "Downloading: " + URL )
278+ print ("to: " + FILENAME )
279+ # print("\n")
254280 HEADERS = {
255281 'User-Agent' : 'Mozilla 5.0' ,
256282 }
259285 if RESPONSE .status_code == 200 :
260286 with open (FILENAME , "w" , encoding = 'utf8' ) as file :
261287 file .write (CONTENT )
262- NOW = strftime ( "%Y-%m-%d %H:%M:%S" , gmtime () )
288+ NOW = refreshDateTimeToNow ( )
263289 else :
264- print (NOW + " - " + "Downloading: " + URL + " >> " + FILENAME )
290+ print (NOW + " - " + "Downloading: " + URL )
291+ print ("to: " + FILENAME )
292+ #print("\n")
265293 urlretrieve (URL , FILENAME )
266- NOW = strftime ("%Y-%m-%d %H:%M:%S" , gmtime ())
294+ NOW = refreshDateTimeToNow ()
295+ # os.system('cls')
267296
268297# Merges lists into one file
269298# Source: https://bobbyhadz.com/blog/merge-text-files-in-python#how-to-merge-text-files-in-python
273302 with open (file_path , 'r' , encoding = 'utf-8' ) as input_file :
274303 output_file .write (input_file .read () + '\n ' )
275304
276- NOW = strftime ( "%Y-%m-%d %H:%M:%S" , gmtime () )
305+ NOW = refreshDateTimeToNow ( )
277306
278307# Removes individual text files
279308I = 0
282311 os .remove (CURRENTWORKINGDIRECTORY + "downloaded_lists/blocklist" + str (I )+ ".txt" )
283312 I = I + 1
284313
285- NOW = strftime ( "%Y-%m-%d %H:%M:%S" , gmtime () )
314+ NOW = refreshDateTimeToNow ( )
286315
287316# Cleans aio_blocklist.txt file
288317print (NOW + " - " + "Cleaning aio_blocklist.txt, please wait.." )
293322# Removes duplicates from from text file
294323CLEANEDOUTPUT = open (CURRENTWORKINGDIRECTORY + 'aio_blocklist.txt' , 'w' , encoding = 'utf-8' ).writelines (UNIQUELINES )
295324
296- NOW = strftime ( "%Y-%m-%d %H:%M:%S" , gmtime () )
325+ NOW = refreshDateTimeToNow ( )
297326
298327# Removes all junk from aio_blocklist.txt file
299328print (NOW + " - " + "Removing junk lines from aio_blocklist.txt, please wait.." )
318347 line = line .replace ('^' ,'^$important' )
319348 line = line .replace ('||||' ,'||' )
320349 line = line .replace ('|||' ,'||' )
350+ line = line .replace ('||' ,'|' ) # Implemented a fix to skip subdomain blocking
321351 line = line .replace ('$important$important' ,'$important' )
322352 new_f .write (line )
323353os .remove (CURRENTWORKINGDIRECTORY + "aio_blocklist.txt" )
324354
325- NOW = strftime ( "%Y-%m-%d %H:%M:%S" , gmtime () )
355+ NOW = refreshDateTimeToNow ( )
326356
327357# Cleans aio_blocklist_final.txt file
328358print (NOW + " - " + "Cleaning aio_blocklist_final.txt, please wait.." )
335365# Removes duplicates from from text file
336366CLEANEDOUTPUT = open (CURRENTWORKINGDIRECTORY + 'aio_blocklist_final.txt' , 'w' , encoding = 'utf-8' ).writelines (UNIQUELINES )
337367
338- NOW = strftime ( "%Y-%m-%d %H:%M:%S" , gmtime () )
368+ NOW = refreshDateTimeToNow ( )
339369print (NOW + " - " + "AIO list has been generated as: aio_blocklist_final.txt" )
340370
341371# Writes to HISTORY.md file
342372with open (CURRENTWORKINGDIRECTORY + "HISTORY.md" , "a" , encoding = 'utf-8' ) as HISTORYFILE :
343373 HISTORYFILE .write ("- Updated " + NOW + "\n " )
344374
345- NOW = strftime ("%Y-%m-%d %H:%M:%S" , gmtime ())
375+ NOW = refreshDateTimeToNow ()
376+ # NOW = strftime("%Y-%m-%d %H:%M:%S", gmtime())
346377print (NOW + " - " + "Updated: HISTORY.md" )
378+
379+ # Version 0.3 changes:
380+ # - added fix to skip blocking subdomains
381+ # - added color text output using "rich" package
382+ # - added more lists
383+ # - fixed datetime now to be local time
384+ # - improved output
385+ #
0 commit comments