From ec88faa437d6e995927c50372dfde540bd301653 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Wed, 5 Feb 2025 15:30:34 -0500 Subject: [PATCH 1/4] Changed HTTP status code checking to catch success codes other than 200 --- discorss.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/discorss.py b/discorss.py index 46224b3..7e49771 100755 --- a/discorss.py +++ b/discorss.py @@ -26,6 +26,7 @@ log_file_name = r"/app.log" # Yes, I know you "can't parse HTML with regex", but # just watch me. html_filter = re.compile(r"\<\/?([A-Za-z \"\=])*\>") +success_codes = ['200', '201', '202', '203', '204', '205', '206'] def get_description(feed): @@ -97,7 +98,7 @@ def main(): r = requests.post( hook["webhook"], data=webhook_string, headers=custom_header ) - if r.status_code != "200": + if r.status_code not in success_codes: print( "Error {} while trying to post {}".format( r.status_code, hook["webhook"] From bd693f6f42a11b38c23d82731486b5fb53107c2e Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Wed, 5 Feb 2025 23:27:49 -0500 Subject: [PATCH 2/4] Added check for non-existant lastupdate key --- .gitignore | 3 ++- discorss.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f8ec04c..d48e085 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.conf *.txt -log/ \ No newline at end of file +log/ +*.bak \ No newline at end of file diff --git a/discorss.py b/discorss.py index bd1f182..b869e7c 100755 --- a/discorss.py +++ b/discorss.py @@ -59,7 +59,10 @@ def main(): with open(config_file_path, "r") as config_file: app_config = json.load(config_file) now = time.mktime(time.localtime()) - last_check = app_config["lastupdate"] + try: + last_check = app_config["lastupdate"] + except KeyError: + last_check = now - 21600 # first run, no lastupdate, check up to 6 hours ago for i, hook in enumerate(app_config["feeds"]): # Get the feed feed = feedparser.parse(hook["url"]) From 87193d0f9402a3578e4b6e18952338d45dcc48da Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Wed, 5 Feb 2025 23:28:14 -0500 Subject: [PATCH 3/4] Added sha3_512 hash of post title, to migrate from using time --- discorss.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/discorss.py b/discorss.py index b869e7c..7eb752e 100755 --- a/discorss.py +++ b/discorss.py @@ -69,7 +69,8 @@ def main(): published_time = time.mktime(feed.entries[0]["published_parsed"]) published_time = published_time + hook["offset"] print("Parsing feed {}...".format(hook["name"])) - new_hash = hashlib.sha3_512(feed.entries[0]["title"]) + # Hash the title of the latest post and use that to determine if it's been posted + new_hash = hashlib.sha3_512(bytes(feed.entries[0]["title"], 'utf-8')).hexdigest() try: if hook["lasthash"] != new_hash: app_config["feeds"][i]["lasthash"] = new_hash From a188f8ee5d129842842f52297548753b36fcd536 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Wed, 5 Feb 2025 23:40:27 -0500 Subject: [PATCH 4/4] Removed part of time check --- discorss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discorss.py b/discorss.py index 7eb752e..6cff9c7 100755 --- a/discorss.py +++ b/discorss.py @@ -105,8 +105,8 @@ def main(): "content-type": "application/json", } webhook_string = json.dumps(webhook) - # print(webhook_string) - if published_time > last_check and published_time < now: + + if published_time > last_check: r = requests.post( hook["webhook"], data=webhook_string, headers=custom_header )