3 Commits

Author SHA1 Message Date
Your Name
9aa071a32d crontab add 2025-02-13 15:42:42 -05:00
Your Name
8033b7a57b automated terminal push 2025-02-13 13:39:26 -05:00
Your Name
be3461d4a5 automated terminal push 2025-02-13 13:37:53 -05:00
9 changed files with 60 additions and 94 deletions

View File

@@ -3,54 +3,25 @@ import time
import re import re
import fnmatch import fnmatch
def check_download_exists_matching_url_version_one(url): def dowork():
print ("enter > downloads > exist check > version 1") ################################################################################################
match = re.search(r"https://sullygnome.com/channel/([^/]+)/(\d+)([a-z]+)/games", url.lower()) url = "https://sullygnome.com/channel/kaicenat/2023january/streams"
if not match: print("checking disk for the stuff...")
print(f"Invalid URL format. Could not extract channel name, year, or month.") print("url", url)
return fileExists = check_download_exists_matching_url(url)
channel_name, year, month = match.groups() print("file already exists / ",fileExists)
print("channel / ",channel_name) ################################################################################################
#print("year / ",year) def check_download_exists_matching_url(url):
#print("month / ",month) print ("hello?")
#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):
print ("enter > downloads > exist check > version 2")
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,16 +39,14 @@ def check_download_exists_matching_url_version_two(url):
print("month / ",month) print("month / ",month)
#file_pattern = f"{channel_name}*{month}*{year}*.csv"
## this is a problem. it works but if there 2 channels. ## this is a problem. it works but if there 2 channels.
## redbull and redbull2 this is throw false positives. ugh ## 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"*{channel_name} - game stats on Twitch in {month} {year} - SullyGnome.csv".lower()
file_pattern = f"{unicode_part} \({channel_name}\) - game stats on Twitch in {month} {year} - SullyGnome.csv".lower() for filename in os.listdir("/root/Downloads/"):
print("regex :",file_pattern)
for filename in os.listdir("/home/yankee/Downloads/"):
updated = filename.lower() updated = filename.lower()
@@ -91,7 +60,10 @@ def check_download_exists_matching_url_version_two(url):
else: else:
print(f"No matching CSV file found for channel '{channel_name}' in year '{year}' and month '{month}'. (version t55555wo)") print(f"No matching CSV file found for channel '{channel_name}' in year '{year}' and month '{month}'.")
return False return False
def shutDownRobot():
print("shutting down the robot now")

View File

@@ -10,6 +10,8 @@ import RestAPIClient
import DiskUtils import DiskUtils
from selenium.webdriver import FirefoxOptions from selenium.webdriver import FirefoxOptions
## https://sullygnome.com/channel/kaicenat/365/games"
def download(url): def download(url):
print(f"launch -> SullyGnomeRobot -> download() -> {url}") print(f"launch -> SullyGnomeRobot -> download() -> {url}")
@@ -26,6 +28,7 @@ def download(url):
print("url / ", driver.current_url) print("url / ", driver.current_url)
########################################## ##########################################
print("stage / start / tblControl_length check") print("stage / start / tblControl_length check")
@@ -84,41 +87,17 @@ def download(url):
print("file download started. now checking if exist before closing") print("file download started. now checking if exist before closing")
counter = 0
max_iterations = 5
while True: while True:
print(f"Loop iteration: {counter}")
counter += 1
if counter == max_iterations:
print(f"Loop exited after {max_iterations} iterations.")
print("shutting down the robot")
driver.quit()
print("robot shut down. breaking. and dying.")
RestAPIClient.addDownloadFailure(url,"file not found on disk")
print("stage / complete / database updated w/ FAILURE")
break
print("checking is file exists... [loop]") print("checking is file exists... [loop]")
existsAlreadyVersionOne = DiskUtils.check_download_exists_matching_url_version_one(url) existsAlready = DiskUtils.check_download_exists_matching_url(url)
print("file already exists (v1) / ",existsAlreadyVersionOne) print("file already exists / ",existsAlready)
if existsAlreadyVersionOne: if existsAlready:
print(f"The file matching the url '{url}' DOES INDEED exists. (version 1)") print(f"The file matching the url '{url}' exists.")
print("sleeping for 4 secs before shutting down robot") print("sleeping for 4 secs before shutting down robot")
@@ -130,10 +109,6 @@ def download(url):
print("robot shut down. breaking. and dying.") print("robot shut down. breaking. and dying.")
RestAPIClient.addDownloadSuccess(url)
print("stage / complete / database updated w/ success")
break break
else: else:
@@ -148,4 +123,8 @@ def download(url):
########################################## ##########################################
RestAPIClient.addDownloadSuccess(url)
print("stage / complete / database updated w/ success")
print(f"complete -> SullyGnomeRobot -> download() -> {url}") print(f"complete -> SullyGnomeRobot -> download() -> {url}")

