Compare commits
6 Commits
production
...
match-asia
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39b2608a36 | ||
|
|
782e6fc655 | ||
|
|
4ec5f446e8 | ||
|
|
dc51e2e646 | ||
|
|
c671cb5d61 | ||
|
|
73cb40154c |
71
DiskUtils.py
71
DiskUtils.py
@@ -50,7 +50,7 @@ def check_download_exists_matching_url_version_one(url):
|
|||||||
|
|
||||||
def check_download_exists_matching_url_version_two(url):
|
def check_download_exists_matching_url_version_two(url):
|
||||||
|
|
||||||
print ("enter > downloads > exist check > version 2")
|
print ("enter > check_download_exists_matching_url_version_two")
|
||||||
|
|
||||||
match = re.search(r"https://sullygnome.com/channel/([^/]+)/(\d+)([a-z]+)/games", url.lower())
|
match = re.search(r"https://sullygnome.com/channel/([^/]+)/(\d+)([a-z]+)/games", url.lower())
|
||||||
|
|
||||||
@@ -68,30 +68,69 @@ def check_download_exists_matching_url_version_two(url):
|
|||||||
|
|
||||||
print("month / ",month)
|
print("month / ",month)
|
||||||
|
|
||||||
## this is a problem. it works but if there 2 channels.
|
|
||||||
## redbull and redbull2 this is throw false positives. ugh
|
|
||||||
|
|
||||||
unicode_part = r"[\u3040-\u309F\u30A0-\u30FF_]*" # Matches any hiragana, katakana, and underscore
|
|
||||||
|
|
||||||
file_pattern = f"{unicode_part} \({channel_name}\) - game stats on Twitch in {month} {year} - SullyGnome.csv".lower()
|
|
||||||
|
|
||||||
print("regex :",file_pattern)
|
|
||||||
|
|
||||||
for filename in os.listdir("/home/yankee/Downloads/"):
|
for filename in os.listdir("/home/yankee/Downloads/"):
|
||||||
|
|
||||||
updated = filename.lower()
|
updated = filename.lower()
|
||||||
|
|
||||||
print("file in downloads / ",updated)
|
print("found file (v2) / ",updated)
|
||||||
|
|
||||||
if fnmatch.fnmatch(updated, file_pattern):
|
##
|
||||||
|
|
||||||
print(f"Found matching file: {updated}")
|
hasKeyDateParts = does_filename_contain_key_date_parts(updated, month, year)
|
||||||
|
|
||||||
return True
|
print("\thasKeyDateParts / ",hasKeyDateParts)
|
||||||
|
|
||||||
else:
|
##
|
||||||
|
|
||||||
print(f"No matching CSV file found for channel '{channel_name}' in year '{year}' and month '{month}'. (version t55555wo)")
|
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)}\)"
|
||||||
|
|
||||||
|
match = re.search(regex, url)
|
||||||
|
|
||||||
|
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 False
|
||||||
|
|
||||||
|
## return extracted_text == target_string.lower()
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("nope!")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ def addDownloadFailure(url, error):
|
|||||||
|
|
||||||
def searchURLSuccesses(url):
|
def searchURLSuccesses(url):
|
||||||
|
|
||||||
print("enter -> callGET()")
|
## print("enter -> callGET()")
|
||||||
|
|
||||||
print("param / url / ",url)
|
## print("param / url / ",url)
|
||||||
|
|
||||||
data = { "url": url }
|
data = { "url": url }
|
||||||
|
|
||||||
@@ -91,15 +91,15 @@ def searchURLSuccesses(url):
|
|||||||
|
|
||||||
response = requests.post("https://apis.yankee.embanet.online/channel/monthly/games/success/exists", data=json_data, headers=headers)
|
response = requests.post("https://apis.yankee.embanet.online/channel/monthly/games/success/exists", data=json_data, headers=headers)
|
||||||
|
|
||||||
print(response.text)
|
## print(response.text)
|
||||||
|
|
||||||
return response.text
|
return response.text
|
||||||
|
|
||||||
def searchURLFailures(url):
|
def searchURLFailures(url):
|
||||||
|
|
||||||
print("enter -> callGET()")
|
## print("enter -> callGET()")
|
||||||
|
|
||||||
print("param / url / ",url)
|
## print("param / url / ",url)
|
||||||
|
|
||||||
data = { "url": url }
|
data = { "url": url }
|
||||||
|
|
||||||
@@ -109,6 +109,6 @@ def searchURLFailures(url):
|
|||||||
|
|
||||||
response = requests.post("https://apis.yankee.embanet.online/channel/monthly/games/failure/exists", data=json_data, headers=headers)
|
response = requests.post("https://apis.yankee.embanet.online/channel/monthly/games/failure/exists", data=json_data, headers=headers)
|
||||||
|
|
||||||
print(response.text)
|
## print(response.text)
|
||||||
|
|
||||||
return response.text
|
return response.text
|
||||||
|
|||||||
@@ -116,6 +116,12 @@ def download(url):
|
|||||||
|
|
||||||
print("file already exists (v1) / ",existsAlreadyVersionOne)
|
print("file already exists (v1) / ",existsAlreadyVersionOne)
|
||||||
|
|
||||||
|
existsAlreadyVersionTwo = DiskUtils.check_download_exists_matching_url_version_two(url)
|
||||||
|
|
||||||
|
print("file already exists (v2) / ",existsAlreadyVersionTwo)
|
||||||
|
|
||||||
|
time.sleep(40)
|
||||||
|
|
||||||
if existsAlreadyVersionOne:
|
if existsAlreadyVersionOne:
|
||||||
|
|
||||||
print(f"The file matching the url '{url}' DOES INDEED exists. (version 1)")
|
print(f"The file matching the url '{url}' DOES INDEED exists. (version 1)")
|
||||||
|
|||||||
79
consumer.py
79
consumer.py
@@ -3,45 +3,80 @@ import time
|
|||||||
import SullyGnomeRobot
|
import SullyGnomeRobot
|
||||||
import RestAPIClient
|
import RestAPIClient
|
||||||
|
|
||||||
|
### start variables ###
|
||||||
|
|
||||||
|
jmsQueue="asian-tester"
|
||||||
|
|
||||||
|
host = '38.107.226.34'
|
||||||
|
|
||||||
|
port = 61613
|
||||||
|
|
||||||
|
|
||||||
|
username = 'admin'
|
||||||
|
password = 'password'
|
||||||
|
|
||||||
|
|
||||||
|
### end variables ###
|
||||||
|
|
||||||
print("## ")
|
print("## ")
|
||||||
print("## starting > JMS consumer (yankee-sully-channels-monthly)")
|
print(f"## starting > JMS consumer app!")
|
||||||
print("## ")
|
print("## ")
|
||||||
|
|
||||||
## https://sullygnome.com/channel/yaritaiji/2024october/games
|
def writeSullyURLToJMS():
|
||||||
|
|
||||||
|
channel="https://sullygnome.com/channel/yaritaiji/2024october/games"
|
||||||
|
|
||||||
|
print(f"launch -> jms writer -> channel-> {channel}")
|
||||||
|
|
||||||
|
conn = stomp.Connection([('osiris.yankee.embanet.online', 61613)])
|
||||||
|
|
||||||
|
conn.connect('admin', 'password', wait=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
conn.send(body=channel.strip(), destination=f'/queue/{jmsQueue}')
|
||||||
|
|
||||||
|
finally:
|
||||||
|
|
||||||
|
conn.disconnect()
|
||||||
|
|
||||||
class MyListener(stomp.ConnectionListener):
|
class MyListener(stomp.ConnectionListener):
|
||||||
|
|
||||||
def on_message(headers, message):
|
def on_message(headers, message):
|
||||||
|
|
||||||
print("** new message! **")
|
## print("** new message! **")
|
||||||
|
|
||||||
print("message / ", message)
|
## print("message / ", message)
|
||||||
|
|
||||||
print("messagebody / ", message.body)
|
print("JMS url -> ", message.body)
|
||||||
|
|
||||||
print("checking the value does or doesnt exist in db")
|
## print("checking the value does or doesnt exist in db")
|
||||||
|
|
||||||
alreadyExistsSuccess = RestAPIClient.searchURLSuccesses(message.body)
|
alreadyExistsSuccess = RestAPIClient.searchURLSuccesses(message.body)
|
||||||
|
|
||||||
print("alreadyExistsSuccess / ", alreadyExistsSuccess)
|
## print("alreadyExistsSuccess / ", alreadyExistsSuccess)
|
||||||
|
|
||||||
if alreadyExistsSuccess.lower().strip() == "true":
|
if alreadyExistsSuccess.lower().strip() == "true":
|
||||||
|
|
||||||
print("this record exists (successes). returning. doing nothing")
|
## print("this record exists (successes). returning. doing nothing")
|
||||||
|
|
||||||
return
|
## return
|
||||||
|
|
||||||
print("didn't exist in success. check in errors now.")
|
print ("skipped!!")
|
||||||
|
|
||||||
|
## print("didn't exist in success. check in errors now.")
|
||||||
|
|
||||||
alreadyExistsFailure = RestAPIClient.searchURLFailures(message.body)
|
alreadyExistsFailure = RestAPIClient.searchURLFailures(message.body)
|
||||||
|
|
||||||
print("alreadyExistsFailure / ", alreadyExistsFailure)
|
## print("alreadyExistsFailure / ", alreadyExistsFailure)
|
||||||
|
|
||||||
if alreadyExistsFailure.lower().strip() == "true":
|
if alreadyExistsFailure.lower().strip() == "true":
|
||||||
|
|
||||||
print("this record exists (failures). returning. doing nothing")
|
## print("this record exists (failures). returning. doing nothing")
|
||||||
|
|
||||||
return
|
##return
|
||||||
|
|
||||||
|
print ("skipped!!")
|
||||||
|
|
||||||
print("didn't exist in success or errors. will process now")
|
print("didn't exist in success or errors. will process now")
|
||||||
|
|
||||||
@@ -62,19 +97,24 @@ class MyListener(stomp.ConnectionListener):
|
|||||||
RestAPIClient.addDownloadFailure(message.body, "error from onmessage (consumer.py)")
|
RestAPIClient.addDownloadFailure(message.body, "error from onmessage (consumer.py)")
|
||||||
|
|
||||||
print("## ")
|
print("## ")
|
||||||
print("## starting > JMS consumer (yankee-sully-channels-monthly)")
|
print(f"## starting > JMS consumer ([{jmsQueue}]")
|
||||||
print("## ")
|
print("## ")
|
||||||
|
|
||||||
conn = stomp.Connection([('38.107.226.34', 61613)])
|
writeSullyURLToJMS()
|
||||||
|
connection_details = [(host, port)]
|
||||||
|
|
||||||
|
conn = stomp.Connection(connection_details)
|
||||||
|
|
||||||
conn.set_listener('', MyListener())
|
conn.set_listener('', MyListener())
|
||||||
|
|
||||||
conn.connect('admin', 'password', wait=True)
|
conn.connect(username, password, wait=True)
|
||||||
|
|
||||||
conn.subscribe('/queue/yankee-sully-channels-monthly', id=1, ack='auto', headers={'activemq.prefetchSize': 10})
|
conn.subscribe(f'/queue/{jmsQueue}', id=1, ack='auto', headers={'activemq.prefetchSize': 10})
|
||||||
|
|
||||||
|
print(f"Subscribed to queue: {jmsQueue}")
|
||||||
|
|
||||||
print("## ")
|
print("## ")
|
||||||
print("## notification > connected to JMS server (yankee-sully-channels-monthly) 456")
|
print(f"## notification > connected to JMS server [{jmsQueue}] (upgrade)")
|
||||||
print("## ")
|
print("## ")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -82,5 +122,6 @@ while True:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
conn.disconnect()
|
conn.disconnect()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user