diff --git a/.gitignore b/.gitignore index d48e085..f8ec04c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ *.conf *.txt -log/ -*.bak \ No newline at end of file +log/ \ No newline at end of file diff --git a/discorss.py b/discorss.py index 3cd9ce6..bd1f182 100755 --- a/discorss.py +++ b/discorss.py @@ -27,7 +27,6 @@ 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): @@ -60,18 +59,14 @@ def main(): with open(config_file_path, "r") as config_file: app_config = json.load(config_file) now = time.mktime(time.localtime()) - try: - last_check = app_config["lastupdate"] - except KeyError: - last_check = now - 21600 # first run, no lastupdate, check up to 6 hours ago + last_check = app_config["lastupdate"] 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"])) - # 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() + new_hash = hashlib.sha3_512(feed.entries[0]["title"]) try: if hook["lasthash"] != new_hash: app_config["feeds"][i]["lasthash"] = new_hash @@ -106,12 +101,12 @@ def main(): "content-type": "application/json", } webhook_string = json.dumps(webhook) - - if published_time > last_check: + # print(webhook_string) + if published_time > last_check and published_time < now: r = requests.post( hook["webhook"], data=webhook_string, headers=custom_header ) - if r.status_code not in success_codes: + if r.status_code != "200": print( "Error {} while trying to post {}".format( r.status_code, hook["webhook"]