diff options
author | daniel-Jones <daniel@danieljon.es> | 2017-07-14 11:36:44 +0930 |
---|---|---|
committer | daniel-Jones <daniel@danieljon.es> | 2017-07-14 11:36:44 +0930 |
commit | b8fc0516910491b9413f499b4532d41428c9a970 (patch) | |
tree | 315d8d7fe2d57c720ef9cf068e26e6c7cfb5298f | |
parent | 3f848ce2c5af2c61b16d6f225820e5c2298e7af4 (diff) | |
download | slacklog-b8fc0516910491b9413f499b4532d41428c9a970.tar.gz slacklog-b8fc0516910491b9413f499b4532d41428c9a970.zip |
messages that have been edited now get updated in the database
-rw-r--r-- | main.py | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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(); |