formatting and docu additions
This commit is contained in:
parent
218f70f541
commit
bf8fdbf848
@ -13,8 +13,29 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import requests as r
|
import requests as r
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class API_Handler:
|
class API_Handler:
|
||||||
#class for communicating with webservice to get data from database
|
"""class for interacting with the api webservice
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
db_adress (string): adress of the database
|
||||||
|
token (string): auth token for api
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
reauthorize(email, password): set new credentials
|
||||||
|
get_user_keywords(user_id): gets the keywords of the user
|
||||||
|
set_keyword(user_id, keyword): sets the keyword of the user
|
||||||
|
delete_keyword(user_id, keyword): deletes the keyword of the user
|
||||||
|
get_user_shares(user_id): gets the shares of the user
|
||||||
|
set_share(user_id, symbol): sets the share of the user
|
||||||
|
delete_share(user_id, symbol): deletes the share of the user
|
||||||
|
get_user_transactions(user_id): gets the transactions of the user
|
||||||
|
set_transaction(user_id, transaction): sets the transaction of the user
|
||||||
|
delete_transaction(user_id, transaction): deletes the transaction of the user
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, db_adress, email, password):
|
def __init__(self, db_adress, email, password):
|
||||||
"""initializes the API_Handler class
|
"""initializes the API_Handler class
|
||||||
|
|
||||||
@ -33,6 +54,7 @@ class API_Handler:
|
|||||||
else:
|
else:
|
||||||
self.token = None
|
self.token = None
|
||||||
|
|
||||||
|
|
||||||
def reauthorize(self, email, password):
|
def reauthorize(self, email, password):
|
||||||
"""set new credentials
|
"""set new credentials
|
||||||
|
|
||||||
@ -50,6 +72,7 @@ class API_Handler:
|
|||||||
self.token = None
|
self.token = None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_user_keywords(self, user_id):
|
def get_user_keywords(self, user_id):
|
||||||
"""gets the keywords of the user
|
"""gets the keywords of the user
|
||||||
|
|
||||||
@ -70,6 +93,7 @@ class API_Handler:
|
|||||||
|
|
||||||
return keywords
|
return keywords
|
||||||
|
|
||||||
|
|
||||||
def set_keyword(self, user_id, keyword):
|
def set_keyword(self, user_id, keyword):
|
||||||
"""sets the keyword of the user
|
"""sets the keyword of the user
|
||||||
|
|
||||||
@ -86,6 +110,7 @@ class API_Handler:
|
|||||||
|
|
||||||
return req.status_code
|
return req.status_code
|
||||||
|
|
||||||
|
|
||||||
def delete_keyword(self, user_id, keyword):
|
def delete_keyword(self, user_id, keyword):
|
||||||
"""deletes the keyword of the user
|
"""deletes the keyword of the user
|
||||||
|
|
||||||
@ -102,6 +127,7 @@ class API_Handler:
|
|||||||
|
|
||||||
return req.status_code
|
return req.status_code
|
||||||
|
|
||||||
|
|
||||||
def get_user_shares(self, user_id):
|
def get_user_shares(self, user_id):
|
||||||
"""gets the shares of the user
|
"""gets the shares of the user
|
||||||
|
|
||||||
@ -121,6 +147,7 @@ class API_Handler:
|
|||||||
|
|
||||||
return shares
|
return shares
|
||||||
|
|
||||||
|
|
||||||
def set_share(self, user_id, symbol):
|
def set_share(self, user_id, symbol):
|
||||||
"""sets the share of the user
|
"""sets the share of the user
|
||||||
|
|
||||||
@ -136,6 +163,7 @@ class API_Handler:
|
|||||||
req = s.post(self.db_adress + "/share", json={"symbol": symbol}, headers=headers)
|
req = s.post(self.db_adress + "/share", json={"symbol": symbol}, headers=headers)
|
||||||
return req.status_code
|
return req.status_code
|
||||||
|
|
||||||
|
|
||||||
def delete_share(self, user_id, symbol):
|
def delete_share(self, user_id, symbol):
|
||||||
"""deletes the share of the user
|
"""deletes the share of the user
|
||||||
|
|
||||||
@ -151,6 +179,7 @@ class API_Handler:
|
|||||||
req = s.delete(self.db_adress + "/share", json={"symbol": symbol}, headers=headers)
|
req = s.delete(self.db_adress + "/share", json={"symbol": symbol}, headers=headers)
|
||||||
return req.status_code
|
return req.status_code
|
||||||
|
|
||||||
|
|
||||||
def get_user_transactions(self, user_id):
|
def get_user_transactions(self, user_id):
|
||||||
"""gets the transactions of the user
|
"""gets the transactions of the user
|
||||||
|
|
||||||
@ -166,6 +195,7 @@ class API_Handler:
|
|||||||
transactions_dict = dict(req.json()["data"])
|
transactions_dict = dict(req.json()["data"])
|
||||||
return transactions_dict
|
return transactions_dict
|
||||||
|
|
||||||
|
|
||||||
def set_transaction(self, user_id, count, price, symbol, timestamp):
|
def set_transaction(self, user_id, count, price, symbol, timestamp):
|
||||||
"""sets the transaction of the user
|
"""sets the transaction of the user
|
||||||
|
|
||||||
@ -185,6 +215,7 @@ class API_Handler:
|
|||||||
req = s.post(self.db_adress + "/transaction", json=transaction, headers=headers)
|
req = s.post(self.db_adress + "/transaction", json=transaction, headers=headers)
|
||||||
return req.status_code
|
return req.status_code
|
||||||
|
|
||||||
|
|
||||||
def get_user_portfolio(self, user_id):
|
def get_user_portfolio(self, user_id):
|
||||||
"""gets the portfolio of the user
|
"""gets the portfolio of the user
|
||||||
|
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
"""
|
|
||||||
script for database interaction
|
|
||||||
"""
|
|
||||||
__author__ = "Florian Kellermann, Linus Eickhoff"
|
|
||||||
__date__ = "15.03.2022"
|
|
||||||
__version__ = "0.0.1"
|
|
||||||
__license__ = "None"
|
|
||||||
|
|
||||||
# get db_key from env
|
|
||||||
|
|
||||||
class DB_Handler:
|
|
||||||
|
|
||||||
def __init__(self, db_adress):
|
|
||||||
# tbd
|
|
||||||
return
|
|
Loading…
Reference in New Issue
Block a user