formatting and docu additions

This commit is contained in:
Rripped 2022-03-29 08:41:09 +02:00
parent 218f70f541
commit bf8fdbf848
2 changed files with 32 additions and 16 deletions

View File

@ -13,8 +13,29 @@ import sys
import os
import requests as r
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):
"""initializes the API_Handler class
@ -33,6 +54,7 @@ class API_Handler:
else:
self.token = None
def reauthorize(self, email, password):
"""set new credentials
@ -50,6 +72,7 @@ class API_Handler:
self.token = None
return None
def get_user_keywords(self, user_id):
"""gets the keywords of the user
@ -70,6 +93,7 @@ class API_Handler:
return keywords
def set_keyword(self, user_id, keyword):
"""sets the keyword of the user
@ -86,6 +110,7 @@ class API_Handler:
return req.status_code
def delete_keyword(self, user_id, keyword):
"""deletes the keyword of the user
@ -102,6 +127,7 @@ class API_Handler:
return req.status_code
def get_user_shares(self, user_id):
"""gets the shares of the user
@ -121,6 +147,7 @@ class API_Handler:
return shares
def set_share(self, user_id, symbol):
"""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)
return req.status_code
def delete_share(self, user_id, symbol):
"""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)
return req.status_code
def get_user_transactions(self, user_id):
"""gets the transactions of the user
@ -166,6 +195,7 @@ class API_Handler:
transactions_dict = dict(req.json()["data"])
return transactions_dict
def set_transaction(self, user_id, count, price, symbol, timestamp):
"""sets the transaction of the user
@ -185,6 +215,7 @@ class API_Handler:
req = s.post(self.db_adress + "/transaction", json=transaction, headers=headers)
return req.status_code
def get_user_portfolio(self, user_id):
"""gets the portfolio of the user

View File

@ -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