added user funcs of api
This commit is contained in:
parent
2e48d2a27e
commit
30bccbf238
@ -74,6 +74,51 @@ class API_Handler:
|
||||
return None
|
||||
|
||||
|
||||
def get_user(self, user_id, max_retries=10):
|
||||
"""gets the shares of the user
|
||||
|
||||
Args:
|
||||
user_id (int): id of the user
|
||||
max_retries (int): max retries for the request
|
||||
|
||||
Returns:
|
||||
json: json of user infos
|
||||
"""
|
||||
if max_retries <= 0:
|
||||
return None
|
||||
|
||||
with r.Session() as s:
|
||||
headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)}
|
||||
req = s.get(self.db_adress + "/user", headers=headers)
|
||||
if(req.status_code == 200):
|
||||
return req.json()["data"]
|
||||
|
||||
else:
|
||||
return self.get_user(user_id, max_retries-1)
|
||||
|
||||
|
||||
def get_all_users(self, max_retries=10):
|
||||
"""gets all users
|
||||
|
||||
Args:
|
||||
max_retries (int): max retries for the request
|
||||
|
||||
Returns:
|
||||
list: list of users
|
||||
"""
|
||||
if max_retries <= 0:
|
||||
return None
|
||||
|
||||
with r.Session() as s:
|
||||
headers = {'Authorization': 'Bearer ' + self.token}
|
||||
req = s.get(self.db_adress + "/users", headers=headers)
|
||||
if(req.status_code == 200):
|
||||
return req.json()["data"]
|
||||
|
||||
else:
|
||||
return self.get_all_users(max_retries-1)
|
||||
|
||||
|
||||
def get_user_keywords(self, user_id, max_retries=10):
|
||||
"""gets the keywords of the user
|
||||
|
||||
@ -282,10 +327,11 @@ class API_Handler:
|
||||
if __name__ == "__main__":
|
||||
|
||||
print("This is a module for the telegram bot. It is not intended to be run directly.")
|
||||
handler = API_Handler("https://aktienbot.flokaiser.com/api", "bot@example.com", "bot")
|
||||
handler = API_Handler("https://gruppe1.testsites.info/api", "bot@example.com", "bot")
|
||||
print(handler.token)
|
||||
keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is currently mine (Linus)
|
||||
print(keywords)
|
||||
shares = handler.get_user_portfolio(user_id = 1709356058)
|
||||
print(handler.set_cron_interval(user_id = 1709356058, cron_interval = "0 0 * * *"))
|
||||
print(shares)
|
||||
sys.exit(1)
|
Loading…
Reference in New Issue
Block a user