From b8fc0516910491b9413f499b4532d41428c9a970 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Fri, 14 Jul 2017 11:36:44 +0930 Subject: messages that have been edited now get updated in the database --- main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.py b/main.py index f930004..cda384f 100644 --- a/main.py +++ b/main.py @@ -143,6 +143,14 @@ def checkifentryexists(ts): return True; return False; +def getmsg(ts): + ''' + retrieves a message from the database + returns message from the database corresponding to the timestamp provided + args: ts = timestamp to search for + ''' + return messagedb.find_one({"timestamp": ts})['message']; + def collectbants(): ''' collects and stores messages, handles message edits @@ -172,6 +180,13 @@ def collectbants(): message_id = messagedb.insert_one(query).inserted_id; else: print("already exists.", data['messages'][i]['ts']); + if ("edited" in data['messages'][i]): + print("messaged has been edited at some point, checking", data['messages'][i]['ts']); + if (getmsg(data['messages'][i]['ts']) != data['messages'][i]['text']): + print("message does NOT match the database, updating"); + messagedb.update({"timestamp" : data['messages'][i]['ts']}, {"$set":{"message": data['messages'][i]['text']}}) + else: + print("message matches, we're ok!"); if __name__ == "__main__": cfg = configparser.ConfigParser(); -- cgit v1.2.3