90 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
		
		
			
		
	
	
			90 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
|   | import os | ||
|  | import time | ||
|  | import re | ||
|  | 
 | ||
|  | def dowork(): | ||
|  | 
 | ||
|  |     ################################################################################################ | ||
|  | 
 | ||
|  |     url = "https://sullygnome.com/channel/kaicenat/2023january/streams" | ||
|  | 
 | ||
|  |     print("checking disk for the stuff...") | ||
|  | 
 | ||
|  |     print("url", url) | ||
|  | 
 | ||
|  |     fileExists = check_download_exists_matching_url(url) | ||
|  | 
 | ||
|  |     print("file already exists / ",fileExists) | ||
|  | 
 | ||
|  |     ################################################################################################ | ||
|  | 
 | ||
|  | def check_download_exists_matching_url(url): | ||
|  | 
 | ||
|  |     print ("hello?") | ||
|  | 
 | ||
|  |     match = re.search(r"https://sullygnome.com/channel/([^/]+)/(\d+)([a-z]+)/streams", url.lower()) | ||
|  | 
 | ||
|  |     if not match: | ||
|  | 
 | ||
|  |         print(f"Invalid URL format. Could not extract channel name, year, or month.") | ||
|  | 
 | ||
|  |         return | ||
|  | 
 | ||
|  |     channel_name, year, month = match.groups() | ||
|  | 
 | ||
|  |     print("channel / ",channel_name) | ||
|  | 
 | ||
|  |     print("year / ",year) | ||
|  | 
 | ||
|  |     print("month / ",month) | ||
|  | 
 | ||
|  |     #file_pattern = f"{channel_name}*{month}*{year}*.csv" | ||
|  | 
 | ||
|  |     file_pattern = f"{channel_name} - Twitch stream stats in {month} {year} - SullyGnome.csv".lower() | ||
|  | 
 | ||
|  |     for filename in os.listdir("/home/softwareshinobi/Downloads/"): | ||
|  | 
 | ||
|  |         updated = filename.lower() | ||
|  | 
 | ||
|  |         print("updated / ",updated) | ||
|  | 
 | ||
|  |         if re.match(file_pattern, updated): | ||
|  | 
 | ||
|  |             print(f"Found matching file: {updated}") | ||
|  | 
 | ||
|  |             return True | ||
|  | 
 | ||
|  |     else: | ||
|  | 
 | ||
|  |         print(f"No matching CSV file found for channel '{channel_name}' in year '{year}' and month '{month}'.") | ||
|  | 
 | ||
|  |         return False | ||
|  | 
 | ||
|  | def shutDownRobot(): | ||
|  | 
 | ||
|  |     print("shutting down the robot now") | ||
|  | 
 | ||
|  | while True: | ||
|  | 
 | ||
|  |     print("checking is file exists... [loop]") | ||
|  | 
 | ||
|  |     if check_file(file_to_check): | ||
|  | 
 | ||
|  |         print(f"The file '{file_to_check}' exists.") | ||
|  | 
 | ||
|  |         print("shutting down the robot") | ||
|  | 
 | ||
|  |         shutDownRobot() | ||
|  | 
 | ||
|  |         print("robot shut down. breaking. and dying.") | ||
|  | 
 | ||
|  |         break | ||
|  | 
 | ||
|  |     else: | ||
|  | 
 | ||
|  |         print(f"The file '{file_to_check}' does not exist.") | ||
|  | 
 | ||
|  |         print("sleeping for some time before checking again...");  | ||
|  | 
 | ||
|  |         time.sleep(1) |