Files
yankee-gnome-fire-consumer/DiskUtils.py

137 lines
3.1 KiB
Python
Raw Normal View History

2025-02-06 22:21:31 -05:00
import os
import time
import re
import fnmatch
def check_download_exists_matching_url_version_one(url):
2025-02-06 22:21:31 -05:00
print ("enter > downloads > exist check > version 1")
2025-02-06 22:21:31 -05:00
match = re.search(r"https://sullygnome.com/channel/([^/]+)/(\d+)([a-z]+)/games", url.lower())
2025-02-06 22:21:31 -05:00
if not match:
2025-02-06 22:21:31 -05:00
print(f"Invalid URL format. Could not extract channel name, year, or month.")
return
2025-02-06 22:21:31 -05:00
channel_name, year, month = match.groups()
2025-02-06 22:21:31 -05:00
print("channel / ",channel_name)
2025-02-06 22:21:31 -05:00
#print("year / ",year)
2025-02-06 22:21:31 -05:00
#print("month / ",month)
2025-02-06 22:21:31 -05:00
#file_pattern = f"{channel_name}*{month}*{year}*.csv"
## this is a problem. it works but if there 2 channels.
## redbull and redbull2 this is throw false positives. ugh
file_pattern = f"*{channel_name} - game stats on Twitch in {month} {year} - SullyGnome.csv".lower()
for filename in os.listdir("/home/yankee/Downloads/"):
updated = filename.lower()
#print("file in downloads / ",updated)
if fnmatch.fnmatch(updated, file_pattern):
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}'. (version one)")
return False
def check_download_exists_matching_url_version_two(url):
2025-03-11 21:20:17 -04:00
2025-03-12 09:16:22 -04:00
print ("enter > check_download_exists_matching_url_version_two")
2025-02-06 22:21:31 -05:00
match = re.search(r"https://sullygnome.com/channel/([^/]+)/(\d+)([a-z]+)/games", 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)
2025-03-11 20:42:48 -04:00
for filename in os.listdir("/home/yankee/Downloads/"):
2025-02-06 22:21:31 -05:00
updated = filename.lower()
2025-03-11 20:32:29 -04:00
print("found file (v2) / ",updated)
2025-02-06 22:21:31 -05:00
2025-03-12 09:16:22 -04:00
##
2025-02-06 22:21:31 -05:00
2025-03-12 09:16:22 -04:00
hasKeyDateParts = does_filename_contain_key_date_parts(updated, month, year)
2025-02-06 22:21:31 -05:00
2025-03-12 09:16:22 -04:00
print("\thasKeyDateParts / ",hasKeyDateParts)
2025-02-06 22:21:31 -05:00
2025-03-12 09:16:22 -04:00
##
hasTargetChannelName = does_filename_contain_target_channel_name(updated,channel_name)
print("\thasTargetChannelName / ",hasTargetChannelName)
##
print ("exit < check_download_exists_matching_url_version_two")
def does_filename_contain_target_channel_name(url,channel):
regex = rf"\({re.escape(channel)}\)"
2025-02-06 22:21:31 -05:00
2025-03-12 09:16:22 -04:00
match = re.search(regex, url)
2025-02-06 22:21:31 -05:00
2025-03-12 09:16:22 -04:00
results = bool(match)
print("results / ",results)
match = re.search("\({channel}\)", url)
if match:
print("yup!")
extracted_text = match.group(1).lower()
print("extracted: /",extracted_text)
return False
## return extracted_text == target_string.lower()
else:
print("nope!")
2025-02-06 22:21:31 -05:00
return False
2025-03-12 09:16:22 -04:00
def does_filename_contain_key_date_parts(filename, monthString, yearNumber):
print("enter -> does_filename_contain_key_date_parts()")
regex = rf"{re.escape(monthString)} {yearNumber}"
doesContain = bool(re.search(regex, filename, re.IGNORECASE))
print("doesContain / ",doesContain)
return doesContain