From 9402ce3c28ffbb4eb3fad0f50427afb421b09630 Mon Sep 17 00:00:00 2001 From: Fotoente Date: Sat, 26 Feb 2022 07:43:48 +0100 Subject: [PATCH] Fixed small error, so it won't finish with one or fewer notes or one and fewer reactions. --- miceco.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/miceco.py b/miceco.py index 578be96..c19b14a 100644 --- a/miceco.py +++ b/miceco.py @@ -98,8 +98,11 @@ while True: formerTimestamp = lastTimestamp - lastTime = noteList[len(noteList) - 1]["createdAt"] - lastTimestamp = int(datetime.timestamp(datetime.strptime(lastTime, '%Y-%m-%dT%H:%M:%S.%f%z')) * 1000) + if not len(noteList) <= 1: # If there is one or less notes, then break the while loop + lastTime = noteList[len(noteList) - 1]["createdAt"] + lastTimestamp = int(datetime.timestamp(datetime.strptime(lastTime, '%Y-%m-%dT%H:%M:%S.%f%z')) * 1000) + else: + break for element in noteList: if element["text"] is None: # Skip Notes without text @@ -116,7 +119,8 @@ for element in noteList: if emojis is not None: for emoji in emojis: - if emoji["name"].find("@") == -1: # Only emojis from the own instance, because reactions will be in "emojis" + if emoji["name"].find( + "@") == -1: # Only emojis from the own instance, because reactions will be in "emojis" # too if not emoji["name"] in doubleList: doubleList.append(emoji["name"]) # Easy way to prevent a double emoji in the list. @@ -132,7 +136,7 @@ for element in noteList: if element["cw"] is not None: emojiList[index]["count"] += element["cw"].count(emojiList[index]["emoji"]) # Count those Emojis, that # are in this note CW text - + # Process UTF8 Emojis if element["cw"] is not None: UTF8text = element["text"] + " " + element["cw"] @@ -181,9 +185,11 @@ if getReactions: reactionList.append(jsonObj) formerTimestamp = lastTimestamp - - lastTime = reactionList[len(reactionList) - 1]["createdAt"] - lastTimestamp = int(datetime.timestamp(datetime.strptime(lastTime, '%Y-%m-%dT%H:%M:%S.%f%z')) * 1000) + if not len(reactionList) <=1: + lastTime = reactionList[len(reactionList) - 1]["createdAt"] + lastTimestamp = int(datetime.timestamp(datetime.strptime(lastTime, '%Y-%m-%dT%H:%M:%S.%f%z')) * 1000) + else: + break react = "" index = None @@ -246,4 +252,4 @@ try: req.raise_for_status() except requests.exceptions.HTTPError as err: print("Couldn't create Posts! " + str(err)) - sys.exit(1) \ No newline at end of file + sys.exit(1)