diff --git a/api/app/auth.py b/api/app/auth.py index e1a4bba..e96d28a 100644 --- a/api/app/auth.py +++ b/api/app/auth.py @@ -17,9 +17,7 @@ def verify_token(token): if token is None: return False - # We decided to append the user id to the bearer token using ":" as separator to select an specific user - # To validate the token we can remove the user id since we only validate the token and not the user id - if ':' in token: + if ':' in token: # Bot token token = token.split(":")[0] try: diff --git a/api/app/blueprints/keyword.py b/api/app/blueprints/keyword.py index e3edc21..4412621 100644 --- a/api/app/blueprints/keyword.py +++ b/api/app/blueprints/keyword.py @@ -31,10 +31,9 @@ def add_keyword(data): key = data['keyword'] - # Check if keyword already exists check_keyword = db.session.query(Keyword).filter_by(keyword=key, email=email).first() if check_keyword is None: - # Keyword doesn't exist yet for this user -> add it + # Keyword doesn't exist yet for this user new_keyword = Keyword( email=email, keyword=key @@ -55,17 +54,17 @@ def add_keyword(data): def remove_keyword(data): email = get_email_or_abort_401() - # Check if request data is valid if not check_if_keyword_data_exists(data): abort(400, message="Keyword missing") - # Check if keyword exists - check_keyword = db.session.query(Keyword).filter_by(keyword=data['keyword'], email=email).first() + key = data['keyword'] + + check_keyword = db.session.query(Keyword).filter_by(keyword=key, email=email).first() + if check_keyword is None: return abort(500, "Keyword doesn't exist for this user") else: - # Keyword exists -> delete it - db.session.query(Keyword).filter_by(keyword=data['keyword'], email=email).delete() + db.session.query(Keyword).filter_by(keyword=key, email=email).delete() db.session.commit() return make_response({}, 200, "Successfully removed keyword") @@ -81,8 +80,6 @@ def get_keywords(): return_keywords = [] keywords = db.session.query(Keyword).filter_by(email=email).all() - # If no keywords exist for this user -> return empty list - # Otherwise iterate over all keywords, convert them to json and add them to the return list if keywords is not None: for row in keywords: return_keywords.append(row.as_dict()) diff --git a/api/app/blueprints/portfolio.py b/api/app/blueprints/portfolio.py index 9ead66b..2b6ab02 100644 --- a/api/app/blueprints/portfolio.py +++ b/api/app/blueprints/portfolio.py @@ -2,7 +2,7 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.1" +__version__ = "1.0.0" import os @@ -25,25 +25,19 @@ def get_portfolio(): email = get_email_or_abort_401() return_portfolio = [] + transactions = db.session.execute("SELECT symbol, SUM(count), SUM(price), MAX(time) FROM `transactions` WHERE email = '" + email + "' GROUP BY symbol;").all() - # Get all transactions of current user - transactions = db.session.execute("SELECT isin, comment, SUM(count), SUM(price), MAX(time) FROM `transactions` WHERE email = '" + email + "' GROUP BY isin, comment;").all() - - # If there are no transactions, return empty portfolio - # Otherwise calculate portfolio if transactions is not None: for row in transactions: data = { - "isin": row[0], - "comment": row[1], - "count": row[2], - # "calculated_price": row[3], - "last_transaction": row[4], + "symbol": row[0], + "count": row[1], + # "calculated_price": row[2], + "last_transaction": row[3], 'current_price': 0 } - # Add current share value to portfolio - query_share_price = db.session.query(SharePrice).filter_by(isin=row[0]).order_by(SharePrice.date.desc()).first() + query_share_price = db.session.query(SharePrice).filter_by(symbol=row[0]).order_by(SharePrice.date.desc()).first() if query_share_price is not None: data['current_price'] = query_share_price.as_dict()['price'] diff --git a/api/app/blueprints/share_price.py b/api/app/blueprints/share_price.py index 50f57ae..aa2a302 100644 --- a/api/app/blueprints/share_price.py +++ b/api/app/blueprints/share_price.py @@ -2,16 +2,17 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.1" +__version__ = "1.0.0" import datetime import os from apiflask import APIBlueprint, abort -from app.auth import auth + +from app.models import SharePrice from app.db import database as db from app.helper_functions import make_response -from app.models import SharePrice +from app.auth import auth from app.schema import SymbolPriceSchema share_price_blueprint = APIBlueprint('share_price', __name__, url_prefix='/api') @@ -23,8 +24,7 @@ __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file @share_price_blueprint.auth_required(auth) @share_price_blueprint.doc(summary="Returns all transaction symbols", description="Returns all transaction symbols for all users") def get_transaction_symbols(): - # Get all transaction symbols - symbols = db.session.execute("SELECT isin FROM `transactions` GROUP BY isin;").all() + symbols = db.session.execute("SELECT symbol FROM `transactions` GROUP BY symbol;").all() return_symbols = [] for s in symbols: @@ -37,11 +37,10 @@ def get_transaction_symbols(): @share_price_blueprint.output({}, 200) @share_price_blueprint.input(schema=SymbolPriceSchema) @share_price_blueprint.auth_required(auth) -@share_price_blueprint.doc(summary="Adds new price for isin", description="Adds new price to database") +@share_price_blueprint.doc(summary="Returns all transaction symbols", description="Returns all transaction symbols for all users") def add_symbol_price(data): - # Check if required data is available - if not check_if_isin_data_exists(data): - abort(400, message="ISIN missing") + if not check_if_symbol_data_exists(data): + abort(400, message="Symbol missing") if not check_if_price_data_exists(data): abort(400, message="Price missing") @@ -49,11 +48,14 @@ def add_symbol_price(data): if not check_if_time_data_exists(data): abort(400, message="Time missing") - # Add share price + symbol = data['symbol'] + price = data['price'] + time = data['time'] + share_price = SharePrice( - isin=data['isin'], - price=data['price'], - date=datetime.datetime.strptime(data['time'], '%Y-%m-%dT%H:%M:%S.%fZ'), + symbol=symbol, + price=price, + date=datetime.datetime.strptime(time, '%Y-%m-%dT%H:%M:%S.%fZ'), ) db.session.add(share_price) @@ -62,11 +64,11 @@ def add_symbol_price(data): return make_response(share_price.as_dict(), 200, "Successfully added price") -def check_if_isin_data_exists(data): - if 'isin' not in data: +def check_if_symbol_data_exists(data): + if 'symbol' not in data: return False - if data['isin'] == "" or data['isin'] is None: + if data['symbol'] == "" or data['symbol'] is None: return False return True diff --git a/api/app/blueprints/shares.py b/api/app/blueprints/shares.py index ad0ffe2..56dad69 100644 --- a/api/app/blueprints/shares.py +++ b/api/app/blueprints/shares.py @@ -2,16 +2,17 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.1" +__version__ = "1.0.0" import os from apiflask import APIBlueprint, abort + from app.auth import auth from app.db import database as db from app.helper_functions import make_response, get_email_or_abort_401 from app.models import Share -from app.schema import SymbolSchema, SymbolResponseSchema, DeleteSuccessfulSchema, SymbolRemoveSchema +from app.schema import SymbolSchema, SymbolResponseSchema, DeleteSuccessfulSchema shares_blueprint = APIBlueprint('share', __name__, url_prefix='/api') __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) @@ -25,21 +26,17 @@ __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file def add_symbol(data): email = get_email_or_abort_401() - # Check if required data is available - if not check_if_isin_data_exists(data): - abort(400, message="ISIN missing") + if not check_if_symbol_data_exists(data): + abort(400, message="Symbol missing") - if not check_if_comment_data_exists(data): - abort(400, message="Comment missing") + symbol = data['symbol'] - # Check if share already exists - check_share = db.session.query(Share).filter_by(isin=data['isin'], email=email).first() + check_share = db.session.query(Share).filter_by(symbol=symbol, email=email).first() if check_share is None: - # Keyword doesn't exist yet for this user -> add it + # Keyword doesn't exist yet for this user new_symbol = Share( email=email, - isin=data['isin'], - comment=data['comment'] + symbol=symbol ) db.session.add(new_symbol) db.session.commit() @@ -51,23 +48,23 @@ def add_symbol(data): @shares_blueprint.route('/share', methods=['DELETE']) @shares_blueprint.output(DeleteSuccessfulSchema, 200) -@shares_blueprint.input(schema=SymbolRemoveSchema) +@shares_blueprint.input(schema=SymbolSchema) @shares_blueprint.auth_required(auth) @shares_blueprint.doc(summary="Removes existing symbol", description="Removes existing symbol for current user") def remove_symbol(data): email = get_email_or_abort_401() - # Check if required data is available - if not check_if_isin_data_exists(data): - abort(400, message="ISIN missing") + if not check_if_symbol_data_exists(data): + abort(400, message="Symbol missing") + + symbol = data['symbol'] + + check_share = db.session.query(Share).filter_by(symbol=symbol, email=email).first() - # Check if share exists - check_share = db.session.query(Share).filter_by(isin=data['isin'], email=email).first() if check_share is None: abort(500, "Symbol doesn't exist for this user") else: - # Delete share - db.session.query(Share).filter_by(isin=data['isin'], email=email).delete() + db.session.query(Share).filter_by(symbol=symbol, email=email).delete() db.session.commit() return make_response({}, 200, "Successfully removed symbol") @@ -83,8 +80,6 @@ def get_symbol(): return_symbols = [] symbols = db.session.query(Share).filter_by(email=email).all() - # If no shares exist for this user -> return empty list - # Otherwise iterate over all shares, convert them to json and add them to the return list if symbols is not None: for row in symbols: return_symbols.append(row.as_dict()) @@ -92,21 +87,11 @@ def get_symbol(): return make_response(return_symbols, 200, "Successfully loaded symbols") -def check_if_isin_data_exists(data): - if "isin" not in data: +def check_if_symbol_data_exists(data): + if "symbol" not in data: return False - if data['isin'] == "" or data['isin'] is None: - return False - - return True - - -def check_if_comment_data_exists(data): - if "comment" not in data: - return False - - if data['comment'] == "" or data['comment'] is None: + if data['symbol'] == "" or data['symbol'] is None: return False return True diff --git a/api/app/blueprints/telegram.py b/api/app/blueprints/telegram.py index b492a91..10aad9f 100644 --- a/api/app/blueprints/telegram.py +++ b/api/app/blueprints/telegram.py @@ -24,13 +24,11 @@ __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file def add_keyword(data): email = get_email_or_abort_401() - # Check if request data is valid if not check_if_telegram_user_id_data_exists(data): abort(400, message="User ID missing") query_user = get_user(email) - # Change user id query_user.telegram_user_id = data['telegram_user_id'] db.session.commit() diff --git a/api/app/blueprints/transactions.py b/api/app/blueprints/transactions.py index d34c799..da3b7bf 100644 --- a/api/app/blueprints/transactions.py +++ b/api/app/blueprints/transactions.py @@ -2,12 +2,13 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.1" +__version__ = "1.0.0" import datetime import os from apiflask import abort, APIBlueprint + from app.auth import auth from app.db import database as db from app.helper_functions import make_response, get_email_or_abort_401 @@ -26,27 +27,21 @@ __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file def add_transaction(data): email = get_email_or_abort_401() - # Check if required data is available - if not check_if_isin_data_exists(data): - abort(400, "ISIN missing") + if not check_if_symbol_data_exists(data): + abort(400, "Symbol missing") if not check_if_time_data_exists(data): abort(400, "Time missing") - if not check_if_comment_data_exists(data): - abort(400, "Comment missing") - if not check_if_count_data_exists(data): abort(400, "Count missing") if not check_if_price_data_exists(data): abort(400, "Price missing") - # Add transaction new_transaction = Transaction( email=email, - isin=data['isin'], - comment=data['comment'], + symbol=data['symbol'], time=datetime.datetime.strptime(data['time'], '%Y-%m-%dT%H:%M:%S.%fZ'), count=data['count'], price=data['price'] @@ -65,11 +60,8 @@ def get_transaction(): email = get_email_or_abort_401() return_transactions = [] - - # Get all transactions transactions = db.session.query(Transaction).filter_by(email=email).all() - # Iterate over transactions and add them to return_transactions if transactions is not None: for row in transactions: return_transactions.append(row.as_dict()) @@ -77,11 +69,11 @@ def get_transaction(): return make_response(return_transactions, 200, "Successfully loaded transactions") -def check_if_isin_data_exists(data): - if "isin" not in data: +def check_if_symbol_data_exists(data): + if "symbol" not in data: return False - if data['isin'] == "" or data['isin'] is None: + if data['symbol'] == "" or data['symbol'] is None: return False return True @@ -97,16 +89,6 @@ def check_if_time_data_exists(data): return True -def check_if_comment_data_exists(data): - if "comment" not in data: - return False - - if data['comment'] == "" or data['comment'] is None: - return False - - return True - - def check_if_count_data_exists(data): if "count" not in data: return False diff --git a/api/app/blueprints/user.py b/api/app/blueprints/user.py index cc6b510..196af26 100644 --- a/api/app/blueprints/user.py +++ b/api/app/blueprints/user.py @@ -28,8 +28,6 @@ def users(): abort_if_no_admin() res = [] - - # Query all users and convert them to dicts for i in User.query.all(): res.append(i.as_dict()) @@ -43,7 +41,6 @@ def users(): def user(): email = get_email_or_abort_401() - # Query current user query_user = get_user(email) return make_response(query_user.as_dict(), 200, "Successfully received current user data") @@ -54,26 +51,23 @@ def user(): @users_blueprint.input(schema=LoginDataSchema) @users_blueprint.doc(summary="Login", description="Returns jwt token if username and password match, otherwise returns error") def login(data): - # Check if required data is available if not check_if_password_data_exists(data): abort(400, "Password missing") if not check_if_email_data_exists(data): abort(400, "Email missing") - # Query current user - query_user = get_user(data['email']) + email = data['email'] + password = data['password'] - # Check if password matches - if not check_password(query_user.password, data['password'].encode("utf-8")): # Password incorrect + query_user = get_user(email) + + if not check_password(query_user.password, password.encode("utf-8")): # Password incorrect abort(500, message="Unable to login") - # Check if user is bot if query_user.email == current_app.config['BOT_EMAIL']: - # Set bot token valid for 1 year token = jwt.encode({'email': query_user.email, 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=365)}, current_app.config['SECRET_KEY'], "HS256") else: - # Set token valid for 1 day token = jwt.encode({'email': query_user.email, 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=1)}, current_app.config['SECRET_KEY'], "HS256") return make_response({"token": token}, 200, "Successfully logged in") @@ -84,7 +78,6 @@ def login(data): @users_blueprint.input(schema=RegisterDataSchema) @users_blueprint.doc(summary="Register", description="Registers user") def register(data): - # Check if required data is available if not check_if_email_data_exists(data): abort(400, "Email missing") @@ -94,16 +87,19 @@ def register(data): if not check_if_password_data_exists(data): abort(400, "Password missing") - # Check if user already exists - query_user = db.session.query(User).filter_by(email=data['email']).first() - if query_user is not None: + email = data['email'] + username = data['username'] + password = data['password'] + + query_user = db.session.query(User).filter_by(email=email).first() + + if query_user is not None: # Username already exist abort(500, message="Email already exist") - # Add user to database new_user = User( - email=data['email'], - username=data['username'], - password=hash_password(data['password']), + email=email, + username=username, + password=hash_password(password), admin=False, cron="0 8 * * *" ) @@ -121,14 +117,11 @@ def register(data): def update_user(data): email = get_email_or_abort_401() - # Query current user query_user = get_user(email) - # Check if password data is available -> if, change password if check_if_password_data_exists(data): query_user.password = hash_password(data['password']) - # Check if username data is available -> if, change username if check_if_username_data_exists(data): query_user.username = data['username'] @@ -145,18 +138,18 @@ def update_user(data): def set_admin(data): abort_if_no_admin() # Only admin users can do this - # Check if required data is available if not check_if_email_data_exists(data): abort(400, "Email missing") if not check_if_admin_data_exists(data): abort(400, "Admin data missing") - # Get user by email - query_user = get_user(data['email']) + email = data['email'] + admin = data['admin'] - # Update user admin state - query_user.admin = data['admin'] + query_user = get_user(email) + + query_user.admin = admin db.session.commit() return make_response({}, 200, "Successfully updated users admin rights") @@ -170,11 +163,9 @@ def set_admin(data): def set_cron(data): email = get_email_or_abort_401() - # Check if required data is available if not check_if_cron_data_exists(data): abort(400, "Cron data missing") - # Update user cron get_user(email).cron = data['cron'] db.session.commit() @@ -187,22 +178,18 @@ def set_cron(data): @users_blueprint.auth_required(auth) @users_blueprint.doc(summary="Delete user", description="Deletes user by username") def delete_user(data): - # Check if required data is available if not check_if_email_data_exists(data): abort(400, "Email missing") - # Check if email to delete is current user - # -> if, delete user - # -> if not, check if user is admin - # -> if, delete user - # -> else, abort - if data['email'] == get_email_or_abort_401(): # Username is same as current user - db.session.query(User).filter_by(email=data['email']).delete() + email = data['email'] + + if email == get_email_or_abort_401(): # Username is same as current user + db.session.query(User).filter_by(email=email).delete() db.session.commit() - else: + else: # Delete different user than my user -> only admin users abort_if_no_admin() - db.session.query(User).filter_by(email=data['email']).delete() + db.session.query(User).filter_by(email=email).delete() db.session.commit() return make_response({}, 200, "Successfully removed user") diff --git a/api/app/helper_functions.py b/api/app/helper_functions.py index 560f114..d3edea3 100644 --- a/api/app/helper_functions.py +++ b/api/app/helper_functions.py @@ -14,48 +14,28 @@ from flask import request, jsonify def hash_password(password): - """ - Hash plain password to save it in the database - """ return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()) def check_password(hashed_password, user_password): - """ - Check if the password is correct using the bcrypt checkpw function - """ return bcrypt.checkpw(user_password, hashed_password) def get_email_from_token_data(token): - """ - Extract email from token data - """ - - # If token is not provided-> return None if token is None or len(token) < 2: return None else: - # Token contains "Bearer " -> remove it token = token[1] - # Again: Check if token is not None - # Don't know why, but sometimes the token is None if token is not None: - - # We decided to append the user id to the bearer token using ":" as separator to select an specific user - # If the token contains ":" -> It may be a bot token - # If token valid -> return user email, not bot email - if ':' in token: + if ':' in token: # Maybe bot token, check if token valid and return username after ":" then telegram_user_id = token.split(":")[1] token = token.split(":")[0] try: - # Only allow selecting users with telegram_user_id if current user is the bot user if jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=["HS256"])['email'] == current_app.config['BOT_EMAIL']: res = db.session.query(User).filter_by(telegram_user_id=telegram_user_id).first() - # Check if user id exists if res is not None: return res.as_dict()['email'] else: @@ -67,18 +47,12 @@ def get_email_from_token_data(token): else: # "Normal" token, extract username from token try: - # Return email from token if token is valid return jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=["HS256"])['email'] except jwt.PyJWTError: return None def get_token(): - """ - Extract token from Authorization header - """ - - # Check if Authorization header is provided if 'Authorization' in request.headers: return request.headers['Authorization'].split(" ") else: @@ -86,10 +60,7 @@ def get_token(): def get_email_or_abort_401(): - """ - Try to receive email from token data - If email is not provided -> abort 401 - """ + # get username from jwt token email = get_email_from_token_data(get_token()) if email is None: # If token not provided or invalid -> return 401 code @@ -99,38 +70,24 @@ def get_email_or_abort_401(): def abort_if_no_admin(): - """ - Check if user is admin - If not -> abort 401 - """ if not is_user_admin(): abort(401, message="Only admin users can access this") def is_user_admin(): - """ - Return users admin status - """ email = get_email_or_abort_401() return db.session.query(User).filter_by(email=email).first().admin def make_response(data, status=200, text=""): - """ - Generate response object - """ return jsonify({"status": status, "text": text, "data": data}) def get_user(email): - """ - Get user from database - """ query_user = db.session.query(User).filter_by(email=email).first() - # Check if user exists - if query_user is None: + if query_user is None: # Username doesn't exist abort(500, message="Can't find user") return query_user diff --git a/api/app/models.py b/api/app/models.py index 8846184..864ce32 100644 --- a/api/app/models.py +++ b/api/app/models.py @@ -2,7 +2,7 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.1" +__version__ = "1.0.0" from app.db import database as db @@ -30,8 +30,7 @@ class Transaction(db.Model): __tablename__ = 'transactions' t_id = db.Column('t_id', db.Integer(), nullable=False, unique=True, primary_key=True) email = db.Column('email', db.String(255), db.ForeignKey('users.email', ondelete='CASCADE')) - isin = db.Column('isin', db.String(255)) - comment = db.Column('comment', db.String(255)) + symbol = db.Column('symbol', db.String(255)) time = db.Column('time', db.DateTime()) count = db.Column('count', db.Integer()) price = db.Column('price', db.Float()) @@ -54,8 +53,7 @@ class Share(db.Model): __tablename__ = 'shares' a_id = db.Column('a_id', db.Integer(), nullable=False, unique=True, primary_key=True) email = db.Column('email', db.String(255), db.ForeignKey('users.email', ondelete='CASCADE')) - isin = db.Column('isin', db.String(255)) - comment = db.Column('comment', db.String(255)) + symbol = db.Column('symbol', db.String(255)) def as_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} @@ -64,7 +62,7 @@ class Share(db.Model): class SharePrice(db.Model): __tablename__ = 'share_price' id = db.Column('id', db.Integer(), nullable=False, unique=True, primary_key=True) - isin = db.Column('isin', db.String(255)) + symbol = db.Column('symbol', db.String(255)) price = db.Column('price', db.Float()) date = db.Column('date', db.DateTime()) diff --git a/api/app/schema.py b/api/app/schema.py index 11be0e2..f48f232 100644 --- a/api/app/schema.py +++ b/api/app/schema.py @@ -2,7 +2,7 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.1" +__version__ = "1.0.0" from apiflask import Schema from apiflask.fields import Integer, String, Boolean, Field, Float @@ -22,7 +22,6 @@ class UsersSchema(Schema): username = String() telegram_user_id = String() email = Email() - cron = String() class AdminDataSchema(Schema): @@ -72,24 +71,18 @@ class KeywordSchema(Schema): class SymbolSchema(Schema): - isin = String() - comment = String() - - -class SymbolRemoveSchema(Schema): - isin = String() + symbol = String() class TransactionSchema(Schema): - isin = String() - comment = String() + symbol = String() time = String(validate=validate.Regexp(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z")) count = Integer() price = Float() class SymbolPriceSchema(Schema): - isin = String() + symbol = String() time = String(validate=validate.Regexp(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z")) price = Float() @@ -109,8 +102,7 @@ class KeywordResponseSchema(Schema): class SymbolResponseSchema(Schema): - isin = String() - comment = String() + symbol = String() s_id = Integer() email = Email() @@ -122,16 +114,14 @@ class PortfolioShareResponseSchema(Schema): class TransactionResponseSchema(Schema): email = Email() - isin = String() - comment = String() + symbol = String() time = String() count = Integer() price = Float() class PortfolioResponseSchema(Schema): - isin = String() - comment = String() + symbol = String() last_transaction = String() count = Integer() # price = Float() diff --git a/api/generate_sample_transactions.py b/api/generate_sample_transactions.py index 2c38856..3c28db4 100644 --- a/api/generate_sample_transactions.py +++ b/api/generate_sample_transactions.py @@ -20,7 +20,7 @@ fake = faker.Faker() token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": username, "password": password}).json()['data']['token'] -for i in range(1, 10): +for i in range(1, 1000): payload = { "count": random.randint(1, 100), "price": random.random() * 100, diff --git a/deploy/base/.env b/deploy/base/.env deleted file mode 100644 index 932c2e2..0000000 --- a/deploy/base/.env +++ /dev/null @@ -1,3 +0,0 @@ -WATCHTOWER_SCHEDULE=0 5 3 * * * -WATCHTOWER_ROLLING_RESTART=true -WATCHTOWER_CLEANUP=true \ No newline at end of file diff --git a/deploy/base/docker-compose.yml b/deploy/base/docker-compose.yml index 0191ffa..0782888 100644 --- a/deploy/base/docker-compose.yml +++ b/deploy/base/docker-compose.yml @@ -64,14 +64,6 @@ services: - portainer_data:/data - /var/run/docker.sock:/var/run/docker.sock - watchtower: - image: containrrr/watchtower - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - /etc/localtime:/etc/localtime:ro - env_file: - - ${PWD}/.env - networks: default: external: diff --git a/documentation/README.md b/documentation/README.md index 3bdec2f..80c8665 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -1,7 +1,7 @@ # Dokumentation ## Swagger Documentation -Visit https://aktienbot.flokaiser.com/api/docs +Visit https://gruppe1.testsites.info/api/docs ## API - `api/openapi.json` diff --git a/frontend/package-lock.json b/frontend/package-lock.json index aa448e2..2cc45ca 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -14,7 +14,7 @@ "@angular/compiler": "~13.2.0", "@angular/core": "~13.2.0", "@angular/forms": "~13.2.0", - "@angular/material": "^13.3.3", + "@angular/material": "^13.3.2", "@angular/platform-browser": "~13.2.0", "@angular/platform-browser-dynamic": "~13.2.0", "@angular/router": "~13.2.0", @@ -24,16 +24,16 @@ "zone.js": "~0.11.4" }, "devDependencies": { - "@angular-devkit/build-angular": "~13.3.3", - "@angular/cli": "~13.3.3", + "@angular-devkit/build-angular": "~13.3.1", + "@angular/cli": "~13.3.1", "@angular/compiler-cli": "~13.2.0", - "@types/jasmine": "~4.0.3", - "@types/node": "^17.0.25", - "jasmine-core": "~4.1.0", - "karma": "~6.3.18", + "@types/jasmine": "~4.0.2", + "@types/node": "^17.0.23", + "jasmine-core": "~4.0.0", + "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", - "karma-jasmine": "~5.0.0", + "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "~1.7.0", "typescript": "~4.5.2" } @@ -51,49 +51,16 @@ "node": ">=6.0.0" } }, - "node_modules/@angular-devkit/architect": { - "version": "0.1303.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.3.tgz", - "integrity": "sha512-WRVVBCzLlMqRZVhZXGASHzNJK/OCAvl/DTGhlLuJDIjF7lVGnXHjtwNM8ilYZq949OnC3fly5Z61TfhbN/OHCg==", - "dev": true, - "dependencies": { - "@angular-devkit/core": "13.3.3", - "rxjs": "6.6.7" - }, - "engines": { - "node": "^12.20.0 || ^14.15.0 || >=16.10.0", - "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", - "yarn": ">= 1.13.0" - } - }, - "node_modules/@angular-devkit/architect/node_modules/rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", - "dev": true, - "dependencies": { - "tslib": "^1.9.0" - }, - "engines": { - "npm": ">=2.0.0" - } - }, - "node_modules/@angular-devkit/architect/node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - }, "node_modules/@angular-devkit/build-angular": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/build-angular/-/build-angular-13.3.3.tgz", - "integrity": "sha512-iEpNF3tF+9Gw+qQKL63fPFHIvWokJdrgVU4GzENQ5QeL8zk8iYTEbH3jWogq5tWy5+VmNP/mKkasq9i78lRiYw==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/build-angular/-/build-angular-13.3.1.tgz", + "integrity": "sha512-xxBW4zZZM+lewW0nEpk9SXw6BMYhxe8WI/FjyEroOV8G2IuOrjZ4112QOpk6jCgmPHSOEldbltEdwoVLAnu09Q==", "dev": true, "dependencies": { "@ampproject/remapping": "1.1.1", - "@angular-devkit/architect": "0.1303.3", - "@angular-devkit/build-webpack": "0.1303.3", - "@angular-devkit/core": "13.3.3", + "@angular-devkit/architect": "0.1303.1", + "@angular-devkit/build-webpack": "0.1303.1", + "@angular-devkit/core": "13.3.1", "@babel/core": "7.16.12", "@babel/generator": "7.16.8", "@babel/helper-annotate-as-pure": "7.16.7", @@ -104,7 +71,7 @@ "@babel/runtime": "7.16.7", "@babel/template": "7.16.7", "@discoveryjs/json-ext": "0.5.6", - "@ngtools/webpack": "13.3.3", + "@ngtools/webpack": "13.3.1", "ansi-colors": "4.1.1", "babel-loader": "8.2.3", "babel-plugin-istanbul": "6.1.1", @@ -126,7 +93,7 @@ "license-webpack-plugin": "4.0.2", "loader-utils": "3.2.0", "mini-css-extract-plugin": "2.5.3", - "minimatch": "3.0.5", + "minimatch": "3.0.4", "open": "8.4.0", "ora": "5.4.1", "parse5-html-rewriting-stream": "6.0.1", @@ -194,6 +161,48 @@ } } }, + "node_modules/@angular-devkit/build-angular/node_modules/@angular-devkit/architect": { + "version": "0.1303.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.1.tgz", + "integrity": "sha512-ppaLzNZPrqrI96ddgm1RuEALVpWZsmHbIPLDd0GBwhF6aOkwF0LpZHd5XyS4ktGFZPReiFIjWSVtqV5vaBdRsw==", + "dev": true, + "dependencies": { + "@angular-devkit/core": "13.3.1", + "rxjs": "6.6.7" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + } + }, + "node_modules/@angular-devkit/build-angular/node_modules/@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "dependencies": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + }, + "peerDependencies": { + "chokidar": "^3.5.2" + }, + "peerDependenciesMeta": { + "chokidar": { + "optional": true + } + } + }, "node_modules/@angular-devkit/build-angular/node_modules/rxjs": { "version": "6.6.7", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", @@ -213,12 +222,12 @@ "dev": true }, "node_modules/@angular-devkit/build-webpack": { - "version": "0.1303.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/build-webpack/-/build-webpack-0.1303.3.tgz", - "integrity": "sha512-v/z/YgwrAzYn1LfN9OHNxqcThyyg4LLx28hmHzDs5gyDShAK189y34EoT9uQ+lCyQrPVhP7UKACCxCdSwOEJiA==", + "version": "0.1303.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/build-webpack/-/build-webpack-0.1303.1.tgz", + "integrity": "sha512-KSnR3y2q5hxh7t7ZSi0Emv/Kh9+D105JaEeyEqjqRjLdZSd2m6eAxbSUMNOAsbqnJTMCfzU5AG7jhbujuge0dQ==", "dev": true, "dependencies": { - "@angular-devkit/architect": "0.1303.3", + "@angular-devkit/architect": "0.1303.1", "rxjs": "6.6.7" }, "engines": { @@ -231,6 +240,48 @@ "webpack-dev-server": "^4.0.0" } }, + "node_modules/@angular-devkit/build-webpack/node_modules/@angular-devkit/architect": { + "version": "0.1303.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.1.tgz", + "integrity": "sha512-ppaLzNZPrqrI96ddgm1RuEALVpWZsmHbIPLDd0GBwhF6aOkwF0LpZHd5XyS4ktGFZPReiFIjWSVtqV5vaBdRsw==", + "dev": true, + "dependencies": { + "@angular-devkit/core": "13.3.1", + "rxjs": "6.6.7" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + } + }, + "node_modules/@angular-devkit/build-webpack/node_modules/@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "dependencies": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + }, + "peerDependencies": { + "chokidar": "^3.5.2" + }, + "peerDependenciesMeta": { + "chokidar": { + "optional": true + } + } + }, "node_modules/@angular-devkit/build-webpack/node_modules/rxjs": { "version": "6.6.7", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", @@ -249,103 +300,13 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, - "node_modules/@angular-devkit/core": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.3.tgz", - "integrity": "sha512-lfQwY9LuVRwcNVzGmyPcwOpb3CAobP4T+c3joR1LLIPS5lzcM0oeCE2bon9N52Ktn4Q/pH98dVtjWL+jSrUADw==", - "dev": true, - "dependencies": { - "ajv": "8.9.0", - "ajv-formats": "2.1.1", - "fast-json-stable-stringify": "2.1.0", - "magic-string": "0.25.7", - "rxjs": "6.6.7", - "source-map": "0.7.3" - }, - "engines": { - "node": "^12.20.0 || ^14.15.0 || >=16.10.0", - "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", - "yarn": ">= 1.13.0" - }, - "peerDependencies": { - "chokidar": "^3.5.2" - }, - "peerDependenciesMeta": { - "chokidar": { - "optional": true - } - } - }, - "node_modules/@angular-devkit/core/node_modules/rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", - "dev": true, - "dependencies": { - "tslib": "^1.9.0" - }, - "engines": { - "npm": ">=2.0.0" - } - }, - "node_modules/@angular-devkit/core/node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - }, - "node_modules/@angular-devkit/core": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.3.tgz", - "integrity": "sha512-lfQwY9LuVRwcNVzGmyPcwOpb3CAobP4T+c3joR1LLIPS5lzcM0oeCE2bon9N52Ktn4Q/pH98dVtjWL+jSrUADw==", - "dev": true, - "dependencies": { - "ajv": "8.9.0", - "ajv-formats": "2.1.1", - "fast-json-stable-stringify": "2.1.0", - "magic-string": "0.25.7", - "rxjs": "6.6.7", - "source-map": "0.7.3" - }, - "engines": { - "node": "^12.20.0 || ^14.15.0 || >=16.10.0", - "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", - "yarn": ">= 1.13.0" - }, - "peerDependencies": { - "chokidar": "^3.5.2" - }, - "peerDependenciesMeta": { - "chokidar": { - "optional": true - } - } - }, - "node_modules/@angular-devkit/core/node_modules/rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", - "dev": true, - "dependencies": { - "tslib": "^1.9.0" - }, - "engines": { - "npm": ">=2.0.0" - } - }, - "node_modules/@angular-devkit/core/node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - }, "node_modules/@angular-devkit/schematics": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-13.3.3.tgz", - "integrity": "sha512-S8UNlw6IoR/kxBYbiwesuA7oJGSnFkD6bJwVLhpHdT6Sqrz2/IrjHcNgTJRAvhsOKIbfDtMtXRzl/PUdWEfgyw==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-13.3.1.tgz", + "integrity": "sha512-DxXMjlq/sALcHuONZRMTBX5k30XPfN4b6Ue4k7Xl8JKZqyHhEzfXaZzgD9u2cwb7wybKEeF/BZ5eJd8JG525og==", "dev": true, "dependencies": { - "@angular-devkit/core": "13.3.3", + "@angular-devkit/core": "13.3.1", "jsonc-parser": "3.0.0", "magic-string": "0.25.7", "ora": "5.4.1", @@ -357,6 +318,33 @@ "yarn": ">= 1.13.0" } }, + "node_modules/@angular-devkit/schematics/node_modules/@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "dependencies": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + }, + "peerDependencies": { + "chokidar": "^3.5.2" + }, + "peerDependenciesMeta": { + "chokidar": { + "optional": true + } + } + }, "node_modules/@angular-devkit/schematics/node_modules/rxjs": { "version": "6.6.7", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", @@ -390,9 +378,9 @@ } }, "node_modules/@angular/cdk": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.3.tgz", - "integrity": "sha512-dzd31mta2VwffxbeO4CelMqb7WswLnkC/r2QZXySnc0CTmj44HqXkqdZuEvVgxaKRVpxsYeuBuhhhy8U00YMOw==", + "version": "13.3.2", + "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.2.tgz", + "integrity": "sha512-Rb+SvQpjXqa0kedk/6nG57f8dC4uG1q35SR6mt6jCz84ikyS2zhikVbzaxLdG15uDvq1+N5Vx3NTSgH19XUSug==", "dependencies": { "tslib": "^2.3.0" }, @@ -412,16 +400,16 @@ "optional": true }, "node_modules/@angular/cli": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.3.tgz", - "integrity": "sha512-a+nnzFP1FfnypXpAhrHbIBaJcxzegWLZUvVzJQwt6P2z60IoHdvTVmyNbY89qI0LE1SrAokEUO1zW3Yjmu7fUw==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.1.tgz", + "integrity": "sha512-0uwU8v3V/2s95X4cZT582J6upReT/ZNw/VAf4p4q51JN+BBvdCEb251xTF+TcOojyToFyJYvg8T28XSrsNsmTQ==", "dev": true, "hasInstallScript": true, "dependencies": { - "@angular-devkit/architect": "0.1303.3", - "@angular-devkit/core": "13.3.3", - "@angular-devkit/schematics": "13.3.3", - "@schematics/angular": "13.3.3", + "@angular-devkit/architect": "0.1303.1", + "@angular-devkit/core": "13.3.1", + "@angular-devkit/schematics": "13.3.1", + "@schematics/angular": "13.3.1", "@yarnpkg/lockfile": "1.1.0", "ansi-colors": "4.1.1", "debug": "4.3.3", @@ -447,6 +435,66 @@ "yarn": ">= 1.13.0" } }, + "node_modules/@angular/cli/node_modules/@angular-devkit/architect": { + "version": "0.1303.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.1.tgz", + "integrity": "sha512-ppaLzNZPrqrI96ddgm1RuEALVpWZsmHbIPLDd0GBwhF6aOkwF0LpZHd5XyS4ktGFZPReiFIjWSVtqV5vaBdRsw==", + "dev": true, + "dependencies": { + "@angular-devkit/core": "13.3.1", + "rxjs": "6.6.7" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + } + }, + "node_modules/@angular/cli/node_modules/@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "dependencies": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + }, + "peerDependencies": { + "chokidar": "^3.5.2" + }, + "peerDependenciesMeta": { + "chokidar": { + "optional": true + } + } + }, + "node_modules/@angular/cli/node_modules/rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "dev": true, + "dependencies": { + "tslib": "^1.9.0" + }, + "engines": { + "npm": ">=2.0.0" + } + }, + "node_modules/@angular/cli/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, "node_modules/@angular/common": { "version": "13.2.6", "resolved": "https://registry.npmjs.org/@angular/common/-/common-13.2.6.tgz", @@ -622,15 +670,15 @@ } }, "node_modules/@angular/material": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.3.tgz", - "integrity": "sha512-PkZ7VW3/7tqdBHSOOmq7com7Ir147OEe1+kfgF/G3y8WUutI9jY2cHKARXGWB+5WgcqKr7ol43u239UGkPfFHg==", + "version": "13.3.2", + "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.2.tgz", + "integrity": "sha512-agIuNcN1wO05ODEXc0wwrMK2ydnhPGO8tcBBCJXrDgiA/ktwm+WtfOsiZwPoev7aJ8pactVhxT5R0bJ6vW2SmA==", "dependencies": { "tslib": "^2.3.0" }, "peerDependencies": { "@angular/animations": "^13.0.0 || ^14.0.0-0", - "@angular/cdk": "13.3.3", + "@angular/cdk": "13.3.2", "@angular/common": "^13.0.0 || ^14.0.0-0", "@angular/core": "^13.0.0 || ^14.0.0-0", "@angular/forms": "^13.0.0 || ^14.0.0-0", @@ -2451,9 +2499,9 @@ } }, "node_modules/@ngtools/webpack": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-13.3.3.tgz", - "integrity": "sha512-O6EzafKfFuvI3Ju941u7ANs0mT7YDdChbVRhVECCPWOTm3Klr73js3bnCDzaJlxZNjzlG/KeUu5ghrhbMrHjSw==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-13.3.1.tgz", + "integrity": "sha512-40iEqAA/l882MPbGuG5EYxzsPWJ37fT4fF22SkPLX2eBgNhJ4K8XMt0gqcFhkHUsSe63frg1qjQ1Pd31msu0bQ==", "dev": true, "engines": { "node": "^12.20.0 || ^14.15.0 || >=16.10.0", @@ -2609,13 +2657,13 @@ } }, "node_modules/@schematics/angular": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.3.3.tgz", - "integrity": "sha512-kX5ghVCmWHcMN+g0pUaFuIJzwrXsVnK4bfid8DckU4EEtfFSv3UA5I1QNJRgpCPxTPhNEAk+3ePN8nzDSjdU+w==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.3.1.tgz", + "integrity": "sha512-+lrK/d1eJsAK6d6E9TDeg3Vc71bDy1KsE8M+lEINdX9Wax22mAz4pw20X9RSCw5RHgn+XcNUuMsgRJAwVhDNpg==", "dev": true, "dependencies": { - "@angular-devkit/core": "13.3.3", - "@angular-devkit/schematics": "13.3.3", + "@angular-devkit/core": "13.3.1", + "@angular-devkit/schematics": "13.3.1", "jsonc-parser": "3.0.0" }, "engines": { @@ -2624,6 +2672,51 @@ "yarn": ">= 1.13.0" } }, + "node_modules/@schematics/angular/node_modules/@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "dependencies": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + }, + "engines": { + "node": "^12.20.0 || ^14.15.0 || >=16.10.0", + "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", + "yarn": ">= 1.13.0" + }, + "peerDependencies": { + "chokidar": "^3.5.2" + }, + "peerDependenciesMeta": { + "chokidar": { + "optional": true + } + } + }, + "node_modules/@schematics/angular/node_modules/rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "dev": true, + "dependencies": { + "tslib": "^1.9.0" + }, + "engines": { + "npm": ">=2.0.0" + } + }, + "node_modules/@schematics/angular/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, "node_modules/@socket.io/base64-arraybuffer": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@socket.io/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz", @@ -2757,9 +2850,9 @@ } }, "node_modules/@types/jasmine": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.0.3.tgz", - "integrity": "sha512-Opp1LvvEuZdk8fSSvchK2mZwhVrsNT0JgJE9Di6MjnaIpmEXM8TLCPPrVtNTYh8+5MPdY8j9bAHMu2SSfwpZJg==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.0.2.tgz", + "integrity": "sha512-mSPIWhDyQ4nzYdR6Ixy15VhVKMVw93mSUlQxxpVb4S9Hj90lBvg+7kkBw23uYcv8CESPPXit+u3cARYcPeC8Jg==", "dev": true }, "node_modules/@types/json-schema": { @@ -2775,9 +2868,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "17.0.25", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.25.tgz", - "integrity": "sha512-wANk6fBrUwdpY4isjWrKTufkrXdu1D2YHCot2fD/DfWxF5sMrVSA+KN7ydckvaTCh0HiqX9IVl0L5/ZoXg5M7w==", + "version": "17.0.23", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.23.tgz", + "integrity": "sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw==", "dev": true }, "node_modules/@types/parse-json": { @@ -3279,9 +3372,9 @@ } }, "node_modules/async": { - "version": "2.6.4", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", - "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", + "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", "dev": true, "dependencies": { "lodash": "^4.17.14" @@ -6865,9 +6958,9 @@ } }, "node_modules/jasmine-core": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.1.0.tgz", - "integrity": "sha512-8E8BiffCL8sBwK1zU9cbavLe8xpJAgOduSJ6N8PJVv8VosQ/nxVTuXj2kUeHxTlZBVvh24G19ga7xdiaxlceKg==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.1.tgz", + "integrity": "sha512-w+JDABxQCkxbGGxg+a2hUVZyqUS2JKngvIyLGu/xiw2ZwgsoSB0iiecLQsQORSeaKQ6iGrCyWG86RfNDuoA7Lg==", "dev": true }, "node_modules/jest-worker": { @@ -7000,9 +7093,9 @@ ] }, "node_modules/karma": { - "version": "6.3.18", - "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.18.tgz", - "integrity": "sha512-YEwXVHRILKWKN7uEW9IkgTPjnYGb3YA3MDvlp04xpSRAyrNPoRmsBayLDgHykKAwBm6/mAOckj4xi/1JdQfhzQ==", + "version": "6.3.17", + "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.17.tgz", + "integrity": "sha512-2TfjHwrRExC8yHoWlPBULyaLwAFmXmxQrcuFImt/JsAsSZu1uOWTZ1ZsWjqQtWpHLiatJOHL5jFjXSJIgCd01g==", "dev": true, "dependencies": { "@colors/colors": "1.5.0", @@ -7024,7 +7117,7 @@ "qjobs": "^1.2.0", "range-parser": "^1.2.1", "rimraf": "^3.0.2", - "socket.io": "^4.4.1", + "socket.io": "^4.2.0", "source-map": "^0.6.1", "tmp": "^0.2.1", "ua-parser-js": "^0.7.30", @@ -7064,18 +7157,18 @@ } }, "node_modules/karma-jasmine": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-5.0.0.tgz", - "integrity": "sha512-dsFkCoTwyoNyQnMgegS72wIA/2xPDJG5yzTry0448U6lAY7P60Wgg4UuLlbdLv8YHbimgNpDXjjmfPdc99EDWQ==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-4.0.1.tgz", + "integrity": "sha512-h8XDAhTiZjJKzfkoO1laMH+zfNlra+dEQHUAjpn5JV1zCPtOIVWGQjLBrqhnzQa/hrU2XrZwSyBa6XjEBzfXzw==", "dev": true, "dependencies": { - "jasmine-core": "^4.1.0" + "jasmine-core": "^3.6.0" }, "engines": { - "node": ">=12" + "node": ">= 10" }, "peerDependencies": { - "karma": "^6.0.0" + "karma": "*" } }, "node_modules/karma-jasmine-html-reporter": { @@ -7090,9 +7183,9 @@ } }, "node_modules/karma-jasmine/node_modules/jasmine-core": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.1.0.tgz", - "integrity": "sha512-8E8BiffCL8sBwK1zU9cbavLe8xpJAgOduSJ6N8PJVv8VosQ/nxVTuXj2kUeHxTlZBVvh24G19ga7xdiaxlceKg==", + "version": "3.99.1", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.1.tgz", + "integrity": "sha512-Hu1dmuoGcZ7AfyynN3LsfruwMbxMALMka+YtZeGoLuDEySVmVAPaonkNoBRIw/ectu8b9tVQCJNgp4a4knp+tg==", "dev": true }, "node_modules/karma-source-map-support": { @@ -7675,9 +7768,9 @@ "dev": true }, "node_modules/minimatch": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.5.tgz", - "integrity": "sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "dependencies": { "brace-expansion": "^1.1.7" @@ -9567,9 +9660,9 @@ "dev": true }, "node_modules/regexp.prototype.flags": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.2.tgz", - "integrity": "sha512-Ynz8fTQW5/1elh+jWU2EDDzeoNbD0OQ0R+D1VJU5ATOkUaro4A9YEkdN2ODQl/8UQFPPpZNw91fOcLFamM7Pww==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.1.tgz", + "integrity": "sha512-pMR7hBVUUGI7PMA37m2ofIdQCsomVnas+Jn5UPGAHQ+/LlwKm/aTLJHdasmHRzlfeZwHiAOaRSo2rbBDm3nNUQ==", "dev": true, "dependencies": { "call-bind": "^1.0.2", @@ -11476,43 +11569,16 @@ "sourcemap-codec": "1.4.8" } }, - "@angular-devkit/architect": { - "version": "0.1303.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.3.tgz", - "integrity": "sha512-WRVVBCzLlMqRZVhZXGASHzNJK/OCAvl/DTGhlLuJDIjF7lVGnXHjtwNM8ilYZq949OnC3fly5Z61TfhbN/OHCg==", - "dev": true, - "requires": { - "@angular-devkit/core": "13.3.3", - "rxjs": "6.6.7" - }, - "dependencies": { - "rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", - "dev": true, - "requires": { - "tslib": "^1.9.0" - } - }, - "tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - } - } - }, "@angular-devkit/build-angular": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/build-angular/-/build-angular-13.3.3.tgz", - "integrity": "sha512-iEpNF3tF+9Gw+qQKL63fPFHIvWokJdrgVU4GzENQ5QeL8zk8iYTEbH3jWogq5tWy5+VmNP/mKkasq9i78lRiYw==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/build-angular/-/build-angular-13.3.1.tgz", + "integrity": "sha512-xxBW4zZZM+lewW0nEpk9SXw6BMYhxe8WI/FjyEroOV8G2IuOrjZ4112QOpk6jCgmPHSOEldbltEdwoVLAnu09Q==", "dev": true, "requires": { "@ampproject/remapping": "1.1.1", - "@angular-devkit/architect": "0.1303.3", - "@angular-devkit/build-webpack": "0.1303.3", - "@angular-devkit/core": "13.3.3", + "@angular-devkit/architect": "0.1303.1", + "@angular-devkit/build-webpack": "0.1303.1", + "@angular-devkit/core": "13.3.1", "@babel/core": "7.16.12", "@babel/generator": "7.16.8", "@babel/helper-annotate-as-pure": "7.16.7", @@ -11523,7 +11589,7 @@ "@babel/runtime": "7.16.7", "@babel/template": "7.16.7", "@discoveryjs/json-ext": "0.5.6", - "@ngtools/webpack": "13.3.3", + "@ngtools/webpack": "13.3.1", "ansi-colors": "4.1.1", "babel-loader": "8.2.3", "babel-plugin-istanbul": "6.1.1", @@ -11546,7 +11612,7 @@ "license-webpack-plugin": "4.0.2", "loader-utils": "3.2.0", "mini-css-extract-plugin": "2.5.3", - "minimatch": "3.0.5", + "minimatch": "3.0.4", "open": "8.4.0", "ora": "5.4.1", "parse5-html-rewriting-stream": "6.0.1", @@ -11576,6 +11642,30 @@ "webpack-subresource-integrity": "5.1.0" }, "dependencies": { + "@angular-devkit/architect": { + "version": "0.1303.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.1.tgz", + "integrity": "sha512-ppaLzNZPrqrI96ddgm1RuEALVpWZsmHbIPLDd0GBwhF6aOkwF0LpZHd5XyS4ktGFZPReiFIjWSVtqV5vaBdRsw==", + "dev": true, + "requires": { + "@angular-devkit/core": "13.3.1", + "rxjs": "6.6.7" + } + }, + "@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "requires": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + } + }, "rxjs": { "version": "6.6.7", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", @@ -11596,77 +11686,39 @@ } }, "@angular-devkit/build-webpack": { - "version": "0.1303.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/build-webpack/-/build-webpack-0.1303.3.tgz", - "integrity": "sha512-v/z/YgwrAzYn1LfN9OHNxqcThyyg4LLx28hmHzDs5gyDShAK189y34EoT9uQ+lCyQrPVhP7UKACCxCdSwOEJiA==", + "version": "0.1303.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/build-webpack/-/build-webpack-0.1303.1.tgz", + "integrity": "sha512-KSnR3y2q5hxh7t7ZSi0Emv/Kh9+D105JaEeyEqjqRjLdZSd2m6eAxbSUMNOAsbqnJTMCfzU5AG7jhbujuge0dQ==", "dev": true, "requires": { - "@angular-devkit/architect": "0.1303.3", + "@angular-devkit/architect": "0.1303.1", "rxjs": "6.6.7" }, "dependencies": { - "rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "@angular-devkit/architect": { + "version": "0.1303.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.1.tgz", + "integrity": "sha512-ppaLzNZPrqrI96ddgm1RuEALVpWZsmHbIPLDd0GBwhF6aOkwF0LpZHd5XyS4ktGFZPReiFIjWSVtqV5vaBdRsw==", "dev": true, "requires": { - "tslib": "^1.9.0" + "@angular-devkit/core": "13.3.1", + "rxjs": "6.6.7" } }, - "tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - } - } - }, - "@angular-devkit/core": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.3.tgz", - "integrity": "sha512-lfQwY9LuVRwcNVzGmyPcwOpb3CAobP4T+c3joR1LLIPS5lzcM0oeCE2bon9N52Ktn4Q/pH98dVtjWL+jSrUADw==", - "dev": true, - "requires": { - "ajv": "8.9.0", - "ajv-formats": "2.1.1", - "fast-json-stable-stringify": "2.1.0", - "magic-string": "0.25.7", - "rxjs": "6.6.7", - "source-map": "0.7.3" - }, - "dependencies": { - "rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", "dev": true, "requires": { - "tslib": "^1.9.0" + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" } }, - "tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - } - } - }, - "@angular-devkit/core": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.3.tgz", - "integrity": "sha512-lfQwY9LuVRwcNVzGmyPcwOpb3CAobP4T+c3joR1LLIPS5lzcM0oeCE2bon9N52Ktn4Q/pH98dVtjWL+jSrUADw==", - "dev": true, - "requires": { - "ajv": "8.9.0", - "ajv-formats": "2.1.1", - "fast-json-stable-stringify": "2.1.0", - "magic-string": "0.25.7", - "rxjs": "6.6.7", - "source-map": "0.7.3" - }, - "dependencies": { "rxjs": { "version": "6.6.7", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", @@ -11685,18 +11737,32 @@ } }, "@angular-devkit/schematics": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-13.3.3.tgz", - "integrity": "sha512-S8UNlw6IoR/kxBYbiwesuA7oJGSnFkD6bJwVLhpHdT6Sqrz2/IrjHcNgTJRAvhsOKIbfDtMtXRzl/PUdWEfgyw==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-13.3.1.tgz", + "integrity": "sha512-DxXMjlq/sALcHuONZRMTBX5k30XPfN4b6Ue4k7Xl8JKZqyHhEzfXaZzgD9u2cwb7wybKEeF/BZ5eJd8JG525og==", "dev": true, "requires": { - "@angular-devkit/core": "13.3.3", + "@angular-devkit/core": "13.3.1", "jsonc-parser": "3.0.0", "magic-string": "0.25.7", "ora": "5.4.1", "rxjs": "6.6.7" }, "dependencies": { + "@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "requires": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + } + }, "rxjs": { "version": "6.6.7", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", @@ -11723,9 +11789,9 @@ } }, "@angular/cdk": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.3.tgz", - "integrity": "sha512-dzd31mta2VwffxbeO4CelMqb7WswLnkC/r2QZXySnc0CTmj44HqXkqdZuEvVgxaKRVpxsYeuBuhhhy8U00YMOw==", + "version": "13.3.2", + "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.2.tgz", + "integrity": "sha512-Rb+SvQpjXqa0kedk/6nG57f8dC4uG1q35SR6mt6jCz84ikyS2zhikVbzaxLdG15uDvq1+N5Vx3NTSgH19XUSug==", "requires": { "parse5": "^5.0.0", "tslib": "^2.3.0" @@ -11740,15 +11806,15 @@ } }, "@angular/cli": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.3.tgz", - "integrity": "sha512-a+nnzFP1FfnypXpAhrHbIBaJcxzegWLZUvVzJQwt6P2z60IoHdvTVmyNbY89qI0LE1SrAokEUO1zW3Yjmu7fUw==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.1.tgz", + "integrity": "sha512-0uwU8v3V/2s95X4cZT582J6upReT/ZNw/VAf4p4q51JN+BBvdCEb251xTF+TcOojyToFyJYvg8T28XSrsNsmTQ==", "dev": true, "requires": { - "@angular-devkit/architect": "0.1303.3", - "@angular-devkit/core": "13.3.3", - "@angular-devkit/schematics": "13.3.3", - "@schematics/angular": "13.3.3", + "@angular-devkit/architect": "0.1303.1", + "@angular-devkit/core": "13.3.1", + "@angular-devkit/schematics": "13.3.1", + "@schematics/angular": "13.3.1", "@yarnpkg/lockfile": "1.1.0", "ansi-colors": "4.1.1", "debug": "4.3.3", @@ -11764,6 +11830,47 @@ "semver": "7.3.5", "symbol-observable": "4.0.0", "uuid": "8.3.2" + }, + "dependencies": { + "@angular-devkit/architect": { + "version": "0.1303.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.1.tgz", + "integrity": "sha512-ppaLzNZPrqrI96ddgm1RuEALVpWZsmHbIPLDd0GBwhF6aOkwF0LpZHd5XyS4ktGFZPReiFIjWSVtqV5vaBdRsw==", + "dev": true, + "requires": { + "@angular-devkit/core": "13.3.1", + "rxjs": "6.6.7" + } + }, + "@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "requires": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + } + }, + "rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "dev": true, + "requires": { + "tslib": "^1.9.0" + } + }, + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + } } }, "@angular/common": { @@ -11885,9 +11992,9 @@ } }, "@angular/material": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.3.tgz", - "integrity": "sha512-PkZ7VW3/7tqdBHSOOmq7com7Ir147OEe1+kfgF/G3y8WUutI9jY2cHKARXGWB+5WgcqKr7ol43u239UGkPfFHg==", + "version": "13.3.2", + "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.2.tgz", + "integrity": "sha512-agIuNcN1wO05ODEXc0wwrMK2ydnhPGO8tcBBCJXrDgiA/ktwm+WtfOsiZwPoev7aJ8pactVhxT5R0bJ6vW2SmA==", "requires": { "tslib": "^2.3.0" } @@ -13159,9 +13266,9 @@ } }, "@ngtools/webpack": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-13.3.3.tgz", - "integrity": "sha512-O6EzafKfFuvI3Ju941u7ANs0mT7YDdChbVRhVECCPWOTm3Klr73js3bnCDzaJlxZNjzlG/KeUu5ghrhbMrHjSw==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-13.3.1.tgz", + "integrity": "sha512-40iEqAA/l882MPbGuG5EYxzsPWJ37fT4fF22SkPLX2eBgNhJ4K8XMt0gqcFhkHUsSe63frg1qjQ1Pd31msu0bQ==", "dev": true, "requires": {} }, @@ -13282,14 +13389,45 @@ "peer": true }, "@schematics/angular": { - "version": "13.3.3", - "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.3.3.tgz", - "integrity": "sha512-kX5ghVCmWHcMN+g0pUaFuIJzwrXsVnK4bfid8DckU4EEtfFSv3UA5I1QNJRgpCPxTPhNEAk+3ePN8nzDSjdU+w==", + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.3.1.tgz", + "integrity": "sha512-+lrK/d1eJsAK6d6E9TDeg3Vc71bDy1KsE8M+lEINdX9Wax22mAz4pw20X9RSCw5RHgn+XcNUuMsgRJAwVhDNpg==", "dev": true, "requires": { - "@angular-devkit/core": "13.3.3", - "@angular-devkit/schematics": "13.3.3", + "@angular-devkit/core": "13.3.1", + "@angular-devkit/schematics": "13.3.1", "jsonc-parser": "3.0.0" + }, + "dependencies": { + "@angular-devkit/core": { + "version": "13.3.1", + "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-13.3.1.tgz", + "integrity": "sha512-eXAcQaP1mn6rnQb+5bv5NsamY6b34UYM7G+S154Hnma6CTTSGBtcmoNAJs8cekuFqWlw7YgpB/e15jR5OLPkDA==", + "dev": true, + "requires": { + "ajv": "8.9.0", + "ajv-formats": "2.1.1", + "fast-json-stable-stringify": "2.1.0", + "magic-string": "0.25.7", + "rxjs": "6.6.7", + "source-map": "0.7.3" + } + }, + "rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "dev": true, + "requires": { + "tslib": "^1.9.0" + } + }, + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + } } }, "@socket.io/base64-arraybuffer": { @@ -13419,9 +13557,9 @@ } }, "@types/jasmine": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.0.3.tgz", - "integrity": "sha512-Opp1LvvEuZdk8fSSvchK2mZwhVrsNT0JgJE9Di6MjnaIpmEXM8TLCPPrVtNTYh8+5MPdY8j9bAHMu2SSfwpZJg==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.0.2.tgz", + "integrity": "sha512-mSPIWhDyQ4nzYdR6Ixy15VhVKMVw93mSUlQxxpVb4S9Hj90lBvg+7kkBw23uYcv8CESPPXit+u3cARYcPeC8Jg==", "dev": true }, "@types/json-schema": { @@ -13437,9 +13575,9 @@ "dev": true }, "@types/node": { - "version": "17.0.25", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.25.tgz", - "integrity": "sha512-wANk6fBrUwdpY4isjWrKTufkrXdu1D2YHCot2fD/DfWxF5sMrVSA+KN7ydckvaTCh0HiqX9IVl0L5/ZoXg5M7w==", + "version": "17.0.23", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.23.tgz", + "integrity": "sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw==", "dev": true }, "@types/parse-json": { @@ -13869,9 +14007,9 @@ "dev": true }, "async": { - "version": "2.6.4", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", - "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", + "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", "dev": true, "requires": { "lodash": "^4.17.14" @@ -16474,9 +16612,9 @@ } }, "jasmine-core": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.1.0.tgz", - "integrity": "sha512-8E8BiffCL8sBwK1zU9cbavLe8xpJAgOduSJ6N8PJVv8VosQ/nxVTuXj2kUeHxTlZBVvh24G19ga7xdiaxlceKg==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.1.tgz", + "integrity": "sha512-w+JDABxQCkxbGGxg+a2hUVZyqUS2JKngvIyLGu/xiw2ZwgsoSB0iiecLQsQORSeaKQ6iGrCyWG86RfNDuoA7Lg==", "dev": true }, "jest-worker": { @@ -16579,9 +16717,9 @@ "dev": true }, "karma": { - "version": "6.3.18", - "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.18.tgz", - "integrity": "sha512-YEwXVHRILKWKN7uEW9IkgTPjnYGb3YA3MDvlp04xpSRAyrNPoRmsBayLDgHykKAwBm6/mAOckj4xi/1JdQfhzQ==", + "version": "6.3.17", + "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.17.tgz", + "integrity": "sha512-2TfjHwrRExC8yHoWlPBULyaLwAFmXmxQrcuFImt/JsAsSZu1uOWTZ1ZsWjqQtWpHLiatJOHL5jFjXSJIgCd01g==", "dev": true, "requires": { "@colors/colors": "1.5.0", @@ -16603,7 +16741,7 @@ "qjobs": "^1.2.0", "range-parser": "^1.2.1", "rimraf": "^3.0.2", - "socket.io": "^4.4.1", + "socket.io": "^4.2.0", "source-map": "^0.6.1", "tmp": "^0.2.1", "ua-parser-js": "^0.7.30", @@ -16681,18 +16819,18 @@ } }, "karma-jasmine": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-5.0.0.tgz", - "integrity": "sha512-dsFkCoTwyoNyQnMgegS72wIA/2xPDJG5yzTry0448U6lAY7P60Wgg4UuLlbdLv8YHbimgNpDXjjmfPdc99EDWQ==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-4.0.1.tgz", + "integrity": "sha512-h8XDAhTiZjJKzfkoO1laMH+zfNlra+dEQHUAjpn5JV1zCPtOIVWGQjLBrqhnzQa/hrU2XrZwSyBa6XjEBzfXzw==", "dev": true, "requires": { - "jasmine-core": "^4.1.0" + "jasmine-core": "^3.6.0" }, "dependencies": { "jasmine-core": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.1.0.tgz", - "integrity": "sha512-8E8BiffCL8sBwK1zU9cbavLe8xpJAgOduSJ6N8PJVv8VosQ/nxVTuXj2kUeHxTlZBVvh24G19ga7xdiaxlceKg==", + "version": "3.99.1", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.1.tgz", + "integrity": "sha512-Hu1dmuoGcZ7AfyynN3LsfruwMbxMALMka+YtZeGoLuDEySVmVAPaonkNoBRIw/ectu8b9tVQCJNgp4a4knp+tg==", "dev": true } } @@ -17080,9 +17218,9 @@ "dev": true }, "minimatch": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.5.tgz", - "integrity": "sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { "brace-expansion": "^1.1.7" @@ -18471,9 +18609,9 @@ "dev": true }, "regexp.prototype.flags": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.2.tgz", - "integrity": "sha512-Ynz8fTQW5/1elh+jWU2EDDzeoNbD0OQ0R+D1VJU5ATOkUaro4A9YEkdN2ODQl/8UQFPPpZNw91fOcLFamM7Pww==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.1.tgz", + "integrity": "sha512-pMR7hBVUUGI7PMA37m2ofIdQCsomVnas+Jn5UPGAHQ+/LlwKm/aTLJHdasmHRzlfeZwHiAOaRSo2rbBDm3nNUQ==", "dev": true, "requires": { "call-bind": "^1.0.2", diff --git a/frontend/package.json b/frontend/package.json index fba736a..d31fa67 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,7 +16,7 @@ "@angular/compiler": "~13.2.0", "@angular/core": "~13.2.0", "@angular/forms": "~13.2.0", - "@angular/material": "^13.3.3", + "@angular/material": "^13.3.2", "@angular/platform-browser": "~13.2.0", "@angular/platform-browser-dynamic": "~13.2.0", "@angular/router": "~13.2.0", @@ -26,16 +26,16 @@ "zone.js": "~0.11.4" }, "devDependencies": { - "@angular-devkit/build-angular": "~13.3.3", - "@angular/cli": "~13.3.3", + "@angular-devkit/build-angular": "~13.3.1", + "@angular/cli": "~13.3.1", "@angular/compiler-cli": "~13.2.0", - "@types/jasmine": "~4.0.3", - "@types/node": "^17.0.25", - "karma": "~6.3.18", - "jasmine-core": "~4.1.0", + "@types/jasmine": "~4.0.2", + "@types/node": "^17.0.23", + "jasmine-core": "~4.0.0", + "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", - "karma-jasmine": "~5.0.0", + "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "~1.7.0", "typescript": "~4.5.2" } diff --git a/frontend/src/app/Services/bot.service.ts b/frontend/src/app/Services/bot.service.ts index 7e8334a..0e764cd 100644 --- a/frontend/src/app/Services/bot.service.ts +++ b/frontend/src/app/Services/bot.service.ts @@ -95,17 +95,17 @@ export class BotService { } /** - * @param {string} symbol + * @param {string} share * @returns Observable */ - public deleteShare(symbol: string): Observable { + public deleteShare(share: string): Observable { return this.http.delete(API_URL + 'share', { headers: new HttpHeaders({ 'Content-Type': 'application/json', Authorization: 'Bearer ' + this.tokenStorage.getToken(), }), body: { - symbol, + share, }, }); } diff --git a/telegram_bot/.env.example b/telegram_bot/.env.example index bcd6a02..a36e6ec 100644 --- a/telegram_bot/.env.example +++ b/telegram_bot/.env.example @@ -6,3 +6,7 @@ NEWS_API_KEY= # Flask secret key SECRET_KEY= + +# bot credentials +BOT_EMAIL= +BOT_PASSWORD= \ No newline at end of file diff --git a/telegram_bot/api_handler.py b/telegram_bot/api_handler.py deleted file mode 100644 index 69c4974..0000000 --- a/telegram_bot/api_handler.py +++ /dev/null @@ -1,7 +0,0 @@ -""" -script for communicating with webservice to get data from database -""" -__author__ = "Florian Kellermann, Linus Eickhoff" -__date__ = "16.03.2022" -__version__ = "0.0.1" -__license__ = "None" \ No newline at end of file diff --git a/telegram_bot/api_handling/__init__.py b/telegram_bot/api_handling/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py new file mode 100644 index 0000000..49751f0 --- /dev/null +++ b/telegram_bot/api_handling/api_handler.py @@ -0,0 +1,350 @@ +""" +script for communicating with webservice to get data from database +""" +__author__ = "Florian Kellermann, Linus Eickhoff" +__date__ = "16.03.2022" +__version__ = "0.0.1" +__license__ = "None" + +#side-dependencies: none +#Work in Progress + +import sys +import os +import requests as r +from croniter import croniter + + + +class API_Handler: + """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 + get_user_portfolio(user_id): gets the portfolio of the user + set_portfolio(user_id, portfolio): sets the portfolio of the user + delete_portfolio(user_id, portfolio): deletes the portfolio of the user + set_cron_interval(user_id, interval): sets the cron interval of the user + """ + + + def __init__(self, db_adress, email, password): + """initializes the API_Handler class + + Args: + db_adress (string): adress of the database + email (string): email of the user + password (string): password of the user + """ + self.db_adress = db_adress + + payload = {'email': email, 'password': password} + with r.Session() as s: + p = s.post(self.db_adress + "/user/login", json=payload) + if p.status_code == 200: + self.token = p.json()["data"]['token'] + else: + print("Error: " + str(p.status_code) + " invalid credentials") + self.token = None + + + def reauthorize(self, email, password): + """set new credentials + + Args: + email (string): email of the user + password (string): password of the user + """ + payload = {'email': email, 'password': password} + with r.Session() as s: + p = s.post(self.db_adress + "/user/login", json=payload) + if p.status_code == 200: + self.token = p.json()["data"]['token'] + return p.json()["data"]['token'] + else: + self.token = None + 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 + + Args: + user_id (int): id of the user + max_retries (int): max retries for the request + + Returns: + list: list of keywords + """ + if max_retries <= 0: + return None + + keywords = [] + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/keywords", headers=headers) + 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, max_retries-1) + + + + def set_keyword(self, user_id, keyword): + """sets the keyword of the user + + Args: + user_id (int): id of the user + keyword (int): keyword of the user + + Returns: + int: status code + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.post(self.db_adress + "/keyword", json={"keyword": keyword}, headers=headers) + + return req.status_code + + + def delete_keyword(self, user_id, keyword): + """deletes the keyword of the user + + Args: + user_id (int): id of the user + keyword (string): keyword of the user + + Returns: + int: status code + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.delete(self.db_adress + "/keyword", json={"keyword": keyword}, headers=headers) + + return req.status_code + + + def get_user_shares(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: + list: list of shares + """ + 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 + "/shares", headers=headers) + if(req.status_code == 200): + shares_json = req.json()["data"] + shares = [] + for share in shares_json: + shares.append(share["symbol"]) + + return shares + + else: + return self.get_user_shares(user_id, max_retries-1) + + + def set_share(self, user_id, symbol): + """sets the share of the user + + Args: + user_id (int): id of the user + symbol (string): symbol of the share + + Returns: + int: status code + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + 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 + + Args: + user_id (int): id of the user + symbol (string): symbol of the share + + Returns: + int: status code + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.delete(self.db_adress + "/share", json={"symbol": symbol}, headers=headers) + return req.status_code + + + def get_user_transactions(self, user_id, max_retries=10): + """gets the transactions of the user + + Args: + user_id (int): id of the user + max_retries (int): max retries for the request + + Returns: + dict: dictionary of transactions + """ + 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 + "/transactions", headers=headers) + + if req.status_code == 200: + transactions_dict = req.json()["data"] + return transactions_dict + else: + return self.get_user_transactions(user_id, max_retries-1) + + + def set_transaction(self, user_id, comment, isin, count, price, time): + """sets the transaction of the user + + Args: + user_id (int): id of the user + comment (string): comment of the transaction + isin (string): isin of the transaction + count (int): count of the transaction + price (float): price of the transaction + time (string): time of the transaction + + Returns: + int: status code + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + transaction = {"comment": comment, "count": count, "isin": isin, "price": price, "time": time} + req = s.post(self.db_adress + "/transaction", json=transaction, headers=headers) + return req.status_code + + + def get_user_portfolio(self, user_id, max_retries=10): + """gets the portfolio of the user + + Args: + user_id (int): id of the user + max_retries (int): max retries for the request + + Returns: + dict: dictionary of portfolio + """ + 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 + "/portfolio", headers=headers) + if req.status_code == 200: + portfolio_dict = req.json()["data"] + return portfolio_dict + else: + return self.get_user_portfolio(user_id, max_retries-1) + + def set_cron_interval(self, user_id, cron_interval): + """sets the cron interval of the user + + Args: + user_id (int): id of the user + cron_interval (String): Update interval in cron format => see https://crontab.guru/ for formatting + + Returns: + int: status code + """ + if not croniter.is_valid(cron_interval): + print("Error: Invalid cron format") + return -1 + + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.put(self.db_adress + "/user/setCron", json={"cron": cron_interval}, headers=headers) + return req.status_code + + +if __name__ == "__main__": + + print("This is a module for the telegram bot. It is not intended to be run directly.") + 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("set cron with status: "+ str(handler.set_cron_interval(user_id = 1709356058, cron_interval = "0 0 * * *"))) + user = handler.get_user(user_id = 1709356058) + print(user) + all_users = handler.get_all_users() + print(all_users) + print(shares) + sys.exit(1) \ No newline at end of file diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index e3e4f28..6655ad5 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -17,29 +17,36 @@ __license__ = "None" import os import telebot -import time import sys import logging import json +import re import news.news_fetcher as news import shares.share_fetcher as share_fetcher +import datetime as dt from telebot import types from dotenv import load_dotenv +from api_handling.api_handler import API_Handler -load_dotenv() -bot_version = "0.2.1" +load_dotenv(dotenv_path='.env') + +bot_version = "1.0.1" user_list = [] +#create api handler +api_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) +print("Webserver Token: " + str(api_handler.token)) + class User: # Currently saving users in this class to test functionality -> later database def __init__(self, p_user_id, p_user_name, p_chat_id): """ Initialize a new user - :type self: - :param self: for class + :type self: User + :param self: object of the class :type p_user_id: int :param p_user_id: telegram user id @@ -61,7 +68,7 @@ class User: # Currently saving users in this class to test functionality -> late bot = telebot.TeleBot(os.getenv('BOT_API_KEY')) -@bot.message_handler(commands=['start']) # /start -> saving as new user and sending welcome +@bot.message_handler(commands=['start', 'Start']) # /start -> saving as new user and sending welcome def send_start(message): """ Description @@ -83,7 +90,7 @@ def send_start(message): bot.reply_to(message, "Welcome to this share bot project. Type /help to get information on what this bot can do") -@bot.message_handler(commands=['version']) +@bot.message_handler(commands=['version', 'Version']) def send_version(message): """ Sending programm version @@ -97,7 +104,7 @@ def send_version(message): bot.reply_to(message, bot_version) -@bot.message_handler(commands=['help']) # /help -> sending all functions +@bot.message_handler(commands=['help', 'Help']) # /help -> sending all functions def send_welcome(message): """ Send all functions @@ -108,10 +115,10 @@ def send_welcome(message): :rtype: none """ - bot.reply_to(message, "/id or /auth for authentication. /update to get updates on your shares. /users to see all users. /news to get current use for your keywords. /share to get price of specific share. For further details see aktienbot.flokaiser.com") + bot.reply_to(message, "/id or /auth get your user id\n/update get updates on your shares.\n/users see all users.\n/me get my user info\n/news get top article for each keyword.\n/allnews get all news (last 7 days)\n/keywords get all your keywords\n/addkeyword add a keyword\n/removekeyword remove a keyword\n/share get price of specific share\n/portfolio see own portfolio\n/newtransaction add new transaction\n/interval get update interval\n/setinterval set update interval\n_For further details see https://gruppe1.testsites.info _", parse_mode='MARKDOWN') -@bot.message_handler(commands=['users']) +@bot.message_handler(commands=['users', 'Users']) # /users -> sending all users def send_all_users(message): """ Send all users, only possible for admins @@ -133,8 +140,27 @@ def send_all_users(message): answer = str(known_user.user_id) + ' : ' + known_user.user_name bot.send_message(chat_id=user_id, text=answer) + +@bot.message_handler(commands=['me', 'Me']) # /me -> sending user info +def send_user(message): + """ Send user data + :type message: message object bot + :param message: message that was reacted to, in this case always containing '/me' -@bot.message_handler(commands=['id', 'auth']) # /auth or /id -> Authentication with user_id over web tool + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + user_data = api_handler.get_user(user_id) # tbd: formatting + if not user_data or user_data == None: + bot.reply_to(message, "This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info") + return + + bot.reply_to(message, 'Your user data:\n' + str(user_data)) + + +@bot.message_handler(commands=['id', 'auth', 'Id', 'Auth']) # /auth or /id -> Authentication with user_id over web tool def send_id(message): """ Send user id for authentication with browser @@ -145,49 +171,72 @@ def send_id(message): :rtype: none """ - answer = 'Your ID/Authentication Code is: [' + str(message.from_user.id) + ']. Enter this code in the settings on aktienbot.flokaiser.com to get updates on your shares.' + answer = 'Your ID/Authentication Code is: [' + str(message.from_user.id) + ']. Enter this code in the settings on https://gruppe1.testsites.info to get updates on your shares.' bot.reply_to(message, answer) -@bot.message_handler(commands=['update']) -def send_update(message): - - """ Send update on shares +#function that sends telegram status(running or offline) as message from telegram bot to user +@bot.message_handler(commands=['status', 'Status']) +def send_status(message): + + """ Sends status to user :type message: message object bot - :param message: message that was reacted to, in this case always containing '/help' + :param message: message that was reacted to, if no other command handler gets called :raises: none :rtype: none """ - user_id = int(message.from_user.id) + bot.reply_to(message, "bot is running") + + +@bot.message_handler(commands=['update', 'Update']) # /update -> update shares +def update_for_user(message): - #Can be deleted when getting from database - dirname = os.path.dirname(__file__) - json_path = os.path.join(dirname, 'shares/shares_example.json') + p_user_id = int(message.from_user.id) + p_my_handler = api_handler - with open(json_path) as json_file: - json_share_data = json.load(json_file) - int_share_count = int(json_share_data['share_count']) - str_username = str(json_share_data['user']) - bot.send_message(chat_id=user_id, text=f'Hello {str_username}. Here is the update on your currently owned shares:') - - - for i in range(int_share_count): - - my_share = json_share_data['shares'][i] - my_share_symbol = str(my_share['symbol']) - my_share_amount = float(my_share['amount_bought']) - my_share_buy_price = float(my_share['price_bought']) - my_share_course = float(share_fetcher.get_share_price(my_share_symbol)) - - - my_update_message = f'Symbol: {my_share_symbol}\nPrice: {my_share_course}\nBought for: {my_share_buy_price}\n\ -Amount owned: {my_share_amount}\nWin/Lose: {(my_share_amount*my_share_course) - (my_share_amount*my_share_buy_price)}' - bot.send_message(chat_id=user_id, text=my_update_message) + share_symbols = [] + share_amounts = [] + share_courses = [] + + my_portfolio = p_my_handler.get_user_portfolio(p_user_id) + + for element in my_portfolio: + if element["count"] != '' and element["symbol"]!= '': + print(element["count"], element["symbol"]) + share_symbols.append(element["symbol"]) + share_amounts.append(element["count"]) + share_courses.append(element["current_price"]) + + my_user = p_my_handler.get_user(p_user_id) + send_to_user("Hello %s this is your share update:"%str(my_user["username"]), pUser_id=p_user_id) + + if len(share_symbols) != 0: + for i in range(len(share_symbols)): + my_update_message = f'Symbol: {share_symbols[i]}\nCurrent Price per Share: {share_courses[i]}\nAmount owned: {share_amounts[i]}\nTotal Investment: {float(share_courses[i]) * float(share_amounts[i])}' + send_to_user(my_update_message, pUser_id=p_user_id) + else: + send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id) + + +def send_to_user(pText, pUser_id = 1770205310): + + """ Send message to user + :type pText: string + :param pText: Text to send to user + + :type pUser_id: int + :param pUser_id: user to send to. per default me (Florian Kellermann) + + :raises: none + + :rtype: none + """ + bot.send_message(chat_id=pUser_id, text=pText) -@bot.message_handler(commands=['share']) +@bot.message_handler(commands=['share', 'Share']) # /share -> get share price def send_share_update(message): """ Send price of a specific share @@ -210,10 +259,49 @@ def send_share_price(message): bot.reply_to(message, str_share_price) -@bot.message_handler(commands=['news']) -def send_news(message): +@bot.message_handler(commands=['allnews', 'Allnews']) # /allnews -> get all news +def send_all_news(message): """ Get news for keywords of user + :type message: message object bot + :param message: message that was reacted to, in this case always containing '/allnews' + + :raises: none + + :rtype: none + """ + + user_id = int(message.from_user.id) + keywords = api_handler.get_user_keywords(user_id) + + if keywords == None: + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') + return + + if not keywords: + bot.send_message(chat_id=user_id, text='You have no keywords. Please add some keywords with /news') + return + + keywords_search = ' OR '.join(keywords) + print(keywords_search) + now = dt.datetime.now().date() + from_date = now - dt.timedelta(days=7) + from_date_formatted = dt.datetime.strftime(from_date, '%Y-%m-%d') + print(from_date_formatted) + news_list = news.get_all_news_by_keyword(keywords_search, from_date_formatted)["articles"] + + if news_list: + for article in news_list: + formatted_article = news.format_article(article) + bot.send_message(chat_id=user_id, text=formatted_article, parse_mode="MARKDOWN") + else: + bot.send_message(chat_id=user_id, text='No news found for your keywords.') + + +@bot.message_handler(commands=['news', 'News']) # /news -> get news for specific keyword +def send_news(message): + """ Get news for keywords of user + :type message: message object bot :param message: message that was reacted to, in this case always containing '/news' @@ -221,21 +309,223 @@ def send_news(message): :rtype: none """ - - keyword = "bitcoin" user_id = int(message.from_user.id) - #Get Information for user with this id + keywords = api_handler.get_user_keywords(user_id) - articles = news.get_top_news_by_keyword(keyword) #tbd: get keyword from db - try: - formatted_article = news.format_article(articles["articles"][0]) - except IndexError: - bot.send_message(chat_id=user_id, text=f"no news currently available for keyword: {keyword}") + if keywords == None: + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') return - bot.send_message(chat_id=user_id, text=f"_keyword: {keyword}_\n\n" + formatted_article, parse_mode="MARKDOWN") + + if not keywords: + bot.send_message(chat_id=user_id, text='You have no keywords. Please add some keywords with /addkeyword') + return + + if keywords: + for keyword in keywords: + top_news = news.get_top_news_by_keyword(keyword)["articles"] + if top_news == None: + bot.send_message(chat_id=user_id, text='News Server did not respond correctly. Try again later.') + return + if not top_news: + bot.send_message(chat_id=user_id, text=f'No news found for keyword: *{keyword}*', parse_mode="MARKDOWN") + return + + formatted_article = news.format_article(top_news[0]) + bot.send_message(chat_id=user_id, text=f"_keyword: {keyword}_\n\n" + formatted_article, parse_mode="MARKDOWN") -@bot.message_handler(func=lambda message: True) # Returning that command is unkown for any other statement +@bot.message_handler(commands=['addkeyword', 'Addkeyword']) # /addkeyword -> add keyword to user +def add_keyword(message): + """ Add keyword to user + :type message: message object bot + :param message: message that was reacted to, in this case always '/addkeyword' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + bot.send_message(chat_id=user_id, text='Type keyword to add:') + bot.register_next_step_handler(message, store_keyword) + +def store_keyword(message): + user_id = int(message.from_user.id) + print(str(user_id)) + keyword = str(message.text).lower() + status = api_handler.set_keyword(user_id, keyword) + if status == 200: + bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" added.') + else: + bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" could not be stored. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info (statuscode {status})') + + +@bot.message_handler(commands=['removekeyword', 'Removekeyword']) # /removekeyword -> remove keyword from user +def remove_keyword(message): + """ Remove keyword from user + :type message: message object bot + :param message: message that was reacted to, in this case always '/removekeyword' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + bot.send_message(chat_id=user_id, text='Type keyword to remove:') + bot.register_next_step_handler(message, remove_keyword_step) + +def remove_keyword_step(message): + user_id = int(message.from_user.id) + keyword = str(message.text).lower() + status = api_handler.delete_keyword(user_id, keyword) + if status == 200: + bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" removed.') + else: + bot.send_message(chat_id=user_id, text=f'Failed deleting keyword "{keyword}". (statuscode {status})') + + +@bot.message_handler(commands=['keywords', 'Keywords']) # /keywords -> get keywords of user +def send_keywords(message): + """ Send keywords of user + :type message: message object bot + :param message: message that was reacted to, in this case always '/keywords' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + keywords = api_handler.get_user_keywords(user_id) + if keywords == None: + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') + return + if not keywords: + bot.send_message(chat_id=user_id, text='No keywords set for this account. Add keywords by using /addkeyword') + return + else: + keywords_str = ', '.join(keywords) + bot.send_message(chat_id=user_id, text=f'Your keywords are: _{keywords_str}_', parse_mode="MARKDOWN") + + +@bot.message_handler(commands=['portfolio', 'Portfolio']) #tbd +def send_portfolio(message): + """ Send portfolio of user + :type message: message object bot + :param message: message that was reacted to, in this case always '/portfolio' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + portfolio = api_handler.get_user_portfolio(user_id) + if portfolio == None: + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info') + return + if not portfolio: + bot.send_message(chat_id=user_id, text='You do not have any stocks in your portfolio.') + return + else: + for stock in portfolio: + comment = str(stock["comment"]) + count = "{:.2f}".format(float(stock["count"])) + isin = str(stock["isin"]) + worth = "{:.2f}".format(float(stock["current_price"]) * float(stock["count"])) + bot.send_message(chat_id=user_id, text=f'*{comment}*\n_{isin}_\namount: {count}\nworth: ${worth}', parse_mode="MARKDOWN") + + +@bot.message_handler(commands=['newtransaction', 'Newtransaction']) #tbd not working rn +def set_new_transaction(message): + """ Set new transaction for user + :type message: message object bot + :param message: message that was reacted to, in this case always '/newtransaction' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + bot.send_message(chat_id=user_id, text='Type ",,," (time of transaction will be set to now):') + bot.register_next_step_handler(message, set_new_transaction_step) + +def set_new_transaction_step(message): + user_id = int(message.from_user.id) + + if not re.match(r"[A-Za-z0-9]+,[A-Za-z0-9]+,[0-9]+(.[0-9]+)?,[0-9]+(.[0-9]+)?", message.text): + bot.send_message(chat_id=user_id, text='Invalid format \n(e.g. Apple,US0378331005,53.2,120.4).\n Try again with /newtransaction.') + return + + transaction_data = str(message.text).split(',') + desc = str(transaction_data[0]) + isin = str(transaction_data[1]) + amount = float(transaction_data[2]) + price = float(transaction_data[3]) + time = dt.datetime.now().isoformat() + #print("\n\n\n\n\n") + #print(f"{symbol},{amount},{price},{time}") + status = api_handler.set_transaction(user_id, desc, isin, amount, price, time) + + if status == 200: + bot.send_message(chat_id=user_id, text='Transaction succesfully added.') + else: + bot.send_message(chat_id=user_id, text=f'Failed adding transaction. (statuscode {status})') + + +@bot.message_handler(commands=['interval', 'Interval']) #tbd +def send_interval(message): + """ send interval for user + :type message: message object bot + :param message: message that was reacted to, in this case always '/interval' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + user_data = api_handler.get_user(user_id) + if user_data == None: + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info and set an interval with /setinterval') + return + else: + interval = str(user_data['cron']) + if interval == 'None': + bot.send_message(chat_id=user_id, text='You do not have an interval set. Set one with /setinterval') + return + formatted_interval = str(interval).replace(' ', '_') + bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})') + + +@bot.message_handler(commands=['setinterval', 'Setinterval']) #tbd +def set_new_interval(message): + """ Set new interval for user + :type message: message object bot + :param message: message that was reacted to, in this case always '/setinterval' + + :raises: none + + :rtype: none + """ + user_id = int(message.from_user.id) + bot.send_message(chat_id=user_id, text='Type interval in cron format:\n(https://crontab.guru/)') + bot.register_next_step_handler(message, set_new_interval_step) + +def set_new_interval_step(message): + + user_id = int(message.from_user.id) + interval = str(message.text) + status = api_handler.set_cron_interval(user_id, interval) + + if status == 200: + bot.send_message(chat_id=user_id, text='Interval succesfully set.') + return + + if status == -1: # only -1 when interval is invalid + bot.send_message(chat_id=user_id, text='Invalid interval format. Try again with\n /setinterval.') + return + else: + bot.send_message(chat_id=user_id, text=f'Failed setting interval. (statuscode {status})') + + +@bot.message_handler(func=lambda message: True) # Returning that command is unknown for any other statement def echo_all(message): """ Tell that command is not known if it is no known command @@ -274,15 +564,12 @@ def query_text(inline_query): def main_loop(): - """ Get Information about bot status every 3 seconds + """ Start bot :raises: none :rtype: none """ bot.infinity_polling() - while 1: - time.sleep(3) - if __name__ == '__main__': try: diff --git a/telegram_bot/bot_scheduler.py b/telegram_bot/bot_scheduler.py new file mode 100644 index 0000000..8fcef6f --- /dev/null +++ b/telegram_bot/bot_scheduler.py @@ -0,0 +1,37 @@ +""" +script for regularly sending updates on shares and news based on user interval +""" +__author__ = "Florian Kellermann, Linus Eickhoff" +__date__ = "05.04.2022" +__version__ = "0.0.1" +__license__ = "None" + +import shares.share_fetcher as share_fetcher +import news.news_fetcher as news_fetcher + +import datetime +import sys +from apscheduler.schedulers.blocking import BlockingScheduler + +''' +* * * * * code +┬ ┬ ┬ ┬ ┬ +│ │ │ │ │ +│ │ │ │ └──── weekday (0->Monday, 7->Sunday) +│ │ │ └────── Month (1-12) +│ │ └──────── Day (1-31) +│ └────────── Hour (0-23) +└──────────── Minute (0-59) + +example 0 8 * * * -> daily update at 8am +''' + +def user_updates(): + """sends timed updates automatically to user + + Args: + + Returns: + + """ + return \ No newline at end of file diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py new file mode 100644 index 0000000..6269b5e --- /dev/null +++ b/telegram_bot/bot_updates.py @@ -0,0 +1,177 @@ +""" +script for regularly sending updates on shares and news based on user interval +""" +__author__ = "Florian Kellermann, Linus Eickhoff" +__date__ = "05.04.2022" +__version__ = "1.0.1" +__license__ = "None" + +from calendar import month +from symtable import Symbol +from shares.share_fetcher import get_share_price +import time +import datetime +from bot import bot +import sys +from multiprocessing import Process +from apscheduler.schedulers.background import BackgroundScheduler +from api_handling.api_handler import API_Handler + + +''' +* * * * * code +┬ ┬ ┬ ┬ ┬ +│ │ │ │ │ +│ │ │ │ └──── weekday (0->Monday, 7->Sunday) +│ │ │ └────── Month (1-12) +│ │ └──────── Day (1-31) +│ └────────── Hour (0-23) +└──────────── Minute (0-59) + +example 0 8 * * * -> daily update at 8am +''' +user_ids = [] +user_crontab = [] + +def main_loop(): + """ main loop for regularly sending updates + :raises: none + + :rtype: none + """ + + current_time_datetime = datetime.datetime.now() + my_handler = API_Handler("https://gruppe1.testsites.info/api", "bot@example.com", "bot") + + + # update_for_user(5270256395, my_handler) # Debug (running test update for kevins shares) + + + update_crontab(current_time_datetime, my_handler) + + +def update_crontab(pCurrent_Time, p_my_handler): + """ Updating crontab lists every hour + :type pCurrent_Time: time when starting crontab update + :param pCurrent_Time: datetime + + :raises: none + + :rtype: none + """ + + global user_crontab + global user_ids + + #p_my_handler.set_cron_interval(user_id = 1770205310, cron_interval = "23 08 * * *") + + all_users = p_my_handler.get_all_users() + + user_ids = [] + user_crontab = [] + + for element in all_users: + if element["cron"] != '' and element["telegram_user_id"] != '': + user_ids.append(int(element["telegram_user_id"])) + user_crontab.append(str(element["cron"])) + + print(user_ids) + + update_based_on_crontab(user_ids, user_crontab, p_my_handler) + + update_crontab(datetime.datetime.now(), p_my_handler) + + +def update_based_on_crontab(p_user_ids, p_user_crontab, p_my_handler): + + """ Check all the crontab codes and add jobs to start in time + :type p_user_ids: array + :param p_user_ids: user id array of all users + + :type p_user_crontab: array + :param p_user_crontab: crontabs for all users equivalent to the user array + + :type p_my_handler: Api_Handler + :param p_my_handler: get database stuff + + :raises: none + + :rtype: none + """ + + my_scheduler = BackgroundScheduler() + + print(len(user_ids)) #Debug + + for i in range(len(p_user_ids)): + cron_split = p_user_crontab[i].split(" ") + print(cron_split[4], cron_split[1], cron_split[0], cron_split[3], cron_split[2]) + my_scheduler.add_job(update_for_user, 'cron', day_of_week = cron_split[4] , hour= cron_split[1] , minute = cron_split[0], month= cron_split[3] , day=cron_split[2], args=(p_user_ids[i], p_my_handler )) + + my_scheduler.start() + + time.sleep( 600 ) + my_scheduler.shutdown() + +def update_for_user(p_user_id, p_my_handler): + + """ Pull shares and send updates for specific user id + :type p_user_id: integer + :param p_user_id: user id of user that shall receive update + + :type p_my_handler: Api_Handler + :param p_my_handler: handle the api and pull from database + + :raises: none + + :rtype: none + """ + share_symbols = [] + share_amounts = [] + share_courses = [] + + my_portfolio = p_my_handler.get_user_portfolio(p_user_id) + + for element in my_portfolio: + if element["count"] != '' and element["symbol"]!= '': + print(element["count"], element["symbol"]) + share_symbols.append(element["symbol"]) + share_amounts.append(element["count"]) + share_courses.append(element["current_price"]) + + my_user = p_my_handler.get_user(p_user_id) + send_to_user("Hello %s this is your share update:"%str(my_user["username"]), pUser_id=p_user_id) + + if len(share_symbols) != 0: + for i in range(len(share_symbols)): + my_update_message = f'Symbol: {share_symbols[i]}\nCurrent Price per Share: {share_courses[i]}\nAmount owned: {share_amounts[i]}\nTotal Investment: {float(share_courses[i]) * float(share_amounts[i])}' + send_to_user(my_update_message, pUser_id=p_user_id) + else: + send_to_user("No shares found for your account. Check https://gruppe1.testsites.info/api to change your settings and add shares.", pUser_id=p_user_id) + + +def send_to_user(pText, pUser_id = 1770205310): + + """ Send message to user + :type pText: string + :param pText: Text to send to user + + :type pUser_id: int + :param pUser_id: user to send to. per default me (Florian Kellermann) + + :raises: none + + :rtype: none + """ + bot.send_message(chat_id=pUser_id, text=pText) + + +if __name__ == "__main__": + + print('bot_updates.py starting.') + try: + main_loop() + sys.exit(-1) + except KeyboardInterrupt: + print("Ending") + sys.exit(-1) \ No newline at end of file diff --git a/telegram_bot/db_handler.py b/telegram_bot/db_handler.py deleted file mode 100644 index 816af71..0000000 --- a/telegram_bot/db_handler.py +++ /dev/null @@ -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 \ No newline at end of file diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index 69c0807..96f50ff 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -10,6 +10,7 @@ import sys import os import json import requests +import datetime as dt from newsapi import NewsApiClient from dotenv import load_dotenv @@ -19,11 +20,31 @@ load_dotenv() # Init api_key = os.getenv('NEWS_API_KEY') newsapi = NewsApiClient(api_key=api_key) -source_json = requests.get(f"https://newsapi.org/v2/top-headlines/sources?apiKey={api_key}&language=en").json() -sources = source_json["sources"] -str_sources = ",".join([source["id"] for source in sources]) +try: + source_json = requests.get(f"https://newsapi.org/v2/top-headlines/sources?apiKey={api_key}&language=en").json() + sources = source_json["sources"] + str_sources = ",".join([source["id"] for source in sources]) +except KeyError: + print("Error: Could not get sources") + sys.exit(1) +def get_all_news_by_keyword(keyword, from_date="2000-01-01"): + """get all news to keyword + Args: + keyword (String): keyword for search + from_date (String): min date for search + + Returns: + JSON/dict: dict containing articles + """ + top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en', from_param=from_date) + if(top_headlines["status"] == "ok"): + return top_headlines + else: + return None + + def get_top_news_by_keyword(keyword): """get top news to keyword Args: @@ -31,9 +52,13 @@ def get_top_news_by_keyword(keyword): Returns: JSON/dict: dict containing articles - """ + """ top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language='en') - return top_headlines + if(top_headlines["status"] == "ok"): + return top_headlines + else: + return None + def format_article(article): """format article for messaging (using markdown syntax) @@ -53,8 +78,10 @@ def format_article(article): if __name__ == '__main__': - print("fetching top news by keyword business...") + print("this is a module and should not be run directly") + print("fetching top news by keyword bitcoin...") - articles = get_top_news_by_keyword("bitcoin") + articles = get_all_news_by_keyword("bitcoin") formatted_article = format_article(articles["articles"][0]) - print(formatted_article) \ No newline at end of file + print(formatted_article) + sys.exit(1) \ No newline at end of file diff --git a/telegram_bot/requirements.txt b/telegram_bot/requirements.txt index 6b0de09..6620615 100644 --- a/telegram_bot/requirements.txt +++ b/telegram_bot/requirements.txt @@ -4,3 +4,6 @@ yfinance~=0.1.70 newsapi-python~=0.2.6 python-dotenv~=0.20.0 requests~=2.27.1 +APScheduler~=3.9.1 +croniter~=1.3.4 +tzlocal==2.1