fixes handling json list output

This commit is contained in:
Raphael Maenle 2021-12-10 17:59:52 +01:00
parent 424812432c
commit 36d5bd42ff

27
main.py
View File

@ -125,20 +125,41 @@ class Bump:
return self.get_post("pop") return self.get_post("pop")
def list(self): def list(self):
return self.get_post("list") params = {
'minutes': 2
}
return self.get_post("list", params)
def clear(self): def clear(self):
return self.get_post("clear") return self.get_post("clear")
def get_post(self, mechanism): def get_post(self, mechanism, add_params = None):
url = self.URL + mechanism url = self.URL + mechanism
params = { params = {
'sender': self.get_sender() 'sender': self.get_sender()
} }
if add_params != None:
params.update(add_params)
r = requests.post(url, params) r = requests.post(url, params)
if r.json() == {}:
if r.json() == {} or r.json() == None:
return {} return {}
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')) return self.decrypt(r.json().get('data'))
def alert(self):
while True:
time.sleep(1)
if __name__ == '__main__': if __name__ == '__main__':
b = Bump() b = Bump()