diff --git a/main.py b/main.py index ea72c75..8ea41ee 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,6 @@ +import time +import ipdb +import json import random import qrcode import requests @@ -143,22 +146,42 @@ class Bump: if add_params != None: params.update(add_params) - r = requests.post(url, params) + messages = requests.post(url, params).json() - if r.json() == {} or r.json() == None: - return {} - elif type(r.json()) == list: - messages = [] - for message in r.json(): - messages.append(self.decrypt(message.get('data'))) + if messages == {} or messages == None or messages == []: + return [{}] + elif type(messages) == list: + for message in messages: + message['data'] = self.decrypt(message.get('data')) return messages else: - return self.decrypt(r.json().get('data')) + messages['data'] = self.decrypt(messages.get('data')) + return [messages] - def alert(self): + + def load_log(self): + with open('.bump_log', "r+") as f: + return f.readlines() + + def save_log(self, message): + with open('.bump_log', "a") as f: + f.write(self.to_log_line(message)) + + def to_log_line(self, message): + return json.dumps(message) + "\n" + + def alert(self, sleep_time=1): + log = self.load_log() while True: - time.sleep(1) + time.sleep(sleep_time) + messages = self.list() + for message in messages: + if self.to_log_line(message) not in log and message != {}: + print(message['data']) + self.save_log(message) + log = self.load_log() + if __name__ == '__main__':