View File

@@ -6,10 +6,10 @@ set -x
## ##
##cd /yankee-gnome-fire-consumer echo "init > consumer.bash"
echo "##" ####
echo "## init > yankee > consumer"
echo "##" cd /yankee-gnome-fire-consumer
python3 consumer.py python3 consumer.py

View File

@@ -2,13 +2,13 @@ import stomp
import time import time
import SullyGnomeRobot import SullyGnomeRobot
import RestAPIClient import RestAPIClient
import os
import signal
print("## ") print("## ")
print("## starting > JMS consumer (yankee-sully-channels-monthly)") print("## starting > JMS consumer (yankee-sully-channels-monthly)")
print("## ") print("## ")
## https://sullygnome.com/channel/yaritaiji/2024october/games
class MyListener(stomp.ConnectionListener): class MyListener(stomp.ConnectionListener):
def on_message(headers, message): def on_message(headers, message):
@@ -62,10 +62,11 @@ 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("## starting > (timed) JMS consumer (yankee-sully-channels-monthly)")
print("## ") print("## ")
conn = stomp.Connection([('38.107.226.34', 61613)])
conn = stomp.Connection([('67.220.70.106', 61613)])
conn.set_listener('', MyListener()) conn.set_listener('', MyListener())
@@ -74,13 +75,27 @@ conn.connect('admin', 'password', wait=True)
conn.subscribe('/queue/yankee-sully-channels-monthly', id=1, ack='auto', headers={'activemq.prefetchSize': 10}) conn.subscribe('/queue/yankee-sully-channels-monthly', id=1, ack='auto', headers={'activemq.prefetchSize': 10})
print("## ") print("## ")
print("## notification > connected to JMS server (yankee-sully-channels-monthly) 456") print("## notification > connected to JMS server (yankee-sully-channels-monthly) 3333")
print("## ") print("## ")
while True: start_time = time.time()
print("start time /",start_time)
counter=0
while time.time() - start_time < 60:
counter = counter + 1
pass pass
print("waiting for 60 seconds of elapsed time: ",counter)
time.sleep(1) time.sleep(1)
print("it's been 60 seconds. what up though?")
conn.disconnect() conn.disconnect()
print("disconnected from JMS. i'll holla!")

View File

@@ -1,7 +1,7 @@
SHELL=/bin/bash SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
48 20 * * * /yankee-gnome-fire-consumer/consumer.bash >> /var/log/yankee.log * * * * * /yankee-gnome-fire-consumer/consumer.bash >> /var/log/yankee.log
* * * * * /yankee-gnome-fire-consumer/ping.bash >> /var/log/cron.log 2>&1 * * * * * /yankee-gnome-fire-consumer/ping.bash >> /var/log/cron.log 2>&1

0
recycle/ping.bash → ping.bash Executable file → Normal file
View File

View File

@@ -42,11 +42,11 @@ def buildCronExecuteTime():
current_time = datetime.datetime.now() current_time = datetime.datetime.now()
new_minute = (current_time.minute + 2) % 60 new_minute = (current_time.minute + 2) % 60 # The % operator performs the wrap-around
print("new_minute / ",new_minute) print("new_minute / ",new_minute)
new_hour = (current_time.hour + 5) % 24 new_hour = current_time.hour + (current_time.minute + 5) // 60 # Integer division for hour increment
print("new_hour / ",new_hour) print("new_hour / ",new_hour)
@@ -56,11 +56,11 @@ def buildCronExecuteTime():
def buildCronSituation(): def buildCronSituation():
##return "* * * * * /yankee-gnome-fire-consumer/consumer.bash >> " + buildLogFileName() return "* * * * * /yankee-gnome-fire-consumer/consumer.bash >> " + buildLogFileName()
return buildCronExecuteTime() + " /yankee-gnome-fire-consumer/consumer.bash >> " + buildLogFileName() ##return buildCronExecuteTime() + "/yankee-gnome-fire-consumer/consumer.bash >> " + buildLogFileName()
##return buildCronExecuteTime() +" /yankee-gnome-fire-consumer/consumer.bash >> " + buildLogFileName() + " 2>&1" ##return buildCronExecuteTime() +"/yankee-gnome-fire-consumer/consumer.bash >> " + buildLogFileName() + " 2>&1"
##return buildCronExecuteTime() +" python3 /yankee-gnome-fire-consumer/consumer.py >> " + buildLogFileName() + " 2>&1" ##return buildCronExecuteTime() +" python3 /yankee-gnome-fire-consumer/consumer.py >> " + buildLogFileName() + " 2>&1"