From 36d5bd42ff8c4e2b635c207c0922aa0e0ee6c29b Mon Sep 17 00:00:00 2001 From: raphael Date: Fri, 10 Dec 2021 17:59:52 +0100 Subject: [PATCH] fixes handling json list output --- main.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index b9fa735..ea72c75 100644 --- a/main.py +++ b/main.py @@ -125,20 +125,41 @@ class Bump: return self.get_post("pop") def list(self): - return self.get_post("list") + params = { + 'minutes': 2 + } + return self.get_post("list", params) def clear(self): return self.get_post("clear") - def get_post(self, mechanism): + def get_post(self, mechanism, add_params = None): url = self.URL + mechanism + params = { 'sender': self.get_sender() } + + if add_params != None: + params.update(add_params) + r = requests.post(url, params) - if r.json() == {}: + + if r.json() == {} or r.json() == None: return {} - return self.decrypt(r.json().get('data')) + elif type(r.json()) == list: + messages = [] + for message in r.json(): + messages.append(self.decrypt(message.get('data'))) + + return messages + else: + return self.decrypt(r.json().get('data')) + + def alert(self): + while True: + time.sleep(1) + if __name__ == '__main__': b = Bump()