workaround for connection problems

This commit is contained in:
Rripped
2022-03-29 12:04:49 +02:00
parent 4c517998ba
commit 4afd1ab87b
3 changed files with 39 additions and 14 deletions

View File

@@ -83,16 +83,20 @@ class API_Handler:
Returns:
list: list of keywords
"""
keywords = []
with r.Session() as s:
headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)}
req = s.get(self.db_adress + "/keywords", headers=headers)
print(req.status_code)
keywords_json = req.json()["data"]
keywords = []
for keyword in keywords_json:
keywords.append(keyword["keyword"])
if(req.status_code == 200):
keywords_json = req.json()["data"]
for keyword in keywords_json:
keywords.append(keyword["keyword"])
return keywords
else:
return self.get_user_keywords(user_id) # might end in infinite loop!!
return keywords
def set_keyword(self, user_id, keyword):
@@ -193,8 +197,10 @@ class API_Handler:
with r.Session() as s:
headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)}
req = s.get(self.db_adress + "/transactions", headers=headers)
transactions_dict = dict(req.json()["data"])
return transactions_dict
if req.status_code == 200:
transactions_dict = dict(req.json()["data"])
return transactions_dict
def set_transaction(self, user_id, count, price, symbol, timestamp):