Compare commits

..

5 commits

Author SHA1 Message Date
A.M. Rowsell
5c91dccc9e Merge branch 'main' into hash 2025-02-05 23:41:23 -05:00
A.M. Rowsell
a188f8ee5d
Removed part of time check 2025-02-05 23:40:27 -05:00
A.M. Rowsell
87193d0f94
Added sha3_512 hash of post title, to migrate from using time 2025-02-05 23:28:14 -05:00
A.M. Rowsell
bd693f6f42
Added check for non-existant lastupdate key 2025-02-05 23:27:49 -05:00
A.M. Rowsell
ec88faa437
Changed HTTP status code checking to catch success codes other than 200 2025-02-05 15:30:34 -05:00
2 changed files with 12 additions and 6 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
*.conf
*.txt
log/
log/
*.bak

View file

@ -27,6 +27,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):
@ -59,14 +60,18 @@ 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"])
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
@ -101,12 +106,12 @@ 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
)
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"]