From 8d5d777de60031efe5ed2cfd21074d5c9799ae0a Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Mon, 28 Mar 2022 18:07:39 +0200 Subject: [PATCH 01/66] implemented apihandler class and functions --- telegram_bot/api_handler.py | 49 ++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/telegram_bot/api_handler.py b/telegram_bot/api_handler.py index 69c4974..aa9b4da 100644 --- a/telegram_bot/api_handler.py +++ b/telegram_bot/api_handler.py @@ -4,4 +4,51 @@ 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 +__license__ = "None" + +#side-dependencies: none +#Work in Progress + +import sys +import os +import requests as r + +class API_Handler: + #class for communicating with webservice to get data from database + def __init__(self, db_adress): + self.db_adress = db_adress + return + + def get_auth_token(self, email, password): + 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: + #print server response + print(p.text) + return None + + def get_user_keywords(self, token, user_id): + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + token + ":" + user_id} + p = s.get(self.db_adress + "/api/keywords", headers=headers) + keywords_json = p.json()["data"] + keywords = [] + for keyword in keywords_json: + keywords.append(keyword["keyword"]) + return keywords + + +if __name__ == "__main__": + + print("This is a module for the telegram bot. It is not intended to be run directly.") + handler = API_Handler("https://aktienbot.flokaiser.com/api") + try: + handler.get_auth_token("bot@example.com", "bot") + except None: + print("Could not connect to server.") + + sys.exit(1) \ No newline at end of file -- 2.45.2 From 4b23261bd1f7fd2daa6fcb8cd1829aa625804243 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Mon, 28 Mar 2022 18:55:52 +0200 Subject: [PATCH 02/66] api_handler functions completed (tbd: testing) --- telegram_bot/api_handler.py | 189 +++++++++++++++++++++++++++++++++--- 1 file changed, 174 insertions(+), 15 deletions(-) diff --git a/telegram_bot/api_handler.py b/telegram_bot/api_handler.py index aa9b4da..45c5de4 100644 --- a/telegram_bot/api_handler.py +++ b/telegram_bot/api_handler.py @@ -15,11 +15,31 @@ import requests as r class API_Handler: #class for communicating with webservice to get data from database - def __init__(self, db_adress): - self.db_adress = db_adress - return + def __init__(self, db_adress, email, password): + """initializes the API_Handler class - def get_auth_token(self, email, password): + 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: + self.token = None + + def reauthorize(self, email, password): + """reauthorizes the user + + 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) @@ -27,28 +47,167 @@ class API_Handler: self.token = p.json()["data"]['token'] return p.json()["data"]['token'] else: - #print server response - print(p.text) + self.token = None return None - def get_user_keywords(self, token, user_id): + def get_user_keywords(self, user_id): + """gets the keywords of the user + + Args: + user_id (int): id of the user + + Returns: + list: list of keywords + """ with r.Session() as s: - headers = {'Authorization': 'Bearer ' + token + ":" + user_id} - p = s.get(self.db_adress + "/api/keywords", headers=headers) - keywords_json = p.json()["data"] + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/keywords", headers=headers) + print(req.status_code) + keywords_json = req.json()["data"] keywords = [] for keyword in keywords_json: keywords.append(keyword["keyword"]) + return keywords + 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): + """gets the shares of the user + + Args: + user_id (int): id of the user + + Returns: + list: list of shares + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/shares", headers=headers) + shares_json = req.json()["data"] + shares = [] + for share in shares_json: + shares.append(share["symbol"]) + + return shares + + 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): + """gets the transactions of the user + + Args: + user_id (int): id of the user + + Returns: + dict: dictionary of transactions + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/transactions", headers=headers) + transactions_dict = dict(req.json()["data"]) + return transactions_dict + + def set_transaction(self, user_id, count, price, symbol, timestamp): + """sets the transaction of the user + + Args: + user_id (int): id of the user + count (int): count of the transaction + price (float): price of the transaction + symbol (string): symbol of the transaction + timestamp (string): timestamp of the transaction + + Returns: + int: status code + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + transaction = {"count": count, "price": price, "symbol": symbol, "time": timestamp} + req = s.post(self.db_adress + "/transaction", json=transaction, headers=headers) + return req.status_code + + def get_user_portfolio(self, user_id): + """gets the portfolio of the user + + Args: + user_id (int): id of the user + + Returns: + dict: dictionary of portfolio + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/portfolio", headers=headers) + portfolio_dict = dict(req.json()["data"]) + return portfolio_dict + + + if __name__ == "__main__": print("This is a module for the telegram bot. It is not intended to be run directly.") - handler = API_Handler("https://aktienbot.flokaiser.com/api") - try: - handler.get_auth_token("bot@example.com", "bot") - except None: - print("Could not connect to server.") + handler = API_Handler("https://aktienbot.flokaiser.com/api", "bot@example.com", "bot") + keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is mine (Linus) + print(keywords) sys.exit(1) \ No newline at end of file -- 2.45.2 From c489e9ab46a3a6723669bd483ce59495b3dcc58b Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Mon, 28 Mar 2022 19:39:37 +0200 Subject: [PATCH 03/66] added keywords from db (not working currently) --- telegram_bot/api_handler.py | 6 +++--- telegram_bot/bot.py | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/telegram_bot/api_handler.py b/telegram_bot/api_handler.py index 45c5de4..93d5c2f 100644 --- a/telegram_bot/api_handler.py +++ b/telegram_bot/api_handler.py @@ -34,7 +34,7 @@ class API_Handler: self.token = None def reauthorize(self, email, password): - """reauthorizes the user + """set new credentials Args: email (string): email of the user @@ -207,7 +207,7 @@ if __name__ == "__main__": print("This is a module for the telegram bot. It is not intended to be run directly.") handler = API_Handler("https://aktienbot.flokaiser.com/api", "bot@example.com", "bot") - - keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is mine (Linus) + print(handler.token) + keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is currently mine (Linus) print(keywords) sys.exit(1) \ No newline at end of file diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index e3e4f28..c62083f 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -28,12 +28,17 @@ import shares.share_fetcher as share_fetcher from telebot import types from dotenv import load_dotenv +from api_handler import API_Handler + load_dotenv() bot_version = "0.2.1" user_list = [] +#create api handler +api_handler = API_Handler("https://aktienbot.flokaiser.com", os.getenv("BOT_EMAIL"), os.getenv("BOT_PASSWORD")) + 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): @@ -222,11 +227,11 @@ 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_keywords(user_id) + keyword = keywords[0] - articles = news.get_top_news_by_keyword(keyword) #tbd: get keyword from db + articles = news.get_top_news_by_keyword(keywords[0]) try: formatted_article = news.format_article(articles["articles"][0]) except IndexError: @@ -235,6 +240,27 @@ def send_news(message): bot.send_message(chat_id=user_id, text=f"_keyword: {keyword}_\n\n" + formatted_article, parse_mode="MARKDOWN") +@bot.message_handler(commands=['addkeyword']) +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) + keyword = str(message.text) + api_handler.add_keyword(user_id, keyword) + bot.send_message(chat_id=user_id, text=f'Keyword {keyword} added.') + + @bot.message_handler(func=lambda message: True) # Returning that command is unkown for any other statement def echo_all(message): -- 2.45.2 From 218f70f541ecf74e00ba09739ed73f674a9bca2b Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 08:31:58 +0200 Subject: [PATCH 04/66] added status function --- telegram_bot/bot.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index c62083f..5fc363f 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -154,6 +154,21 @@ def send_id(message): bot.reply_to(message, answer) +#function that sends telegram status(running or offline) as message from telegram bot to user +@bot.message_handler(commands=['status']) +def send_status(message): + + """ Sends status to user + :type message: message object bot + :param message: message that was reacted to, if no other command handler gets called + + :raises: none + + :rtype: none + """ + bot.reply_to(message, "bot is running") + + @bot.message_handler(commands=['update']) def send_update(message): @@ -306,9 +321,6 @@ def main_loop(): :rtype: none """ bot.infinity_polling() - while 1: - time.sleep(3) - if __name__ == '__main__': try: -- 2.45.2 From bf8fdbf848a0bf17b1ff40d199fde80aefe71e62 Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 08:41:09 +0200 Subject: [PATCH 05/66] formatting and docu additions --- telegram_bot/api_handler.py | 33 ++++++++++++++++++++++++++++++++- telegram_bot/db_handler.py | 15 --------------- 2 files changed, 32 insertions(+), 16 deletions(-) delete mode 100644 telegram_bot/db_handler.py diff --git a/telegram_bot/api_handler.py b/telegram_bot/api_handler.py index 93d5c2f..049ae93 100644 --- a/telegram_bot/api_handler.py +++ b/telegram_bot/api_handler.py @@ -13,8 +13,29 @@ import sys import os import requests as r + + class API_Handler: - #class for communicating with webservice to get data from database + """class for interacting with the api webservice + + Attributes: + db_adress (string): adress of the database + token (string): auth token for api + + Methods: + reauthorize(email, password): set new credentials + get_user_keywords(user_id): gets the keywords of the user + set_keyword(user_id, keyword): sets the keyword of the user + delete_keyword(user_id, keyword): deletes the keyword of the user + get_user_shares(user_id): gets the shares of the user + set_share(user_id, symbol): sets the share of the user + delete_share(user_id, symbol): deletes the share of the user + get_user_transactions(user_id): gets the transactions of the user + set_transaction(user_id, transaction): sets the transaction of the user + delete_transaction(user_id, transaction): deletes the transaction of the user + """ + + def __init__(self, db_adress, email, password): """initializes the API_Handler class @@ -33,6 +54,7 @@ class API_Handler: else: self.token = None + def reauthorize(self, email, password): """set new credentials @@ -50,6 +72,7 @@ class API_Handler: self.token = None return None + def get_user_keywords(self, user_id): """gets the keywords of the user @@ -70,6 +93,7 @@ class API_Handler: return keywords + def set_keyword(self, user_id, keyword): """sets the keyword of the user @@ -86,6 +110,7 @@ class API_Handler: return req.status_code + def delete_keyword(self, user_id, keyword): """deletes the keyword of the user @@ -102,6 +127,7 @@ class API_Handler: return req.status_code + def get_user_shares(self, user_id): """gets the shares of the user @@ -121,6 +147,7 @@ class API_Handler: return shares + def set_share(self, user_id, symbol): """sets the share of the user @@ -136,6 +163,7 @@ class API_Handler: req = s.post(self.db_adress + "/share", json={"symbol": symbol}, headers=headers) return req.status_code + def delete_share(self, user_id, symbol): """deletes the share of the user @@ -151,6 +179,7 @@ class API_Handler: req = s.delete(self.db_adress + "/share", json={"symbol": symbol}, headers=headers) return req.status_code + def get_user_transactions(self, user_id): """gets the transactions of the user @@ -166,6 +195,7 @@ class API_Handler: transactions_dict = dict(req.json()["data"]) return transactions_dict + def set_transaction(self, user_id, count, price, symbol, timestamp): """sets the transaction of the user @@ -185,6 +215,7 @@ class API_Handler: req = s.post(self.db_adress + "/transaction", json=transaction, headers=headers) return req.status_code + def get_user_portfolio(self, user_id): """gets the portfolio of the user 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 -- 2.45.2 From 456bba027b70427bac0b062fe066206eb3fa8026 Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 08:44:40 +0200 Subject: [PATCH 06/66] updated env example with bot creds --- telegram_bot/.env.example | 4 ++++ 1 file changed, 4 insertions(+) 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 -- 2.45.2 From 1ba19a219fe7dac9640cfdfb0490ef23bae5d8f0 Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 08:49:32 +0200 Subject: [PATCH 07/66] small change --- telegram_bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 5fc363f..617b23e 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -31,7 +31,7 @@ from dotenv import load_dotenv from api_handler import API_Handler -load_dotenv() +load_dotenv(dotenv_path='.env') bot_version = "0.2.1" user_list = [] -- 2.45.2 From 21d5d357b861f5cc2c3d4efb7ec97166d7683276 Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 09:26:50 +0200 Subject: [PATCH 08/66] moved api handler in subfolder --- telegram_bot/api_handling/__init__.py | 0 telegram_bot/api_handling/api_handler.py | 245 +++++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 telegram_bot/api_handling/__init__.py create mode 100644 telegram_bot/api_handling/api_handler.py 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..97eb937 --- /dev/null +++ b/telegram_bot/api_handling/api_handler.py @@ -0,0 +1,245 @@ +""" +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 + + + +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 + delete_transaction(user_id, transaction): deletes the transaction 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_keywords(self, user_id): + """gets the keywords of the user + + Args: + user_id (int): id of the user + + Returns: + list: list of keywords + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/keywords", headers=headers) + print(req.status_code) + keywords_json = req.json()["data"] + keywords = [] + for keyword in keywords_json: + keywords.append(keyword["keyword"]) + + return keywords + + + 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): + """gets the shares of the user + + Args: + user_id (int): id of the user + + Returns: + list: list of shares + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/shares", headers=headers) + shares_json = req.json()["data"] + shares = [] + for share in shares_json: + shares.append(share["symbol"]) + + return shares + + + 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): + """gets the transactions of the user + + Args: + user_id (int): id of the user + + Returns: + dict: dictionary of transactions + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/transactions", headers=headers) + transactions_dict = dict(req.json()["data"]) + return transactions_dict + + + def set_transaction(self, user_id, count, price, symbol, timestamp): + """sets the transaction of the user + + Args: + user_id (int): id of the user + count (int): count of the transaction + price (float): price of the transaction + symbol (string): symbol of the transaction + timestamp (string): timestamp of the transaction + + Returns: + int: status code + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + transaction = {"count": count, "price": price, "symbol": symbol, "time": timestamp} + req = s.post(self.db_adress + "/transaction", json=transaction, headers=headers) + return req.status_code + + + def get_user_portfolio(self, user_id): + """gets the portfolio of the user + + Args: + user_id (int): id of the user + + Returns: + dict: dictionary of portfolio + """ + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/portfolio", headers=headers) + portfolio_dict = dict(req.json()["data"]) + return portfolio_dict + + + + +if __name__ == "__main__": + + print("This is a module for the telegram bot. It is not intended to be run directly.") + handler = API_Handler("https://aktienbot.flokaiser.com/api", "bot@example.com", "bot") + print(handler.token) + keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is currently mine (Linus) + print(keywords) + sys.exit(1) \ No newline at end of file -- 2.45.2 From 4c517998ba0150bb0c877aa5400a7343e0cca8f0 Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 10:49:02 +0200 Subject: [PATCH 09/66] added funcs --- telegram_bot/api_handler.py | 244 ------------------------------------ telegram_bot/bot.py | 48 ++++--- 2 files changed, 34 insertions(+), 258 deletions(-) delete mode 100644 telegram_bot/api_handler.py diff --git a/telegram_bot/api_handler.py b/telegram_bot/api_handler.py deleted file mode 100644 index 049ae93..0000000 --- a/telegram_bot/api_handler.py +++ /dev/null @@ -1,244 +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" - -#side-dependencies: none -#Work in Progress - -import sys -import os -import requests as r - - - -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 - delete_transaction(user_id, transaction): deletes the transaction 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: - 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_keywords(self, user_id): - """gets the keywords of the user - - Args: - user_id (int): id of the user - - Returns: - list: list of keywords - """ - with r.Session() as s: - headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} - req = s.get(self.db_adress + "/keywords", headers=headers) - print(req.status_code) - keywords_json = req.json()["data"] - keywords = [] - for keyword in keywords_json: - keywords.append(keyword["keyword"]) - - return keywords - - - 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): - """gets the shares of the user - - Args: - user_id (int): id of the user - - Returns: - list: list of shares - """ - with r.Session() as s: - headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} - req = s.get(self.db_adress + "/shares", headers=headers) - shares_json = req.json()["data"] - shares = [] - for share in shares_json: - shares.append(share["symbol"]) - - return shares - - - 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): - """gets the transactions of the user - - Args: - user_id (int): id of the user - - Returns: - dict: dictionary of transactions - """ - with r.Session() as s: - headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} - req = s.get(self.db_adress + "/transactions", headers=headers) - transactions_dict = dict(req.json()["data"]) - return transactions_dict - - - def set_transaction(self, user_id, count, price, symbol, timestamp): - """sets the transaction of the user - - Args: - user_id (int): id of the user - count (int): count of the transaction - price (float): price of the transaction - symbol (string): symbol of the transaction - timestamp (string): timestamp of the transaction - - Returns: - int: status code - """ - with r.Session() as s: - headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} - transaction = {"count": count, "price": price, "symbol": symbol, "time": timestamp} - req = s.post(self.db_adress + "/transaction", json=transaction, headers=headers) - return req.status_code - - - def get_user_portfolio(self, user_id): - """gets the portfolio of the user - - Args: - user_id (int): id of the user - - Returns: - dict: dictionary of portfolio - """ - with r.Session() as s: - headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} - req = s.get(self.db_adress + "/portfolio", headers=headers) - portfolio_dict = dict(req.json()["data"]) - return portfolio_dict - - - - -if __name__ == "__main__": - - print("This is a module for the telegram bot. It is not intended to be run directly.") - handler = API_Handler("https://aktienbot.flokaiser.com/api", "bot@example.com", "bot") - print(handler.token) - keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is currently mine (Linus) - print(keywords) - sys.exit(1) \ No newline at end of file diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 617b23e..9f75ecf 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -28,7 +28,7 @@ import shares.share_fetcher as share_fetcher from telebot import types from dotenv import load_dotenv -from api_handler import API_Handler +from api_handling.api_handler import API_Handler load_dotenv(dotenv_path='.env') @@ -37,7 +37,8 @@ bot_version = "0.2.1" user_list = [] #create api handler -api_handler = API_Handler("https://aktienbot.flokaiser.com", os.getenv("BOT_EMAIL"), os.getenv("BOT_PASSWORD")) +api_handler = API_Handler("https://aktienbot.flokaiser.com/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) +print(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): @@ -243,16 +244,14 @@ def send_news(message): """ user_id = int(message.from_user.id) - keywords = api_handler.get_keywords(user_id) - keyword = keywords[0] + keywords = api_handler.get_user_keywords(user_id) + keyword_search = 'OR'.join(keywords) - articles = news.get_top_news_by_keyword(keywords[0]) - 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}") - return - bot.send_message(chat_id=user_id, text=f"_keyword: {keyword}_\n\n" + formatted_article, parse_mode="MARKDOWN") + news_list = api_handler.get_news_for_keyword(keyword_search)['articles'] + + for news in news_list: + formatted_article = news.format_article(news) + bot.send_message(chat_id=user_id, text=formatted_article, parse_mode="MARKDOWN") @bot.message_handler(commands=['addkeyword']) @@ -271,9 +270,30 @@ def add_keyword(message): def store_keyword(message): user_id = int(message.from_user.id) - keyword = str(message.text) - api_handler.add_keyword(user_id, keyword) - bot.send_message(chat_id=user_id, text=f'Keyword {keyword} added.') + print(str(user_id)) + keyword = str(message.text).lower() + api_handler.set_keyword(user_id, keyword) + bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" added.') + +@bot.message_handler(commands=['removekeyword']) +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() + api_handler.delete_keyword(user_id, keyword) + bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" removed.') @bot.message_handler(func=lambda message: True) # Returning that command is unkown for any other statement -- 2.45.2 From 4afd1ab87be8adcff99b2263529eb1b058fe0558 Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 12:04:49 +0200 Subject: [PATCH 10/66] workaround for connection problems --- telegram_bot/api_handling/api_handler.py | 22 ++++++++++++++-------- telegram_bot/bot.py | 24 ++++++++++++++++++++---- telegram_bot/news/news_fetcher.py | 7 +++++-- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index 97eb937..8c14833 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -83,16 +83,20 @@ class API_Handler: Returns: list: list of keywords """ + keywords = [] with r.Session() as s: headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} req = s.get(self.db_adress + "/keywords", headers=headers) - print(req.status_code) - keywords_json = req.json()["data"] - keywords = [] - for keyword in keywords_json: - keywords.append(keyword["keyword"]) + if(req.status_code == 200): + keywords_json = req.json()["data"] + for keyword in keywords_json: + keywords.append(keyword["keyword"]) + + return keywords + + else: + return self.get_user_keywords(user_id) # might end in infinite loop!! - return keywords def set_keyword(self, user_id, keyword): @@ -193,8 +197,10 @@ class API_Handler: with r.Session() as s: headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} req = s.get(self.db_adress + "/transactions", headers=headers) - transactions_dict = dict(req.json()["data"]) - return transactions_dict + + if req.status_code == 200: + transactions_dict = dict(req.json()["data"]) + return transactions_dict def set_transaction(self, user_id, count, price, symbol, timestamp): diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 9f75ecf..43d8845 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -245,12 +245,12 @@ def send_news(message): user_id = int(message.from_user.id) keywords = api_handler.get_user_keywords(user_id) - keyword_search = 'OR'.join(keywords) + keywords_search = ','.join(keywords) - news_list = api_handler.get_news_for_keyword(keyword_search)['articles'] + news_list = news.get_top_news_by_keyword(keywords_search)["articles"] - for news in news_list: - formatted_article = news.format_article(news) + for article in news_list: + formatted_article = news.format_article(article) bot.send_message(chat_id=user_id, text=formatted_article, parse_mode="MARKDOWN") @@ -275,6 +275,7 @@ def store_keyword(message): api_handler.set_keyword(user_id, keyword) bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" added.') + @bot.message_handler(commands=['removekeyword']) def remove_keyword(message): """ Remove keyword from user @@ -296,6 +297,21 @@ def remove_keyword_step(message): bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" removed.') +@bot.message_handler(commands=['keywords']) +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) + bot.send_message(chat_id=user_id, text=f'Your keywords are: {keywords}') + + @bot.message_handler(func=lambda message: True) # Returning that command is unkown for any other statement def echo_all(message): diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index 69c0807..e320936 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -6,6 +6,7 @@ __date__ = "15.03.2022" __version__ = "0.0.1" __license__ = "None" +from ast import parse import sys import os import json @@ -13,6 +14,7 @@ import requests from newsapi import NewsApiClient from dotenv import load_dotenv +import urllib.parse as urlparse load_dotenv() @@ -31,8 +33,9 @@ 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') + """ + keyword_url = urlparse.quote(keyword) + top_headlines = newsapi.get_top_headlines(q=keyword_url, sources=str_sources, language='en') return top_headlines def format_article(article): -- 2.45.2 From 4bd53c01169fea417372efa1d4c586641cb1f41d Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 12:20:58 +0200 Subject: [PATCH 11/66] news working --- telegram_bot/bot.py | 15 ++++++++++----- telegram_bot/news/news_fetcher.py | 4 +--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 43d8845..c1f21f2 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -245,13 +245,18 @@ def send_news(message): user_id = int(message.from_user.id) keywords = api_handler.get_user_keywords(user_id) - keywords_search = ','.join(keywords) - + keywords_search = ' OR '.join(keywords) + print(keywords_search) news_list = news.get_top_news_by_keyword(keywords_search)["articles"] - for article in news_list: - formatted_article = news.format_article(article) - bot.send_message(chat_id=user_id, text=formatted_article, parse_mode="MARKDOWN") + 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=['addkeyword']) diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index e320936..bf2aeb9 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -14,7 +14,6 @@ import requests from newsapi import NewsApiClient from dotenv import load_dotenv -import urllib.parse as urlparse load_dotenv() @@ -34,8 +33,7 @@ def get_top_news_by_keyword(keyword): Returns: JSON/dict: dict containing articles """ - keyword_url = urlparse.quote(keyword) - top_headlines = newsapi.get_top_headlines(q=keyword_url, sources=str_sources, language='en') + top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en') return top_headlines def format_article(article): -- 2.45.2 From 4005e8dccf696cd81c9581825841dcb3ecf6c17e Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 12:28:28 +0200 Subject: [PATCH 12/66] fetching news by keywords --- telegram_bot/bot.py | 2 +- telegram_bot/news/news_fetcher.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index c1f21f2..2fcc146 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -247,7 +247,7 @@ def send_news(message): keywords = api_handler.get_user_keywords(user_id) keywords_search = ' OR '.join(keywords) print(keywords_search) - news_list = news.get_top_news_by_keyword(keywords_search)["articles"] + news_list = news.get_all_news_by_keyword(keywords_search)["articles"][:5] if news_list: for article in news_list: diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index bf2aeb9..b10d390 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -25,8 +25,8 @@ sources = source_json["sources"] str_sources = ",".join([source["id"] for source in sources]) -def get_top_news_by_keyword(keyword): - """get top news to keyword +def get_all_news_by_keyword(keyword, from_date="2022-01-01", to_date="2022-03-29"): # hard coded will change soon + """get all news to keyword Args: keyword (String): keyword for search -- 2.45.2 From 0aee85d718fe4f7dd2b806c43e1b6410bd0afc4f Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 12:29:13 +0200 Subject: [PATCH 13/66] bug fix --- telegram_bot/news/news_fetcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index b10d390..f8764ba 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -56,6 +56,6 @@ if __name__ == '__main__': print("fetching top news by keyword business...") - 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 -- 2.45.2 From 6289e5dc71d37d4b5ef91a71959bcd9c9b42a72d Mon Sep 17 00:00:00 2001 From: Rripped Date: Tue, 29 Mar 2022 13:37:44 +0200 Subject: [PATCH 14/66] added date parameter --- telegram_bot/bot.py | 7 ++++++- telegram_bot/news/news_fetcher.py | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 2fcc146..b24599a 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -24,6 +24,7 @@ import json 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 @@ -247,7 +248,11 @@ def send_news(message): keywords = api_handler.get_user_keywords(user_id) keywords_search = ' OR '.join(keywords) print(keywords_search) - news_list = news.get_all_news_by_keyword(keywords_search)["articles"][:5] + 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"][:5] if news_list: for article in news_list: diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index f8764ba..f913257 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -11,6 +11,7 @@ import sys import os import json import requests +import datetime as dt from newsapi import NewsApiClient from dotenv import load_dotenv @@ -25,15 +26,16 @@ sources = source_json["sources"] str_sources = ",".join([source["id"] for source in sources]) -def get_all_news_by_keyword(keyword, from_date="2022-01-01", to_date="2022-03-29"): # hard coded will change soon +def get_all_news_by_keyword(keyword, from_date="2000-01-01"): # hard coded will change soon """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') + top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en', from_param=from_date) return top_headlines def format_article(article): @@ -54,7 +56,8 @@ 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_all_news_by_keyword("bitcoin") formatted_article = format_article(articles["articles"][0]) -- 2.45.2 From cc70f8c47850fd6756983508c4ebf8e405b0fdda Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Mon, 4 Apr 2022 16:38:15 +0200 Subject: [PATCH 15/66] share handler in api_handler --- telegram_bot/api_handling/api_handler.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index 8c14833..bc5ef79 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -248,4 +248,6 @@ if __name__ == "__main__": 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(shares) sys.exit(1) \ No newline at end of file -- 2.45.2 From 0b8ae845ede4b1cb7f20b7fb6ad5c099409f8e07 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Mon, 4 Apr 2022 16:54:25 +0200 Subject: [PATCH 16/66] added max req params --- telegram_bot/api_handling/api_handler.py | 49 ++++++++++++++++++------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index bc5ef79..88810ce 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -74,15 +74,19 @@ class API_Handler: return None - def get_user_keywords(self, user_id): + 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)} @@ -95,7 +99,7 @@ class API_Handler: return keywords else: - return self.get_user_keywords(user_id) # might end in infinite loop!! + return self.get_user_keywords(user_id, max_retries-1) @@ -133,24 +137,32 @@ class API_Handler: return req.status_code - def get_user_shares(self, user_id): + 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) - shares_json = req.json()["data"] - shares = [] - for share in shares_json: - shares.append(share["symbol"]) + if(req.status_code == 200): + shares_json = req.json()["data"] + shares = [] + for share in shares_json: + shares.append(share["symbol"]) - return shares + return shares + + else: + return self.get_user_shares(user_id, max_retries-1) def set_share(self, user_id, symbol): @@ -185,15 +197,19 @@ class API_Handler: return req.status_code - def get_user_transactions(self, user_id): + 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) @@ -201,6 +217,8 @@ class API_Handler: if req.status_code == 200: transactions_dict = dict(req.json()["data"]) return transactions_dict + else: + return self.get_user_transactions(user_id, max_retries-1) def set_transaction(self, user_id, count, price, symbol, timestamp): @@ -223,20 +241,27 @@ class API_Handler: return req.status_code - def get_user_portfolio(self, user_id): + 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) - portfolio_dict = dict(req.json()["data"]) - return portfolio_dict + if req.status_code == 200: + portfolio_dict = dict(req.json()["data"]) + return portfolio_dict + else: + return self.get_user_portfolio(user_id, max_retries-1) -- 2.45.2 From a2aed53bc89451f4d1259849f12e2b3d57b1b483 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Mon, 4 Apr 2022 17:33:54 +0200 Subject: [PATCH 17/66] api adress updated --- telegram_bot/bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index b24599a..be23eb4 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -38,8 +38,8 @@ bot_version = "0.2.1" user_list = [] #create api handler -api_handler = API_Handler("https://aktienbot.flokaiser.com/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) -print(api_handler.token) +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): -- 2.45.2 From 643c040b32cefdb180468d606b0e01ca0d7cc742 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Mon, 4 Apr 2022 18:57:59 +0200 Subject: [PATCH 18/66] updated and added functions --- telegram_bot/news/news_fetcher.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index f913257..332dafd 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -36,7 +36,26 @@ def get_all_news_by_keyword(keyword, from_date="2000-01-01"): # hard coded will JSON/dict: dict containing articles """ top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en', from_param=from_date) - return top_headlines + if(top_headlines["status"] == "ok"): + return top_headlines + else: + return None + + +def get_top_news_by_keyword(keyword): + """get top news to keyword + Args: + keyword (String): keyword for search + + Returns: + JSON/dict: dict containing articles + """ + top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language='en') + if(top_headlines["status"] == "ok"): + return top_headlines + else: + return None + def format_article(article): """format article for messaging (using markdown syntax) -- 2.45.2 From 96e96b4612922f155278fc205a67a23f4546ae0f Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Mon, 4 Apr 2022 18:59:00 +0200 Subject: [PATCH 19/66] updated functions, added fail handling and messages --- telegram_bot/bot.py | 88 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index be23eb4..c50ad61 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -14,6 +14,7 @@ __license__ = "None" # API Documentation https://core.telegram.org/bots/api # Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started +from ast import keyword import os import telebot @@ -45,8 +46,8 @@ class User: # Currently saving users in this class to test functionality -> late 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 @@ -115,7 +116,7 @@ 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/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\n_For further details see https://gruppe1.testsites.info _", parse_mode='MARKDOWN') @bot.message_handler(commands=['users']) @@ -152,7 +153,7 @@ 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) @@ -205,7 +206,7 @@ def send_update(message): 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)}' + 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) @@ -232,12 +233,12 @@ 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']) +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 '/news' + :param message: message that was reacted to, in this case always containing '/allnews' :raises: none @@ -246,13 +247,22 @@ def send_news(message): 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 too 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"][:5] + news_list = news.get_all_news_by_keyword(keywords_search, from_date_formatted)["articles"] if news_list: for article in news_list: @@ -262,6 +272,40 @@ def send_news(message): bot.send_message(chat_id=user_id, text='No news found for your keywords.') +@bot.message_handler(commands=['news']) +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' + + :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 too 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 /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(commands=['addkeyword']) @@ -282,8 +326,11 @@ def store_keyword(message): user_id = int(message.from_user.id) print(str(user_id)) keyword = str(message.text).lower() - api_handler.set_keyword(user_id, keyword) - bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" added.') + 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. (statuscode {status})') @bot.message_handler(commands=['removekeyword']) @@ -303,8 +350,11 @@ def remove_keyword(message): def remove_keyword_step(message): user_id = int(message.from_user.id) keyword = str(message.text).lower() - api_handler.delete_keyword(user_id, keyword) - bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" removed.') + 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']) @@ -319,10 +369,18 @@ def send_keywords(message): """ user_id = int(message.from_user.id) keywords = api_handler.get_user_keywords(user_id) - bot.send_message(chat_id=user_id, text=f'Your keywords are: {keywords}') + if keywords == None: + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too 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(func=lambda message: True) # Returning that command is unkown for any other statement +@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 -- 2.45.2 From 3711331338b61bd954e93ad462c44deeda482c3c Mon Sep 17 00:00:00 2001 From: Rripped <75929322+Rripped@users.noreply.github.com> Date: Mon, 4 Apr 2022 19:01:23 +0200 Subject: [PATCH 20/66] Update README.md --- documentation/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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` -- 2.45.2 From 9d10b1a048f42df4073b0df79087be0d121d41d3 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 10:07:03 +0200 Subject: [PATCH 21/66] New file for regularly sending bot updates --- telegram_bot/bot_updates.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 telegram_bot/bot_updates.py diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py new file mode 100644 index 0000000..aaacd7b --- /dev/null +++ b/telegram_bot/bot_updates.py @@ -0,0 +1,7 @@ +""" +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" \ No newline at end of file -- 2.45.2 From e85bbacdde74f751a6101335540e83a6b1470fb2 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 12:38:20 +0200 Subject: [PATCH 22/66] Example and description of crontab syntax --- telegram_bot/bot_updates.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index aaacd7b..08a3db8 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -4,4 +4,17 @@ 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" \ No newline at end of file +__license__ = "None" + +''' +* * * * * code +┬ ┬ ┬ ┬ ┬ +│ │ │ │ │ +│ │ │ │ └──── weekday (0-7, Sunday is 0 or 7) +│ │ │ └────── Month (1-12) +│ │ └──────── Day (1-31) +│ └────────── Hour (0-23) +└──────────── Minute (0-59) + +example 0 8 * * * -> daily update at 8am +''' -- 2.45.2 From 40d444f36c41fa9bc2265905c0e3620a01f04b41 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 14:00:33 +0200 Subject: [PATCH 23/66] bot-updates got a send to user function and will be working with crontab --- telegram_bot/bot.py | 2 +- telegram_bot/bot_updates.py | 40 ++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index c50ad61..83582ba 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -419,7 +419,7 @@ def query_text(inline_query): def main_loop(): - """ Get Information about bot status every 3 seconds + """ Start bot :raises: none :rtype: none diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index 08a3db8..88c3e86 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -6,11 +6,16 @@ __date__ = "05.04.2022" __version__ = "0.0.1" __license__ = "None" +from shares.share_fetcher import get_share_price +import time +from bot import bot +import sys + ''' * * * * * code ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ -│ │ │ │ └──── weekday (0-7, Sunday is 0 or 7) +│ │ │ │ └──── weekday (0->Monday, 7->Sunday) │ │ │ └────── Month (1-12) │ │ └──────── Day (1-31) │ └────────── Hour (0-23) @@ -18,3 +23,36 @@ __license__ = "None" example 0 8 * * * -> daily update at 8am ''' + +def main_loop(): + """ main loop for regularly sending updates + :raises: none + + :rtype: none + """ + + +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('This script shall not be run directly. Starting main_loop for debugging purposes.') + try: + main_loop() + sys.exit(-1) + except KeyboardInterrupt: + print("Ending") + sys.exit(-1) \ No newline at end of file -- 2.45.2 From 2c0bbe31111cd4c6e9a0ab316346add54cc8ddcc Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 14:12:12 +0200 Subject: [PATCH 24/66] Work in progress, need some communication first. Working on bot_updates --- telegram_bot/bot_updates.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index 88c3e86..d5f351b 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -24,6 +24,9 @@ import sys example 0 8 * * * -> daily update at 8am ''' +user_ids = [] +user_crontab = [] + def main_loop(): """ main loop for regularly sending updates :raises: none @@ -31,6 +34,9 @@ def main_loop(): :rtype: none """ + current_time = time.ctime() + send_to_user(current_time) + def send_to_user(pText, pUser_id = 1770205310): -- 2.45.2 From 7b99be963311696451a954938062a40ded09ebea Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 15:07:06 +0200 Subject: [PATCH 25/66] Updating contrab based on time is working, need api calls --- telegram_bot/bot_updates.py | 51 +++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index d5f351b..e1fe445 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -8,8 +8,10 @@ __license__ = "None" from shares.share_fetcher import get_share_price import time +import datetime from bot import bot import sys +from multiprocessing import Process ''' * * * * * code @@ -34,8 +36,53 @@ def main_loop(): :rtype: none """ - current_time = time.ctime() - send_to_user(current_time) + current_time_datetime = datetime.datetime.now() + + print(time.ctime()) # Debug + + p1 = Process(target= update_crontab, args=(current_time_datetime, )) #Test threading instead of multiprocessing + p1.start() + p3 = Process(target= update_based_on_crontab, args=(current_time_datetime, ) ) + p3.daemon = True + p3.start() + p1.join() + p3.terminate() + p1.terminate() + + +def update_crontab(pCurrent_Time): + """ Updating crontab lists every hour + :type pCurrent_Time: time when starting crontab update + :param pCurrent_Time: datetime + + :raises: none + + :rtype: none + """ + + # Update user info now + + print('in update_crontab') + + user_ids.clear() # Example for me (Florian Kellermann) + user_crontab.clear() + user_ids.append(1770205310) + user_crontab.append("0 8 * * *") + + while True: + time_difference = datetime.datetime.now() - pCurrent_Time + if float(str(time_difference).split(':')[0]) >=1: + update_crontab(datetime.datetime.now()) + + +def update_based_on_crontab(pCurrent_Time): + current_time_ctime = time.ctime() + for i in range(len(user_crontab)): + print('tbd') + + + time.sleep(60) + def send_to_user(pText, pUser_id = 1770205310): -- 2.45.2 From 5311c891939baa452bf89f2bc832e7da16ac83e6 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 15:12:51 +0200 Subject: [PATCH 26/66] minor updates --- telegram_bot/bot_updates.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index e1fe445..e729e8a 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -40,7 +40,7 @@ def main_loop(): print(time.ctime()) # Debug - p1 = Process(target= update_crontab, args=(current_time_datetime, )) #Test threading instead of multiprocessing + p1 = Process(target= update_crontab, args=(current_time_datetime, )) p1.start() p3 = Process(target= update_based_on_crontab, args=(current_time_datetime, ) ) p3.daemon = True @@ -73,6 +73,7 @@ def update_crontab(pCurrent_Time): time_difference = datetime.datetime.now() - pCurrent_Time if float(str(time_difference).split(':')[0]) >=1: update_crontab(datetime.datetime.now()) + break def update_based_on_crontab(pCurrent_Time): -- 2.45.2 From aee793deb4ed2775ef1cdf8a1e4fa8732e5f5024 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 15:17:04 +0200 Subject: [PATCH 27/66] creating sends from crontab in work --- telegram_bot/bot_updates.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index e729e8a..5467aad 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -78,13 +78,29 @@ def update_crontab(pCurrent_Time): def update_based_on_crontab(pCurrent_Time): current_time_ctime = time.ctime() + + if str(current_time_ctime).split(' ')[0] == "Mon": + current_day = 0 + elif str(current_time_ctime).split(' ')[0] == "Tue": + current_day = 1 + elif str(current_time_ctime).split(' ')[0] == "Wed": + current_day = 3 + elif str(current_time_ctime).split(' ')[0] == "Thu": + current_day = 4 + elif str(current_time_ctime).split(' ')[0] == "Fri": + current_day = 5 + elif str(current_time_ctime).split(' ')[0] == "Sat": + current_day = 6 + elif str(current_time_ctime).split(' ')[0] == "Sun": + current_day = 7 + else: + print('Error with time code') + sys.exit(-1) + for i in range(len(user_crontab)): print('tbd') - time.sleep(60) - - def send_to_user(pText, pUser_id = 1770205310): -- 2.45.2 From 84754dd54f46b2b2d6ecc9f74e80cf89941ce984 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 5 Apr 2022 18:23:11 +0200 Subject: [PATCH 28/66] Update to bot_updates --- telegram_bot/bot_updates.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index 5467aad..a709bf7 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -78,28 +78,49 @@ def update_crontab(pCurrent_Time): def update_based_on_crontab(pCurrent_Time): current_time_ctime = time.ctime() + ctime_split = str(current_time_ctime).split(' ') - if str(current_time_ctime).split(' ')[0] == "Mon": + if [0] == "Mon": current_day = 0 - elif str(current_time_ctime).split(' ')[0] == "Tue": + elif ctime_split[0] == "Tue": current_day = 1 - elif str(current_time_ctime).split(' ')[0] == "Wed": + elif ctime_split[0] == "Wed": current_day = 3 - elif str(current_time_ctime).split(' ')[0] == "Thu": + elif ctime_split[0] == "Thu": current_day = 4 - elif str(current_time_ctime).split(' ')[0] == "Fri": + elif ctime_split[0] == "Fri": current_day = 5 - elif str(current_time_ctime).split(' ')[0] == "Sat": + elif ctime_split[0] == "Sat": current_day = 6 - elif str(current_time_ctime).split(' ')[0] == "Sun": + elif ctime_split[0] == "Sun": current_day = 7 else: print('Error with time code') sys.exit(-1) for i in range(len(user_crontab)): - print('tbd') + day_match = False + hour_match = False + user_crontab[i] = user_crontab.strip() + + contrab_split = str(user_crontab[i]).split(' ') + + if ',' in contrab_split[4]: # if the user wants to be alerted on multiple specific days + contrab_days = contrab_split[4].split(',') + else: + contrab_days = contrab_days + + for element in contrab_days: + if str(current_day) == element or element=='*': + hour_match = True + + + + + if hour_match and day_match: + send_to_user("regular update", pUser_id=user_crontab[i]) + def send_to_user(pText, pUser_id = 1770205310): -- 2.45.2 From 813231449e6b0101a742bd7913bcd828e589082a Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Wed, 6 Apr 2022 14:26:52 +0200 Subject: [PATCH 29/66] Mistake corrected --- telegram_bot/bot_updates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index a709bf7..821de90 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -80,7 +80,7 @@ def update_based_on_crontab(pCurrent_Time): current_time_ctime = time.ctime() ctime_split = str(current_time_ctime).split(' ') - if [0] == "Mon": + if ctime_split[0] == "Mon": current_day = 0 elif ctime_split[0] == "Tue": current_day = 1 -- 2.45.2 From 27858a3b5993eacd16da6d5004d8c6f23394259f Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 12 Apr 2022 10:08:41 +0200 Subject: [PATCH 30/66] added crontab put function --- telegram_bot/api_handling/api_handler.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index 88810ce..bc8bc8a 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -263,7 +263,20 @@ class API_Handler: 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 + """ + 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__": -- 2.45.2 From 2e48d2a27ee0a3b5621f471f2a81d07ad92f11d1 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 12 Apr 2022 10:12:35 +0200 Subject: [PATCH 31/66] removed unused --- telegram_bot/news/news_fetcher.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telegram_bot/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index 332dafd..2b79721 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -6,7 +6,6 @@ __date__ = "15.03.2022" __version__ = "0.0.1" __license__ = "None" -from ast import parse import sys import os import json @@ -26,7 +25,7 @@ sources = source_json["sources"] str_sources = ",".join([source["id"] for source in sources]) -def get_all_news_by_keyword(keyword, from_date="2000-01-01"): # hard coded will change soon +def get_all_news_by_keyword(keyword, from_date="2000-01-01"): """get all news to keyword Args: keyword (String): keyword for search @@ -80,4 +79,5 @@ if __name__ == '__main__': 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 -- 2.45.2 From ac4c59bbf8e618e852e37917a5db07ce7a3289af Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Tue, 12 Apr 2022 10:33:45 +0200 Subject: [PATCH 32/66] Fix share delete bug --- frontend/src/app/Services/bot.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/Services/bot.service.ts b/frontend/src/app/Services/bot.service.ts index 0e764cd..7e8334a 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} share + * @param {string} symbol * @returns Observable */ - public deleteShare(share: string): Observable { + public deleteShare(symbol: string): Observable { return this.http.delete(API_URL + 'share', { headers: new HttpHeaders({ 'Content-Type': 'application/json', Authorization: 'Bearer ' + this.tokenStorage.getToken(), }), body: { - share, + symbol, }, }); } -- 2.45.2 From 30bccbf2381d884096f348626a6a16763c0cd169 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 12 Apr 2022 10:41:48 +0200 Subject: [PATCH 33/66] added user funcs of api --- telegram_bot/api_handling/api_handler.py | 48 +++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index bc8bc8a..33c9a41 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -74,6 +74,51 @@ class API_Handler: return None + def get_user(self, user_id, max_retries=10): + """gets the shares of the user + + Args: + user_id (int): id of the user + max_retries (int): max retries for the request + + Returns: + json: json of user infos + """ + if max_retries <= 0: + return None + + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} + req = s.get(self.db_adress + "/user", headers=headers) + if(req.status_code == 200): + return req.json()["data"] + + else: + return self.get_user(user_id, max_retries-1) + + + def get_all_users(self, max_retries=10): + """gets all users + + Args: + max_retries (int): max retries for the request + + Returns: + list: list of users + """ + if max_retries <= 0: + return None + + with r.Session() as s: + headers = {'Authorization': 'Bearer ' + self.token} + req = s.get(self.db_adress + "/users", headers=headers) + if(req.status_code == 200): + return req.json()["data"] + + else: + return self.get_all_users(max_retries-1) + + def get_user_keywords(self, user_id, max_retries=10): """gets the keywords of the user @@ -282,10 +327,11 @@ class API_Handler: if __name__ == "__main__": print("This is a module for the telegram bot. It is not intended to be run directly.") - handler = API_Handler("https://aktienbot.flokaiser.com/api", "bot@example.com", "bot") + handler = API_Handler("https://gruppe1.testsites.info/api", "bot@example.com", "bot") print(handler.token) keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is currently mine (Linus) print(keywords) shares = handler.get_user_portfolio(user_id = 1709356058) + print(handler.set_cron_interval(user_id = 1709356058, cron_interval = "0 0 * * *")) print(shares) sys.exit(1) \ No newline at end of file -- 2.45.2 From 561ce58d73274d147569f54613940cf054f18c0b Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 12 Apr 2022 11:32:33 +0200 Subject: [PATCH 34/66] added new lib --- telegram_bot/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/telegram_bot/requirements.txt b/telegram_bot/requirements.txt index 6b0de09..2e8462d 100644 --- a/telegram_bot/requirements.txt +++ b/telegram_bot/requirements.txt @@ -4,3 +4,4 @@ yfinance~=0.1.70 newsapi-python~=0.2.6 python-dotenv~=0.20.0 requests~=2.27.1 +APScheduler~=3.9.1 -- 2.45.2 From c8d461b747ea6746d0dfc6065a831c003f4083c7 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 12 Apr 2022 11:33:21 +0200 Subject: [PATCH 35/66] tested new methods --- telegram_bot/api_handling/api_handler.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index 33c9a41..b1ce853 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -332,6 +332,10 @@ if __name__ == "__main__": keywords = handler.get_user_keywords(user_id = 1709356058) #user_id is currently mine (Linus) print(keywords) shares = handler.get_user_portfolio(user_id = 1709356058) - print(handler.set_cron_interval(user_id = 1709356058, cron_interval = "0 0 * * *")) + print("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 -- 2.45.2 From 1095c6378850de3dbb831f51eb5a43809c0f4697 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 12 Apr 2022 11:33:53 +0200 Subject: [PATCH 36/66] added scheduler --- telegram_bot/bot_scheduler.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 telegram_bot/bot_scheduler.py diff --git a/telegram_bot/bot_scheduler.py b/telegram_bot/bot_scheduler.py new file mode 100644 index 0000000..e69de29 -- 2.45.2 From 24c2702f1027ac634b55a7369ee1ae03ab059590 Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Tue, 12 Apr 2022 11:36:23 +0200 Subject: [PATCH 37/66] Added comments --- api/app/auth.py | 4 +- api/app/blueprints/keyword.py | 15 ++++--- api/app/blueprints/portfolio.py | 5 +++ api/app/blueprints/share_price.py | 13 +++--- api/app/blueprints/shares.py | 22 +++++----- api/app/blueprints/telegram.py | 2 + api/app/blueprints/transactions.py | 5 +++ api/app/blueprints/user.py | 65 +++++++++++++++++------------ api/app/helper_functions.py | 49 ++++++++++++++++++++-- api/app/schema.py | 1 + api/generate_sample_transactions.py | 8 ++-- 11 files changed, 132 insertions(+), 57 deletions(-) diff --git a/api/app/auth.py b/api/app/auth.py index e96d28a..e1a4bba 100644 --- a/api/app/auth.py +++ b/api/app/auth.py @@ -17,7 +17,9 @@ def verify_token(token): if token is None: return False - if ':' in token: # Bot token + # 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: token = token.split(":")[0] try: diff --git a/api/app/blueprints/keyword.py b/api/app/blueprints/keyword.py index 4412621..e3edc21 100644 --- a/api/app/blueprints/keyword.py +++ b/api/app/blueprints/keyword.py @@ -31,9 +31,10 @@ 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 + # Keyword doesn't exist yet for this user -> add it new_keyword = Keyword( email=email, keyword=key @@ -54,17 +55,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") - key = data['keyword'] - - check_keyword = db.session.query(Keyword).filter_by(keyword=key, email=email).first() - + # Check if keyword exists + check_keyword = db.session.query(Keyword).filter_by(keyword=data['keyword'], email=email).first() if check_keyword is None: return abort(500, "Keyword doesn't exist for this user") else: - db.session.query(Keyword).filter_by(keyword=key, email=email).delete() + # Keyword exists -> delete it + db.session.query(Keyword).filter_by(keyword=data['keyword'], email=email).delete() db.session.commit() return make_response({}, 200, "Successfully removed keyword") @@ -80,6 +81,8 @@ 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 2b6ab02..2cefe4d 100644 --- a/api/app/blueprints/portfolio.py +++ b/api/app/blueprints/portfolio.py @@ -25,8 +25,12 @@ def get_portfolio(): email = get_email_or_abort_401() return_portfolio = [] + + # Get all transactions of current user transactions = db.session.execute("SELECT symbol, SUM(count), SUM(price), MAX(time) FROM `transactions` WHERE email = '" + email + "' GROUP BY symbol;").all() + # If there are no transactions, return empty portfolio + # Otherwise calculate portfolio if transactions is not None: for row in transactions: data = { @@ -37,6 +41,7 @@ def get_portfolio(): 'current_price': 0 } + # Add current share value to portfolio 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 aa2a302..d63a844 100644 --- a/api/app/blueprints/share_price.py +++ b/api/app/blueprints/share_price.py @@ -24,6 +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 symbol FROM `transactions` GROUP BY symbol;").all() return_symbols = [] @@ -39,6 +40,7 @@ def get_transaction_symbols(): @share_price_blueprint.auth_required(auth) @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_symbol_data_exists(data): abort(400, message="Symbol missing") @@ -48,14 +50,11 @@ def add_symbol_price(data): if not check_if_time_data_exists(data): abort(400, message="Time missing") - symbol = data['symbol'] - price = data['price'] - time = data['time'] - + # Add share price share_price = SharePrice( - symbol=symbol, - price=price, - date=datetime.datetime.strptime(time, '%Y-%m-%dT%H:%M:%S.%fZ'), + symbol=data['symbol'], + price=data['price'], + date=datetime.datetime.strptime(data['time'], '%Y-%m-%dT%H:%M:%S.%fZ'), ) db.session.add(share_price) diff --git a/api/app/blueprints/shares.py b/api/app/blueprints/shares.py index 56dad69..e015585 100644 --- a/api/app/blueprints/shares.py +++ b/api/app/blueprints/shares.py @@ -26,17 +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_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 already exists + check_share = db.session.query(Share).filter_by(symbol=data['symbol'], email=email).first() if check_share is None: - # Keyword doesn't exist yet for this user + # Keyword doesn't exist yet for this user -> add it new_symbol = Share( email=email, - symbol=symbol + symbol=data['symbol'] ) db.session.add(new_symbol) db.session.commit() @@ -54,17 +54,17 @@ def add_symbol(data): def remove_symbol(data): email = get_email_or_abort_401() + # Check if required data is available 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(symbol=data['symbol'], email=email).first() if check_share is None: abort(500, "Symbol doesn't exist for this user") else: - db.session.query(Share).filter_by(symbol=symbol, email=email).delete() + # Delete share + db.session.query(Share).filter_by(symbol=data['symbol'], email=email).delete() db.session.commit() return make_response({}, 200, "Successfully removed symbol") @@ -80,6 +80,8 @@ 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()) diff --git a/api/app/blueprints/telegram.py b/api/app/blueprints/telegram.py index 10aad9f..b492a91 100644 --- a/api/app/blueprints/telegram.py +++ b/api/app/blueprints/telegram.py @@ -24,11 +24,13 @@ __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 da3b7bf..2bc469b 100644 --- a/api/app/blueprints/transactions.py +++ b/api/app/blueprints/transactions.py @@ -27,6 +27,7 @@ __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_symbol_data_exists(data): abort(400, "Symbol missing") @@ -39,6 +40,7 @@ def add_transaction(data): if not check_if_price_data_exists(data): abort(400, "Price missing") + # Add transaction new_transaction = Transaction( email=email, symbol=data['symbol'], @@ -60,8 +62,11 @@ 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()) diff --git a/api/app/blueprints/user.py b/api/app/blueprints/user.py index 196af26..cc6b510 100644 --- a/api/app/blueprints/user.py +++ b/api/app/blueprints/user.py @@ -28,6 +28,8 @@ 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()) @@ -41,6 +43,7 @@ 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") @@ -51,23 +54,26 @@ 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") - email = data['email'] - password = data['password'] + # Query current user + query_user = get_user(data['email']) - query_user = get_user(email) - - if not check_password(query_user.password, password.encode("utf-8")): # Password incorrect + # Check if password matches + if not check_password(query_user.password, data['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") @@ -78,6 +84,7 @@ 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") @@ -87,19 +94,16 @@ def register(data): if not check_if_password_data_exists(data): abort(400, "Password missing") - 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 + # Check if user already exists + query_user = db.session.query(User).filter_by(email=data['email']).first() + if query_user is not None: abort(500, message="Email already exist") + # Add user to database new_user = User( - email=email, - username=username, - password=hash_password(password), + email=data['email'], + username=data['username'], + password=hash_password(data['password']), admin=False, cron="0 8 * * *" ) @@ -117,11 +121,14 @@ 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'] @@ -138,18 +145,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") - email = data['email'] - admin = data['admin'] + # Get user by email + query_user = get_user(data['email']) - query_user = get_user(email) - - query_user.admin = admin + # Update user admin state + query_user.admin = data['admin'] db.session.commit() return make_response({}, 200, "Successfully updated users admin rights") @@ -163,9 +170,11 @@ 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() @@ -178,18 +187,22 @@ 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") - 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() + # 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() db.session.commit() - else: # Delete different user than my user -> only admin users + else: abort_if_no_admin() - db.session.query(User).filter_by(email=email).delete() + db.session.query(User).filter_by(email=data['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 d3edea3..560f114 100644 --- a/api/app/helper_functions.py +++ b/api/app/helper_functions.py @@ -14,28 +14,48 @@ 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: - if ':' in token: # Maybe bot token, check if token valid and return username after ":" then + + # 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: 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: @@ -47,12 +67,18 @@ 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: @@ -60,7 +86,10 @@ def get_token(): def get_email_or_abort_401(): - # get username from jwt token + """ + Try to receive email from token data + If email is not provided -> abort 401 + """ email = get_email_from_token_data(get_token()) if email is None: # If token not provided or invalid -> return 401 code @@ -70,24 +99,38 @@ 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() - if query_user is None: # Username doesn't exist + # Check if user exists + if query_user is None: abort(500, message="Can't find user") return query_user diff --git a/api/app/schema.py b/api/app/schema.py index f48f232..134c401 100644 --- a/api/app/schema.py +++ b/api/app/schema.py @@ -22,6 +22,7 @@ class UsersSchema(Schema): username = String() telegram_user_id = String() email = Email() + cron = String() class AdminDataSchema(Schema): diff --git a/api/generate_sample_transactions.py b/api/generate_sample_transactions.py index 3c28db4..b891a34 100644 --- a/api/generate_sample_transactions.py +++ b/api/generate_sample_transactions.py @@ -10,17 +10,17 @@ import random import faker import requests -username = '' -password = '' +username = 'bot@example.com' +password = 'bot' shares = ["TWTR", "GOOG", "AAPL", "MSFT", "AMZN", "FB", "NFLX", "TSLA", "BABA", "BA", "BAC", "C", "CAT", "CSCO", "CVX", "DIS", "DOW", "DUK", "GE", "HD", "IBM" "INTC", "JNJ", "JPM", "KO", "MCD", "MMM", "MRK", "NKE", "PFE", "PG", "T", "UNH", "UTX", "V", "VZ", "WMT", "XOM", "YHOO", "ZTS"] fake = faker.Faker() -token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": username, "password": password}).json()['data']['token'] +token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": username, "password": password}).json()['data']['token'] + ":1709356058" -for i in range(1, 1000): +for i in range(1, 10): payload = { "count": random.randint(1, 100), "price": random.random() * 100, -- 2.45.2 From 489cd4c5b285b92de77de7f6129c13e684d7f2ea Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Tue, 12 Apr 2022 12:16:25 +0200 Subject: [PATCH 38/66] Removed code --- api/generate_sample_transactions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/generate_sample_transactions.py b/api/generate_sample_transactions.py index b891a34..2c38856 100644 --- a/api/generate_sample_transactions.py +++ b/api/generate_sample_transactions.py @@ -10,15 +10,15 @@ import random import faker import requests -username = 'bot@example.com' -password = 'bot' +username = '' +password = '' shares = ["TWTR", "GOOG", "AAPL", "MSFT", "AMZN", "FB", "NFLX", "TSLA", "BABA", "BA", "BAC", "C", "CAT", "CSCO", "CVX", "DIS", "DOW", "DUK", "GE", "HD", "IBM" "INTC", "JNJ", "JPM", "KO", "MCD", "MMM", "MRK", "NKE", "PFE", "PG", "T", "UNH", "UTX", "V", "VZ", "WMT", "XOM", "YHOO", "ZTS"] fake = faker.Faker() -token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": username, "password": password}).json()['data']['token'] + ":1709356058" +token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": username, "password": password}).json()['data']['token'] for i in range(1, 10): payload = { -- 2.45.2 From 564fa5f308921d3cabb45c2838452df4e10d7f8e Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Tue, 12 Apr 2022 12:40:42 +0200 Subject: [PATCH 39/66] Added watchtower to automatically update containers --- deploy/base/docker-compose.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/deploy/base/docker-compose.yml b/deploy/base/docker-compose.yml index 0782888..0191ffa 100644 --- a/deploy/base/docker-compose.yml +++ b/deploy/base/docker-compose.yml @@ -64,6 +64,14 @@ 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: -- 2.45.2 From 0eac07e6f548cffdf4db6e05bdfe569dd137b36a Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Tue, 12 Apr 2022 12:41:08 +0200 Subject: [PATCH 40/66] Added watchtower config --- deploy/base/.env | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 deploy/base/.env diff --git a/deploy/base/.env b/deploy/base/.env new file mode 100644 index 0000000..932c2e2 --- /dev/null +++ b/deploy/base/.env @@ -0,0 +1,3 @@ +WATCHTOWER_SCHEDULE=0 5 3 * * * +WATCHTOWER_ROLLING_RESTART=true +WATCHTOWER_CLEANUP=true \ No newline at end of file -- 2.45.2 From 2a4abb0fd064ac0eed755df4b45b479a23fd25e0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Apr 2022 12:52:48 +0000 Subject: [PATCH 41/66] Bump jasmine-core from 4.0.1 to 4.1.0 in /frontend Bumps [jasmine-core](https://github.com/jasmine/jasmine) from 4.0.1 to 4.1.0. - [Release notes](https://github.com/jasmine/jasmine/releases) - [Changelog](https://github.com/jasmine/jasmine/blob/main/RELEASE.md) - [Commits](https://github.com/jasmine/jasmine/compare/v4.0.1...v4.1.0) --- updated-dependencies: - dependency-name: jasmine-core dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- frontend/package-lock.json | 14 +++++++------- frontend/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2cc45ca..d0c34c1 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -29,7 +29,7 @@ "@angular/compiler-cli": "~13.2.0", "@types/jasmine": "~4.0.2", "@types/node": "^17.0.23", - "jasmine-core": "~4.0.0", + "jasmine-core": "~4.1.0", "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", @@ -6958,9 +6958,9 @@ } }, "node_modules/jasmine-core": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.1.tgz", - "integrity": "sha512-w+JDABxQCkxbGGxg+a2hUVZyqUS2JKngvIyLGu/xiw2ZwgsoSB0iiecLQsQORSeaKQ6iGrCyWG86RfNDuoA7Lg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.1.0.tgz", + "integrity": "sha512-8E8BiffCL8sBwK1zU9cbavLe8xpJAgOduSJ6N8PJVv8VosQ/nxVTuXj2kUeHxTlZBVvh24G19ga7xdiaxlceKg==", "dev": true }, "node_modules/jest-worker": { @@ -16612,9 +16612,9 @@ } }, "jasmine-core": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.0.1.tgz", - "integrity": "sha512-w+JDABxQCkxbGGxg+a2hUVZyqUS2JKngvIyLGu/xiw2ZwgsoSB0iiecLQsQORSeaKQ6iGrCyWG86RfNDuoA7Lg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.1.0.tgz", + "integrity": "sha512-8E8BiffCL8sBwK1zU9cbavLe8xpJAgOduSJ6N8PJVv8VosQ/nxVTuXj2kUeHxTlZBVvh24G19ga7xdiaxlceKg==", "dev": true }, "jest-worker": { diff --git a/frontend/package.json b/frontend/package.json index d31fa67..ed43eea 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -31,7 +31,7 @@ "@angular/compiler-cli": "~13.2.0", "@types/jasmine": "~4.0.2", "@types/node": "^17.0.23", - "jasmine-core": "~4.0.0", + "jasmine-core": "~4.1.0", "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", -- 2.45.2 From 1e752b60a333c77fc8b191d51d4185e13b83c0b6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Apr 2022 09:38:45 +0000 Subject: [PATCH 42/66] Bump karma from 6.3.17 to 6.3.18 in /frontend Bumps [karma](https://github.com/karma-runner/karma) from 6.3.17 to 6.3.18. - [Release notes](https://github.com/karma-runner/karma/releases) - [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) - [Commits](https://github.com/karma-runner/karma/compare/v6.3.17...v6.3.18) --- updated-dependencies: - dependency-name: karma dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- frontend/package-lock.json | 18 +++++++++--------- frontend/package.json | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2cc45ca..8a053b1 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -30,7 +30,7 @@ "@types/jasmine": "~4.0.2", "@types/node": "^17.0.23", "jasmine-core": "~4.0.0", - "karma": "~6.3.0", + "karma": "~6.3.18", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", "karma-jasmine": "~4.0.0", @@ -7093,9 +7093,9 @@ ] }, "node_modules/karma": { - "version": "6.3.17", - "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.17.tgz", - "integrity": "sha512-2TfjHwrRExC8yHoWlPBULyaLwAFmXmxQrcuFImt/JsAsSZu1uOWTZ1ZsWjqQtWpHLiatJOHL5jFjXSJIgCd01g==", + "version": "6.3.18", + "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.18.tgz", + "integrity": "sha512-YEwXVHRILKWKN7uEW9IkgTPjnYGb3YA3MDvlp04xpSRAyrNPoRmsBayLDgHykKAwBm6/mAOckj4xi/1JdQfhzQ==", "dev": true, "dependencies": { "@colors/colors": "1.5.0", @@ -7117,7 +7117,7 @@ "qjobs": "^1.2.0", "range-parser": "^1.2.1", "rimraf": "^3.0.2", - "socket.io": "^4.2.0", + "socket.io": "^4.4.1", "source-map": "^0.6.1", "tmp": "^0.2.1", "ua-parser-js": "^0.7.30", @@ -16717,9 +16717,9 @@ "dev": true }, "karma": { - "version": "6.3.17", - "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.17.tgz", - "integrity": "sha512-2TfjHwrRExC8yHoWlPBULyaLwAFmXmxQrcuFImt/JsAsSZu1uOWTZ1ZsWjqQtWpHLiatJOHL5jFjXSJIgCd01g==", + "version": "6.3.18", + "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.18.tgz", + "integrity": "sha512-YEwXVHRILKWKN7uEW9IkgTPjnYGb3YA3MDvlp04xpSRAyrNPoRmsBayLDgHykKAwBm6/mAOckj4xi/1JdQfhzQ==", "dev": true, "requires": { "@colors/colors": "1.5.0", @@ -16741,7 +16741,7 @@ "qjobs": "^1.2.0", "range-parser": "^1.2.1", "rimraf": "^3.0.2", - "socket.io": "^4.2.0", + "socket.io": "^4.4.1", "source-map": "^0.6.1", "tmp": "^0.2.1", "ua-parser-js": "^0.7.30", diff --git a/frontend/package.json b/frontend/package.json index d31fa67..abf2e9f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -32,7 +32,7 @@ "@types/jasmine": "~4.0.2", "@types/node": "^17.0.23", "jasmine-core": "~4.0.0", - "karma": "~6.3.0", + "karma": "~6.3.18", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", "karma-jasmine": "~4.0.0", -- 2.45.2 From 29c6b2bcf7d2f8de1165f024bf38a95ffc8a1ecc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Apr 2022 09:39:22 +0000 Subject: [PATCH 43/66] Bump karma-jasmine from 4.0.1 to 5.0.0 in /frontend Bumps [karma-jasmine](https://github.com/karma-runner/karma-jasmine) from 4.0.1 to 5.0.0. - [Release notes](https://github.com/karma-runner/karma-jasmine/releases) - [Changelog](https://github.com/karma-runner/karma-jasmine/blob/master/CHANGELOG.md) - [Commits](https://github.com/karma-runner/karma-jasmine/compare/v4.0.1...v5.0.0) --- updated-dependencies: - dependency-name: karma-jasmine dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- frontend/package-lock.json | 34 +++++++++++++++++----------------- frontend/package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2cc45ca..42501bb 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -33,7 +33,7 @@ "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", - "karma-jasmine": "~4.0.0", + "karma-jasmine": "~5.0.0", "karma-jasmine-html-reporter": "~1.7.0", "typescript": "~4.5.2" } @@ -7157,18 +7157,18 @@ } }, "node_modules/karma-jasmine": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-4.0.1.tgz", - "integrity": "sha512-h8XDAhTiZjJKzfkoO1laMH+zfNlra+dEQHUAjpn5JV1zCPtOIVWGQjLBrqhnzQa/hrU2XrZwSyBa6XjEBzfXzw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-5.0.0.tgz", + "integrity": "sha512-dsFkCoTwyoNyQnMgegS72wIA/2xPDJG5yzTry0448U6lAY7P60Wgg4UuLlbdLv8YHbimgNpDXjjmfPdc99EDWQ==", "dev": true, "dependencies": { - "jasmine-core": "^3.6.0" + "jasmine-core": "^4.1.0" }, "engines": { - "node": ">= 10" + "node": ">=12" }, "peerDependencies": { - "karma": "*" + "karma": "^6.0.0" } }, "node_modules/karma-jasmine-html-reporter": { @@ -7183,9 +7183,9 @@ } }, "node_modules/karma-jasmine/node_modules/jasmine-core": { - "version": "3.99.1", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.1.tgz", - "integrity": "sha512-Hu1dmuoGcZ7AfyynN3LsfruwMbxMALMka+YtZeGoLuDEySVmVAPaonkNoBRIw/ectu8b9tVQCJNgp4a4knp+tg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.1.0.tgz", + "integrity": "sha512-8E8BiffCL8sBwK1zU9cbavLe8xpJAgOduSJ6N8PJVv8VosQ/nxVTuXj2kUeHxTlZBVvh24G19ga7xdiaxlceKg==", "dev": true }, "node_modules/karma-source-map-support": { @@ -16819,18 +16819,18 @@ } }, "karma-jasmine": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-4.0.1.tgz", - "integrity": "sha512-h8XDAhTiZjJKzfkoO1laMH+zfNlra+dEQHUAjpn5JV1zCPtOIVWGQjLBrqhnzQa/hrU2XrZwSyBa6XjEBzfXzw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-5.0.0.tgz", + "integrity": "sha512-dsFkCoTwyoNyQnMgegS72wIA/2xPDJG5yzTry0448U6lAY7P60Wgg4UuLlbdLv8YHbimgNpDXjjmfPdc99EDWQ==", "dev": true, "requires": { - "jasmine-core": "^3.6.0" + "jasmine-core": "^4.1.0" }, "dependencies": { "jasmine-core": { - "version": "3.99.1", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.99.1.tgz", - "integrity": "sha512-Hu1dmuoGcZ7AfyynN3LsfruwMbxMALMka+YtZeGoLuDEySVmVAPaonkNoBRIw/ectu8b9tVQCJNgp4a4knp+tg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-4.1.0.tgz", + "integrity": "sha512-8E8BiffCL8sBwK1zU9cbavLe8xpJAgOduSJ6N8PJVv8VosQ/nxVTuXj2kUeHxTlZBVvh24G19ga7xdiaxlceKg==", "dev": true } } diff --git a/frontend/package.json b/frontend/package.json index d31fa67..9a3451f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -35,7 +35,7 @@ "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", - "karma-jasmine": "~4.0.0", + "karma-jasmine": "~5.0.0", "karma-jasmine-html-reporter": "~1.7.0", "typescript": "~4.5.2" } -- 2.45.2 From 79cfe4e64e7f0ae142b45a4cd7ebdc6ee804d536 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 09:23:15 +0000 Subject: [PATCH 44/66] Bump @angular/material from 13.3.2 to 13.3.3 in /frontend Bumps [@angular/material](https://github.com/angular/components) from 13.3.2 to 13.3.3. - [Release notes](https://github.com/angular/components/releases) - [Changelog](https://github.com/angular/components/blob/master/CHANGELOG.md) - [Commits](https://github.com/angular/components/compare/13.3.2...13.3.3) --- updated-dependencies: - dependency-name: "@angular/material" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- frontend/package-lock.json | 28 ++++++++++++++-------------- frontend/package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2cc45ca..7c0ff5e 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.2", + "@angular/material": "^13.3.3", "@angular/platform-browser": "~13.2.0", "@angular/platform-browser-dynamic": "~13.2.0", "@angular/router": "~13.2.0", @@ -378,9 +378,9 @@ } }, "node_modules/@angular/cdk": { - "version": "13.3.2", - "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.2.tgz", - "integrity": "sha512-Rb+SvQpjXqa0kedk/6nG57f8dC4uG1q35SR6mt6jCz84ikyS2zhikVbzaxLdG15uDvq1+N5Vx3NTSgH19XUSug==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.3.tgz", + "integrity": "sha512-dzd31mta2VwffxbeO4CelMqb7WswLnkC/r2QZXySnc0CTmj44HqXkqdZuEvVgxaKRVpxsYeuBuhhhy8U00YMOw==", "dependencies": { "tslib": "^2.3.0" }, @@ -670,15 +670,15 @@ } }, "node_modules/@angular/material": { - "version": "13.3.2", - "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.2.tgz", - "integrity": "sha512-agIuNcN1wO05ODEXc0wwrMK2ydnhPGO8tcBBCJXrDgiA/ktwm+WtfOsiZwPoev7aJ8pactVhxT5R0bJ6vW2SmA==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.3.tgz", + "integrity": "sha512-PkZ7VW3/7tqdBHSOOmq7com7Ir147OEe1+kfgF/G3y8WUutI9jY2cHKARXGWB+5WgcqKr7ol43u239UGkPfFHg==", "dependencies": { "tslib": "^2.3.0" }, "peerDependencies": { "@angular/animations": "^13.0.0 || ^14.0.0-0", - "@angular/cdk": "13.3.2", + "@angular/cdk": "13.3.3", "@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", @@ -11789,9 +11789,9 @@ } }, "@angular/cdk": { - "version": "13.3.2", - "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.2.tgz", - "integrity": "sha512-Rb+SvQpjXqa0kedk/6nG57f8dC4uG1q35SR6mt6jCz84ikyS2zhikVbzaxLdG15uDvq1+N5Vx3NTSgH19XUSug==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.3.tgz", + "integrity": "sha512-dzd31mta2VwffxbeO4CelMqb7WswLnkC/r2QZXySnc0CTmj44HqXkqdZuEvVgxaKRVpxsYeuBuhhhy8U00YMOw==", "requires": { "parse5": "^5.0.0", "tslib": "^2.3.0" @@ -11992,9 +11992,9 @@ } }, "@angular/material": { - "version": "13.3.2", - "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.2.tgz", - "integrity": "sha512-agIuNcN1wO05ODEXc0wwrMK2ydnhPGO8tcBBCJXrDgiA/ktwm+WtfOsiZwPoev7aJ8pactVhxT5R0bJ6vW2SmA==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.3.tgz", + "integrity": "sha512-PkZ7VW3/7tqdBHSOOmq7com7Ir147OEe1+kfgF/G3y8WUutI9jY2cHKARXGWB+5WgcqKr7ol43u239UGkPfFHg==", "requires": { "tslib": "^2.3.0" } diff --git a/frontend/package.json b/frontend/package.json index d31fa67..02d8871 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.2", + "@angular/material": "^13.3.3", "@angular/platform-browser": "~13.2.0", "@angular/platform-browser-dynamic": "~13.2.0", "@angular/router": "~13.2.0", -- 2.45.2 From 3992e77d2b3539115a7098c2f92f089d74e792a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 09:24:02 +0000 Subject: [PATCH 45/66] Bump @angular-devkit/build-angular from 13.3.1 to 13.3.3 in /frontend Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 13.3.1 to 13.3.3. - [Release notes](https://github.com/angular/angular-cli/releases) - [Changelog](https://github.com/angular/angular-cli/blob/master/CHANGELOG.md) - [Commits](https://github.com/angular/angular-cli/compare/13.3.1...13.3.3) --- updated-dependencies: - dependency-name: "@angular-devkit/build-angular" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- frontend/package-lock.json | 304 +++++++++++++++++++------------------ frontend/package.json | 2 +- 2 files changed, 155 insertions(+), 151 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2cc45ca..86e73af 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -24,7 +24,7 @@ "zone.js": "~0.11.4" }, "devDependencies": { - "@angular-devkit/build-angular": "~13.3.1", + "@angular-devkit/build-angular": "~13.3.3", "@angular/cli": "~13.3.1", "@angular/compiler-cli": "~13.2.0", "@types/jasmine": "~4.0.2", @@ -51,16 +51,49 @@ "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.1", - "resolved": "https://registry.npmjs.org/@angular-devkit/build-angular/-/build-angular-13.3.1.tgz", - "integrity": "sha512-xxBW4zZZM+lewW0nEpk9SXw6BMYhxe8WI/FjyEroOV8G2IuOrjZ4112QOpk6jCgmPHSOEldbltEdwoVLAnu09Q==", + "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==", "dev": true, "dependencies": { "@ampproject/remapping": "1.1.1", - "@angular-devkit/architect": "0.1303.1", - "@angular-devkit/build-webpack": "0.1303.1", - "@angular-devkit/core": "13.3.1", + "@angular-devkit/architect": "0.1303.3", + "@angular-devkit/build-webpack": "0.1303.3", + "@angular-devkit/core": "13.3.3", "@babel/core": "7.16.12", "@babel/generator": "7.16.8", "@babel/helper-annotate-as-pure": "7.16.7", @@ -71,7 +104,7 @@ "@babel/runtime": "7.16.7", "@babel/template": "7.16.7", "@discoveryjs/json-ext": "0.5.6", - "@ngtools/webpack": "13.3.1", + "@ngtools/webpack": "13.3.3", "ansi-colors": "4.1.1", "babel-loader": "8.2.3", "babel-plugin-istanbul": "6.1.1", @@ -93,7 +126,7 @@ "license-webpack-plugin": "4.0.2", "loader-utils": "3.2.0", "mini-css-extract-plugin": "2.5.3", - "minimatch": "3.0.4", + "minimatch": "3.0.5", "open": "8.4.0", "ora": "5.4.1", "parse5-html-rewriting-stream": "6.0.1", @@ -161,48 +194,6 @@ } } }, - "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", @@ -222,12 +213,12 @@ "dev": true }, "node_modules/@angular-devkit/build-webpack": { - "version": "0.1303.1", - "resolved": "https://registry.npmjs.org/@angular-devkit/build-webpack/-/build-webpack-0.1303.1.tgz", - "integrity": "sha512-KSnR3y2q5hxh7t7ZSi0Emv/Kh9+D105JaEeyEqjqRjLdZSd2m6eAxbSUMNOAsbqnJTMCfzU5AG7jhbujuge0dQ==", + "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==", "dev": true, "dependencies": { - "@angular-devkit/architect": "0.1303.1", + "@angular-devkit/architect": "0.1303.3", "rxjs": "6.6.7" }, "engines": { @@ -240,25 +231,28 @@ "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==", + "node_modules/@angular-devkit/build-webpack/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": { - "@angular-devkit/core": "13.3.1", - "rxjs": "6.6.7" + "tslib": "^1.9.0" }, "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" + "npm": ">=2.0.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==", + "node_modules/@angular-devkit/build-webpack/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", @@ -282,7 +276,7 @@ } } }, - "node_modules/@angular-devkit/build-webpack/node_modules/rxjs": { + "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==", @@ -294,7 +288,7 @@ "npm": ">=2.0.0" } }, - "node_modules/@angular-devkit/build-webpack/node_modules/tslib": { + "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==", @@ -2499,9 +2493,9 @@ } }, "node_modules/@ngtools/webpack": { - "version": "13.3.1", - "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-13.3.1.tgz", - "integrity": "sha512-40iEqAA/l882MPbGuG5EYxzsPWJ37fT4fF22SkPLX2eBgNhJ4K8XMt0gqcFhkHUsSe63frg1qjQ1Pd31msu0bQ==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-13.3.3.tgz", + "integrity": "sha512-O6EzafKfFuvI3Ju941u7ANs0mT7YDdChbVRhVECCPWOTm3Klr73js3bnCDzaJlxZNjzlG/KeUu5ghrhbMrHjSw==", "dev": true, "engines": { "node": "^12.20.0 || ^14.15.0 || >=16.10.0", @@ -3372,9 +3366,9 @@ } }, "node_modules/async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", "dev": true, "dependencies": { "lodash": "^4.17.14" @@ -7768,9 +7762,9 @@ "dev": true }, "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.5.tgz", + "integrity": "sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==", "dev": true, "dependencies": { "brace-expansion": "^1.1.7" @@ -9660,9 +9654,9 @@ "dev": true }, "node_modules/regexp.prototype.flags": { - "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==", + "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==", "dev": true, "dependencies": { "call-bind": "^1.0.2", @@ -11569,16 +11563,43 @@ "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.1", - "resolved": "https://registry.npmjs.org/@angular-devkit/build-angular/-/build-angular-13.3.1.tgz", - "integrity": "sha512-xxBW4zZZM+lewW0nEpk9SXw6BMYhxe8WI/FjyEroOV8G2IuOrjZ4112QOpk6jCgmPHSOEldbltEdwoVLAnu09Q==", + "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==", "dev": true, "requires": { "@ampproject/remapping": "1.1.1", - "@angular-devkit/architect": "0.1303.1", - "@angular-devkit/build-webpack": "0.1303.1", - "@angular-devkit/core": "13.3.1", + "@angular-devkit/architect": "0.1303.3", + "@angular-devkit/build-webpack": "0.1303.3", + "@angular-devkit/core": "13.3.3", "@babel/core": "7.16.12", "@babel/generator": "7.16.8", "@babel/helper-annotate-as-pure": "7.16.7", @@ -11589,7 +11610,7 @@ "@babel/runtime": "7.16.7", "@babel/template": "7.16.7", "@discoveryjs/json-ext": "0.5.6", - "@ngtools/webpack": "13.3.1", + "@ngtools/webpack": "13.3.3", "ansi-colors": "4.1.1", "babel-loader": "8.2.3", "babel-plugin-istanbul": "6.1.1", @@ -11612,7 +11633,7 @@ "license-webpack-plugin": "4.0.2", "loader-utils": "3.2.0", "mini-css-extract-plugin": "2.5.3", - "minimatch": "3.0.4", + "minimatch": "3.0.5", "open": "8.4.0", "ora": "5.4.1", "parse5-html-rewriting-stream": "6.0.1", @@ -11642,30 +11663,6 @@ "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", @@ -11686,39 +11683,46 @@ } }, "@angular-devkit/build-webpack": { - "version": "0.1303.1", - "resolved": "https://registry.npmjs.org/@angular-devkit/build-webpack/-/build-webpack-0.1303.1.tgz", - "integrity": "sha512-KSnR3y2q5hxh7t7ZSi0Emv/Kh9+D105JaEeyEqjqRjLdZSd2m6eAxbSUMNOAsbqnJTMCfzU5AG7jhbujuge0dQ==", + "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==", "dev": true, "requires": { - "@angular-devkit/architect": "0.1303.1", + "@angular-devkit/architect": "0.1303.3", "rxjs": "6.6.7" }, "dependencies": { - "@angular-devkit/architect": { - "version": "0.1303.1", - "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1303.1.tgz", - "integrity": "sha512-ppaLzNZPrqrI96ddgm1RuEALVpWZsmHbIPLDd0GBwhF6aOkwF0LpZHd5XyS4ktGFZPReiFIjWSVtqV5vaBdRsw==", + "rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", "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" + "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/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", @@ -13266,9 +13270,9 @@ } }, "@ngtools/webpack": { - "version": "13.3.1", - "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-13.3.1.tgz", - "integrity": "sha512-40iEqAA/l882MPbGuG5EYxzsPWJ37fT4fF22SkPLX2eBgNhJ4K8XMt0gqcFhkHUsSe63frg1qjQ1Pd31msu0bQ==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-13.3.3.tgz", + "integrity": "sha512-O6EzafKfFuvI3Ju941u7ANs0mT7YDdChbVRhVECCPWOTm3Klr73js3bnCDzaJlxZNjzlG/KeUu5ghrhbMrHjSw==", "dev": true, "requires": {} }, @@ -14007,9 +14011,9 @@ "dev": true }, "async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", "dev": true, "requires": { "lodash": "^4.17.14" @@ -17218,9 +17222,9 @@ "dev": true }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.5.tgz", + "integrity": "sha512-tUpxzX0VAzJHjLu0xUfFv1gwVp9ba3IOuRAVH2EGuRW8a5emA2FlACLqiT/lDVtS1W+TGNwqz3sWaNyLgDJWuw==", "dev": true, "requires": { "brace-expansion": "^1.1.7" @@ -18609,9 +18613,9 @@ "dev": true }, "regexp.prototype.flags": { - "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==", + "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==", "dev": true, "requires": { "call-bind": "^1.0.2", diff --git a/frontend/package.json b/frontend/package.json index d31fa67..b3ff57c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -26,7 +26,7 @@ "zone.js": "~0.11.4" }, "devDependencies": { - "@angular-devkit/build-angular": "~13.3.1", + "@angular-devkit/build-angular": "~13.3.3", "@angular/cli": "~13.3.1", "@angular/compiler-cli": "~13.2.0", "@types/jasmine": "~4.0.2", -- 2.45.2 From acdd46780c27991247dc55a391bcf1e73c35fefa Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Sun, 17 Apr 2022 10:49:42 +0200 Subject: [PATCH 46/66] added small error handling --- telegram_bot/bot_scheduler.py | 37 +++++++++++++++++++++++++++++++ telegram_bot/news/news_fetcher.py | 10 ++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/telegram_bot/bot_scheduler.py b/telegram_bot/bot_scheduler.py index e69de29..8fcef6f 100644 --- a/telegram_bot/bot_scheduler.py +++ 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/news/news_fetcher.py b/telegram_bot/news/news_fetcher.py index 2b79721..96f50ff 100644 --- a/telegram_bot/news/news_fetcher.py +++ b/telegram_bot/news/news_fetcher.py @@ -20,9 +20,13 @@ 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"): -- 2.45.2 From 5078660ce19bbb15f83c9b4dec8442b257aee96c Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Sun, 17 Apr 2022 11:21:49 +0200 Subject: [PATCH 47/66] fixed dict errors --- telegram_bot/api_handling/api_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index b1ce853..fa4a37e 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -260,7 +260,7 @@ class API_Handler: req = s.get(self.db_adress + "/transactions", headers=headers) if req.status_code == 200: - transactions_dict = dict(req.json()["data"]) + transactions_dict = req.json()["data"] return transactions_dict else: return self.get_user_transactions(user_id, max_retries-1) @@ -303,7 +303,7 @@ class API_Handler: headers = {'Authorization': 'Bearer ' + self.token + ":" + str(user_id)} req = s.get(self.db_adress + "/portfolio", headers=headers) if req.status_code == 200: - portfolio_dict = dict(req.json()["data"]) + portfolio_dict = req.json()["data"] return portfolio_dict else: return self.get_user_portfolio(user_id, max_retries-1) -- 2.45.2 From 543c51397e64fd1808e2e7b69d934fab8dfae10d Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Sun, 17 Apr 2022 11:57:28 +0200 Subject: [PATCH 48/66] added transaction and portfolio commands --- telegram_bot/api_handling/api_handler.py | 4 ++ telegram_bot/bot.py | 64 +++++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index fa4a37e..c06e6ee 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -33,6 +33,10 @@ class API_Handler: get_user_transactions(user_id): gets the transactions of the user set_transaction(user_id, transaction): sets the transaction of the user delete_transaction(user_id, transaction): deletes the transaction of the user + 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 """ diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 83582ba..b1d985b 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -14,14 +14,13 @@ __license__ = "None" # API Documentation https://core.telegram.org/bots/api # Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started -from ast import keyword 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 @@ -380,6 +379,67 @@ def send_keywords(message): bot.send_message(chat_id=user_id, text=f'Your keywords are: _{keywords_str}_', parse_mode="MARKDOWN") +@bot.message_handler(commands=['portfolio']) +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 too 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: + portfolio_str = ', '.join(portfolio) # tbd: format portfolio + bot.send_message(chat_id=user_id, text=f'Your portfolio is: _{portfolio_str}_', parse_mode="MARKDOWN") + + +@bot.message_handler(commands=['newtransaction']) +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]+,[0-9]+[.[0-9]+]?,[0-9]+[.[0-9]+]?", message.text): + bot.send_message(chat_id=user_id, text='Invalid format. Try again with /newtransaction.') + return + + transaction_data = str(message.text).split(',') + symbol = str(transaction_data[0]) + amount = float(transaction_data[1]) + price = float(transaction_data[2]) + time = dt.datetime.now() + + status = api_handler.set_transaction(user_id, amount, price, symbol, 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(func=lambda message: True) # Returning that command is unknown for any other statement def echo_all(message): -- 2.45.2 From b06b02432680a642cc06016a6ac3ff11f2cdd753 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Sun, 17 Apr 2022 12:20:53 +0200 Subject: [PATCH 49/66] bot new commands and funcs + api updates --- telegram_bot/api_handling/api_handler.py | 6 ++- telegram_bot/bot.py | 49 ++++++++++++++++++++++++ telegram_bot/requirements.txt | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index c06e6ee..c5bc997 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -12,6 +12,7 @@ __license__ = "None" import sys import os import requests as r +from croniter import croniter @@ -32,7 +33,6 @@ class API_Handler: delete_share(user_id, symbol): deletes the share of the user get_user_transactions(user_id): gets the transactions of the user set_transaction(user_id, transaction): sets the transaction of the user - delete_transaction(user_id, transaction): deletes the transaction of the user 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 @@ -322,6 +322,10 @@ class API_Handler: 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) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index b1d985b..e2cb748 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -437,7 +437,56 @@ def set_new_transaction_step(message): bot.send_message(chat_id=user_id, text=f'Failed adding transaction. (statuscode {status})') +@bot.message_handler(commands=['interval']) +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) + interval = api_handler.get_user(user_id)['cron'] + if interval == None: + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info and set an interval with /setinterval') + return + else: + interval = str(interval) + formatted_interval = str(interval).replace(' ', '_') + bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})', parse_mode="MARKDOWN") + + +@bot.message_handler(commands=['setinterval']) +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 (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: + bot.send_message(chat_id=user_id, text='Invalid interval. Try again with /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 diff --git a/telegram_bot/requirements.txt b/telegram_bot/requirements.txt index 2e8462d..146877f 100644 --- a/telegram_bot/requirements.txt +++ b/telegram_bot/requirements.txt @@ -5,3 +5,4 @@ newsapi-python~=0.2.6 python-dotenv~=0.20.0 requests~=2.27.1 APScheduler~=3.9.1 +cronitor~=1.3.4 -- 2.45.2 From caa90a577f4b339a0f97af74540f4b3cd3704a91 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Sun, 17 Apr 2022 12:35:59 +0200 Subject: [PATCH 50/66] testing --- telegram_bot/bot.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index e2cb748..7b5e38d 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -115,7 +115,7 @@ def send_welcome(message): :rtype: none """ - bot.reply_to(message, "/id or /auth get your user id\n/update get updates on your shares.\n/users see all users.\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\n_For further details see https://gruppe1.testsites.info _", parse_mode='MARKDOWN') + bot.reply_to(message, "/id or /auth get your user id\n/update get updates on your shares.\n/users see all users.\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']) @@ -379,7 +379,7 @@ def send_keywords(message): bot.send_message(chat_id=user_id, text=f'Your keywords are: _{keywords_str}_', parse_mode="MARKDOWN") -@bot.message_handler(commands=['portfolio']) +@bot.message_handler(commands=['portfolio']) #tbd def send_portfolio(message): """ Send portfolio of user :type message: message object bot @@ -402,7 +402,7 @@ def send_portfolio(message): bot.send_message(chat_id=user_id, text=f'Your portfolio is: _{portfolio_str}_', parse_mode="MARKDOWN") -@bot.message_handler(commands=['newtransaction']) +@bot.message_handler(commands=['newtransaction']) #tbd def set_new_transaction(message): """ Set new transaction for user :type message: message object bot @@ -437,7 +437,7 @@ def set_new_transaction_step(message): bot.send_message(chat_id=user_id, text=f'Failed adding transaction. (statuscode {status})') -@bot.message_handler(commands=['interval']) +@bot.message_handler(commands=['interval']) #tbd def send_interval(message): """ send interval for user :type message: message object bot @@ -448,12 +448,12 @@ def send_interval(message): :rtype: none """ user_id = int(message.from_user.id) - interval = api_handler.get_user(user_id)['cron'] + interval = api_handler.get_user(user_id) if interval == None: bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info and set an interval with /setinterval') return else: - interval = str(interval) + interval = str(interval['cron']) formatted_interval = str(interval).replace(' ', '_') bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})', parse_mode="MARKDOWN") @@ -469,7 +469,7 @@ def set_new_interval(message): :rtype: none """ user_id = int(message.from_user.id) - bot.send_message(chat_id=user_id, text='Type interval in cron format (https://crontab.guru/):') + 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): @@ -482,7 +482,7 @@ def set_new_interval_step(message): bot.send_message(chat_id=user_id, text='Interval succesfully set.') return - if status == -1: + if status == -1: # only -1 when interval is invalid bot.send_message(chat_id=user_id, text='Invalid interval. Try again with /setinterval.') return else: -- 2.45.2 From 26b41f2c94576c38980346008996c4e3786d1027 Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Sun, 17 Apr 2022 13:07:57 +0200 Subject: [PATCH 51/66] fixing and debugging --- telegram_bot/bot.py | 60 +++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 7b5e38d..c3ab17e 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -115,7 +115,7 @@ def send_welcome(message): :rtype: none """ - bot.reply_to(message, "/id or /auth get your user id\n/update get updates on your shares.\n/users see all users.\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.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']) @@ -140,7 +140,26 @@ 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']) +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' + :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']) # /auth or /id -> Authentication with user_id over web tool def send_id(message): @@ -248,7 +267,7 @@ def send_all_news(message): 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 too connect your telegram id (/id) on https://gruppe1.testsites.info') + 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: @@ -286,7 +305,7 @@ def send_news(message): 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 too connect your telegram id (/id) on https://gruppe1.testsites.info') + 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: @@ -369,7 +388,7 @@ def send_keywords(message): 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 too connect your telegram id (/id) on https://gruppe1.testsites.info') + 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') @@ -392,17 +411,18 @@ def send_portfolio(message): 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 too connect your telegram id (/id) on https://gruppe1.testsites.info') + 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: - portfolio_str = ', '.join(portfolio) # tbd: format portfolio - bot.send_message(chat_id=user_id, text=f'Your portfolio is: _{portfolio_str}_', parse_mode="MARKDOWN") + # tbd: format portfolio + + bot.send_message(chat_id=user_id, text=f'Your portfolio is: _{str(portfolio)}_', parse_mode="MARKDOWN") -@bot.message_handler(commands=['newtransaction']) #tbd +@bot.message_handler(commands=['newtransaction']) #tbd not working rn def set_new_transaction(message): """ Set new transaction for user :type message: message object bot @@ -413,14 +433,14 @@ def set_new_transaction(message): :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.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]+,[0-9]+[.[0-9]+]?,[0-9]+[.[0-9]+]?", message.text): - bot.send_message(chat_id=user_id, text='Invalid format. Try again with /newtransaction.') + if not re.match(r"[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. AAPL,53.2,120.4).\n Try again with /newtransaction.') return transaction_data = str(message.text).split(',') @@ -428,7 +448,8 @@ def set_new_transaction_step(message): amount = float(transaction_data[1]) price = float(transaction_data[2]) time = dt.datetime.now() - + #print("\n\n\n\n\n") + #print(f"{symbol},{amount},{price},{time}") status = api_handler.set_transaction(user_id, amount, price, symbol, time) if status == 200: @@ -448,14 +469,17 @@ def send_interval(message): :rtype: none """ user_id = int(message.from_user.id) - interval = api_handler.get_user(user_id) - if interval == None: - bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure too connect your telegram id (/id) on https://gruppe1.testsites.info and set an interval with /setinterval') + 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(interval['cron']) + 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})', parse_mode="MARKDOWN") + bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})') @bot.message_handler(commands=['setinterval']) @@ -483,7 +507,7 @@ def set_new_interval_step(message): return if status == -1: # only -1 when interval is invalid - bot.send_message(chat_id=user_id, text='Invalid interval. Try again with /setinterval.') + 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})') -- 2.45.2 From 1803bba222b56ec7e196a5721589b9d91f3bfdb7 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Sun, 17 Apr 2022 13:26:12 +0200 Subject: [PATCH 52/66] Not working fully yet, still problems with scheduler, might try other module later --- telegram_bot/bot_updates.py | 98 ++++++++++++++++------------------- telegram_bot/requirements.txt | 3 +- telegram_bot/testfile.py | 41 +++++++++++++++ 3 files changed, 87 insertions(+), 55 deletions(-) create mode 100644 telegram_bot/testfile.py diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index 821de90..7ed1bf2 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -6,12 +6,16 @@ __date__ = "05.04.2022" __version__ = "0.0.1" __license__ = "None" +from calendar import month 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.blocking import BlockingScheduler +from api_handling.api_handler import API_Handler + ''' * * * * * code @@ -25,7 +29,6 @@ from multiprocessing import Process example 0 8 * * * -> daily update at 8am ''' - user_ids = [] user_crontab = [] @@ -37,20 +40,24 @@ def main_loop(): """ current_time_datetime = datetime.datetime.now() + my_handler = API_Handler("https://gruppe1.testsites.info/api", "bot@example.com", "bot") print(time.ctime()) # Debug - p1 = Process(target= update_crontab, args=(current_time_datetime, )) + """p1 = Process(target= update_crontab, args=(current_time_datetime, my_handler )) p1.start() - p3 = Process(target= update_based_on_crontab, args=(current_time_datetime, ) ) + time.sleep(5) + p3 = Process(target= update_based_on_crontab, args=() ) p3.daemon = True p3.start() p1.join() p3.terminate() - p1.terminate() + p1.terminate()""" + + update_crontab(current_time_datetime, my_handler) -def update_crontab(pCurrent_Time): +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 @@ -60,14 +67,23 @@ def update_crontab(pCurrent_Time): :rtype: none """ - # Update user info now + global user_crontab + global user_ids - print('in update_crontab') + p_my_handler.set_cron_interval(user_id = 1770205310, cron_interval = "50 11 * * *") - user_ids.clear() # Example for me (Florian Kellermann) - user_crontab.clear() - user_ids.append(1770205310) - user_crontab.append("0 8 * * *") + 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() while True: time_difference = datetime.datetime.now() - pCurrent_Time @@ -76,52 +92,26 @@ def update_crontab(pCurrent_Time): break -def update_based_on_crontab(pCurrent_Time): - current_time_ctime = time.ctime() - ctime_split = str(current_time_ctime).split(' ') +def update_based_on_crontab(): - if ctime_split[0] == "Mon": - current_day = 0 - elif ctime_split[0] == "Tue": - current_day = 1 - elif ctime_split[0] == "Wed": - current_day = 3 - elif ctime_split[0] == "Thu": - current_day = 4 - elif ctime_split[0] == "Fri": - current_day = 5 - elif ctime_split[0] == "Sat": - current_day = 6 - elif ctime_split[0] == "Sun": - current_day = 7 - else: - print('Error with time code') - sys.exit(-1) + my_scheduler = BlockingScheduler() - for i in range(len(user_crontab)): - day_match = False - hour_match = False - - user_crontab[i] = user_crontab.strip() - - contrab_split = str(user_crontab[i]).split(' ') - - if ',' in contrab_split[4]: # if the user wants to be alerted on multiple specific days - contrab_days = contrab_split[4].split(',') - else: - contrab_days = contrab_days - - for element in contrab_days: - if str(current_day) == element or element=='*': - hour_match = True - - - - - if hour_match and day_match: - send_to_user("regular update", pUser_id=user_crontab[i]) + print("update based on cron") + + print(len(user_ids)) #Debug + + for i in range(len(user_ids)): + print("in loop") + cron_split = 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=(user_ids[i], )) + + my_scheduler.start() + + print("update based on crontab") - +def update_for_user(p_user_id): + print("updating for {p_user_id}") def send_to_user(pText, pUser_id = 1770205310): diff --git a/telegram_bot/requirements.txt b/telegram_bot/requirements.txt index 146877f..6620615 100644 --- a/telegram_bot/requirements.txt +++ b/telegram_bot/requirements.txt @@ -5,4 +5,5 @@ newsapi-python~=0.2.6 python-dotenv~=0.20.0 requests~=2.27.1 APScheduler~=3.9.1 -cronitor~=1.3.4 +croniter~=1.3.4 +tzlocal==2.1 diff --git a/telegram_bot/testfile.py b/telegram_bot/testfile.py new file mode 100644 index 0000000..4369096 --- /dev/null +++ b/telegram_bot/testfile.py @@ -0,0 +1,41 @@ +from multiprocessing import Process +import time + +class Array_Class: + def __init__(self): + self.array = [] + + def SetArray(self, parray): + array = parray + + def GetArray(self): + return self.array + +my_array = Array_Class() + + +def update_crontab(): + global my_array + array = [] + time.sleep(5) + array.append(1) + my_array.SetArray(array) + print("set done") + +def update_based_on_crontab(): + time.sleep(5) + print(my_array.GetArray()) + + +"""update_crontab() +update_based_on_crontab()""" + +if __name__ == "__main__": + p1 = Process(target= update_crontab, args=()) + p1.start() + p3 = Process(target= update_based_on_crontab, args=() ) + p3.daemon = True + p3.start() + p1.join() + p3.terminate() + p1.terminate() \ No newline at end of file -- 2.45.2 From 689a8cb1fcf98cfc9381b8eba4cddd7b3a095ad7 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Sun, 17 Apr 2022 13:27:25 +0200 Subject: [PATCH 53/66] Removed testfile --- telegram_bot/testfile.py | 41 ---------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 telegram_bot/testfile.py diff --git a/telegram_bot/testfile.py b/telegram_bot/testfile.py deleted file mode 100644 index 4369096..0000000 --- a/telegram_bot/testfile.py +++ /dev/null @@ -1,41 +0,0 @@ -from multiprocessing import Process -import time - -class Array_Class: - def __init__(self): - self.array = [] - - def SetArray(self, parray): - array = parray - - def GetArray(self): - return self.array - -my_array = Array_Class() - - -def update_crontab(): - global my_array - array = [] - time.sleep(5) - array.append(1) - my_array.SetArray(array) - print("set done") - -def update_based_on_crontab(): - time.sleep(5) - print(my_array.GetArray()) - - -"""update_crontab() -update_based_on_crontab()""" - -if __name__ == "__main__": - p1 = Process(target= update_crontab, args=()) - p1.start() - p3 = Process(target= update_based_on_crontab, args=() ) - p3.daemon = True - p3.start() - p1.join() - p3.terminate() - p1.terminate() \ No newline at end of file -- 2.45.2 From 44c57aa881856030e81a6ff4f7cea809a523cef6 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Mon, 18 Apr 2022 17:11:02 +0200 Subject: [PATCH 54/66] Almost working, having some troubles with the blockers still --- telegram_bot/bot_updates.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index 7ed1bf2..ff0bf40 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -70,7 +70,7 @@ def update_crontab(pCurrent_Time, p_my_handler): global user_crontab global user_ids - p_my_handler.set_cron_interval(user_id = 1770205310, cron_interval = "50 11 * * *") + p_my_handler.set_cron_interval(user_id = 1770205310, cron_interval = "8 17 * * *") all_users = p_my_handler.get_all_users() @@ -83,16 +83,30 @@ def update_crontab(pCurrent_Time, p_my_handler): user_crontab.append(str(element["cron"])) print(user_ids) - update_based_on_crontab() + update_based_on_crontab(user_ids, user_crontab) + + p1 = Process(target= sleeping_time, args=(pCurrent_Time, )) + p1.start() + p3 = Process(target= update_based_on_crontab, args=(user_ids, user_crontab ) ) + p3.daemon = True + p3.start() + p1.join() + p3.terminate() + p1.terminate() + update_crontab(datetime.datetime.now(), p_my_handler) + + + +def sleeping_time(pCurrent_Time): while True: time_difference = datetime.datetime.now() - pCurrent_Time - if float(str(time_difference).split(':')[0]) >=1: + print(time_difference) + if float(str(time_difference).split(':')[1]) >=1: # every minute (0:00:03.646070) -> example time code update_crontab(datetime.datetime.now()) break - -def update_based_on_crontab(): +def update_based_on_crontab(p_user_ids, p_user_crontab): my_scheduler = BlockingScheduler() @@ -100,15 +114,13 @@ def update_based_on_crontab(): print(len(user_ids)) #Debug - for i in range(len(user_ids)): + for i in range(len(p_user_ids)): print("in loop") - cron_split = user_crontab[i].split(" ") + 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=(user_ids[i], )) + 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], )) my_scheduler.start() - - print("update based on crontab") def update_for_user(p_user_id): print("updating for {p_user_id}") @@ -130,6 +142,7 @@ def send_to_user(pText, pUser_id = 1770205310): if __name__ == "__main__": + print('This script shall not be run directly. Starting main_loop for debugging purposes.') try: main_loop() -- 2.45.2 From 788f63213851ebabdf3373ca6a38114146a0d48c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 17:49:33 +0000 Subject: [PATCH 55/66] Bump @types/node from 17.0.23 to 17.0.25 in /frontend Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 17.0.23 to 17.0.25. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- frontend/package-lock.json | 16 ++++++++-------- frontend/package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index e2c0f7f..4dfdd24 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -28,9 +28,9 @@ "@angular/cli": "~13.3.1", "@angular/compiler-cli": "~13.2.0", "@types/jasmine": "~4.0.2", - "@types/node": "^17.0.23", - "karma": "~6.3.18", + "@types/node": "^17.0.25", "jasmine-core": "~4.1.0", + "karma": "~6.3.18", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", "karma-jasmine": "~5.0.0", @@ -2868,9 +2868,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "17.0.23", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.23.tgz", - "integrity": "sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw==", + "version": "17.0.25", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.25.tgz", + "integrity": "sha512-wANk6fBrUwdpY4isjWrKTufkrXdu1D2YHCot2fD/DfWxF5sMrVSA+KN7ydckvaTCh0HiqX9IVl0L5/ZoXg5M7w==", "dev": true }, "node_modules/@types/parse-json": { @@ -13575,9 +13575,9 @@ "dev": true }, "@types/node": { - "version": "17.0.23", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.23.tgz", - "integrity": "sha512-UxDxWn7dl97rKVeVS61vErvw086aCYhDLyvRQZ5Rk65rZKepaFdm53GeqXaKBuOhED4e9uWq34IC3TdSdJJ2Gw==", + "version": "17.0.25", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.25.tgz", + "integrity": "sha512-wANk6fBrUwdpY4isjWrKTufkrXdu1D2YHCot2fD/DfWxF5sMrVSA+KN7ydckvaTCh0HiqX9IVl0L5/ZoXg5M7w==", "dev": true }, "@types/parse-json": { diff --git a/frontend/package.json b/frontend/package.json index a1bc013..26e7ac5 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -30,7 +30,7 @@ "@angular/cli": "~13.3.1", "@angular/compiler-cli": "~13.2.0", "@types/jasmine": "~4.0.2", - "@types/node": "^17.0.23", + "@types/node": "^17.0.25", "karma": "~6.3.18", "jasmine-core": "~4.1.0", "karma-chrome-launcher": "~3.1.0", -- 2.45.2 From cd3b3285d117604777991fe4873c158b59e13700 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 17:50:56 +0000 Subject: [PATCH 56/66] Bump @angular/cli from 13.3.1 to 13.3.3 in /frontend Bumps [@angular/cli](https://github.com/angular/angular-cli) from 13.3.1 to 13.3.3. - [Release notes](https://github.com/angular/angular-cli/releases) - [Changelog](https://github.com/angular/angular-cli/blob/master/CHANGELOG.md) - [Commits](https://github.com/angular/angular-cli/compare/13.3.1...13.3.3) --- updated-dependencies: - dependency-name: "@angular/cli" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- frontend/package-lock.json | 404 +++++++++++++++---------------------- frontend/package.json | 2 +- 2 files changed, 162 insertions(+), 244 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 194d13f..5c4ab35 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -25,7 +25,7 @@ }, "devDependencies": { "@angular-devkit/build-angular": "~13.3.1", - "@angular/cli": "~13.3.1", + "@angular/cli": "~13.3.3", "@angular/compiler-cli": "~13.2.0", "@types/jasmine": "~4.0.2", "@types/node": "^17.0.25", @@ -51,6 +51,39 @@ "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.1", "resolved": "https://registry.npmjs.org/@angular-devkit/build-angular/-/build-angular-13.3.1.tgz", @@ -300,28 +333,10 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, - "node_modules/@angular-devkit/schematics": { - "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.1", - "jsonc-parser": "3.0.0", - "magic-string": "0.25.7", - "ora": "5.4.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/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==", + "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", @@ -345,6 +360,42 @@ } } }, + "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==", + "dev": true, + "dependencies": { + "@angular-devkit/core": "13.3.3", + "jsonc-parser": "3.0.0", + "magic-string": "0.25.7", + "ora": "5.4.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/schematics/node_modules/rxjs": { "version": "6.6.7", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", @@ -400,16 +451,16 @@ "optional": true }, "node_modules/@angular/cli": { - "version": "13.3.1", - "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.1.tgz", - "integrity": "sha512-0uwU8v3V/2s95X4cZT582J6upReT/ZNw/VAf4p4q51JN+BBvdCEb251xTF+TcOojyToFyJYvg8T28XSrsNsmTQ==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.3.tgz", + "integrity": "sha512-a+nnzFP1FfnypXpAhrHbIBaJcxzegWLZUvVzJQwt6P2z60IoHdvTVmyNbY89qI0LE1SrAokEUO1zW3Yjmu7fUw==", "dev": true, "hasInstallScript": true, "dependencies": { - "@angular-devkit/architect": "0.1303.1", - "@angular-devkit/core": "13.3.1", - "@angular-devkit/schematics": "13.3.1", - "@schematics/angular": "13.3.1", + "@angular-devkit/architect": "0.1303.3", + "@angular-devkit/core": "13.3.3", + "@angular-devkit/schematics": "13.3.3", + "@schematics/angular": "13.3.3", "@yarnpkg/lockfile": "1.1.0", "ansi-colors": "4.1.1", "debug": "4.3.3", @@ -435,66 +486,6 @@ "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", @@ -2657,13 +2648,13 @@ } }, "node_modules/@schematics/angular": { - "version": "13.3.1", - "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.3.1.tgz", - "integrity": "sha512-+lrK/d1eJsAK6d6E9TDeg3Vc71bDy1KsE8M+lEINdX9Wax22mAz4pw20X9RSCw5RHgn+XcNUuMsgRJAwVhDNpg==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.3.3.tgz", + "integrity": "sha512-kX5ghVCmWHcMN+g0pUaFuIJzwrXsVnK4bfid8DckU4EEtfFSv3UA5I1QNJRgpCPxTPhNEAk+3ePN8nzDSjdU+w==", "dev": true, "dependencies": { - "@angular-devkit/core": "13.3.1", - "@angular-devkit/schematics": "13.3.1", + "@angular-devkit/core": "13.3.3", + "@angular-devkit/schematics": "13.3.3", "jsonc-parser": "3.0.0" }, "engines": { @@ -2672,51 +2663,6 @@ "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", @@ -11569,6 +11515,33 @@ "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.1", "resolved": "https://registry.npmjs.org/@angular-devkit/build-angular/-/build-angular-13.3.1.tgz", @@ -11736,33 +11709,50 @@ } } }, - "@angular-devkit/schematics": { - "version": "13.3.1", - "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-13.3.1.tgz", - "integrity": "sha512-DxXMjlq/sALcHuONZRMTBX5k30XPfN4b6Ue4k7Xl8JKZqyHhEzfXaZzgD9u2cwb7wybKEeF/BZ5eJd8JG525og==", + "@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": { - "@angular-devkit/core": "13.3.1", + "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==", + "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/schematics": { + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-13.3.3.tgz", + "integrity": "sha512-S8UNlw6IoR/kxBYbiwesuA7oJGSnFkD6bJwVLhpHdT6Sqrz2/IrjHcNgTJRAvhsOKIbfDtMtXRzl/PUdWEfgyw==", + "dev": true, + "requires": { + "@angular-devkit/core": "13.3.3", "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", @@ -11806,15 +11796,15 @@ } }, "@angular/cli": { - "version": "13.3.1", - "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.1.tgz", - "integrity": "sha512-0uwU8v3V/2s95X4cZT582J6upReT/ZNw/VAf4p4q51JN+BBvdCEb251xTF+TcOojyToFyJYvg8T28XSrsNsmTQ==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.3.tgz", + "integrity": "sha512-a+nnzFP1FfnypXpAhrHbIBaJcxzegWLZUvVzJQwt6P2z60IoHdvTVmyNbY89qI0LE1SrAokEUO1zW3Yjmu7fUw==", "dev": true, "requires": { - "@angular-devkit/architect": "0.1303.1", - "@angular-devkit/core": "13.3.1", - "@angular-devkit/schematics": "13.3.1", - "@schematics/angular": "13.3.1", + "@angular-devkit/architect": "0.1303.3", + "@angular-devkit/core": "13.3.3", + "@angular-devkit/schematics": "13.3.3", + "@schematics/angular": "13.3.3", "@yarnpkg/lockfile": "1.1.0", "ansi-colors": "4.1.1", "debug": "4.3.3", @@ -11830,47 +11820,6 @@ "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": { @@ -13389,45 +13338,14 @@ "peer": true }, "@schematics/angular": { - "version": "13.3.1", - "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.3.1.tgz", - "integrity": "sha512-+lrK/d1eJsAK6d6E9TDeg3Vc71bDy1KsE8M+lEINdX9Wax22mAz4pw20X9RSCw5RHgn+XcNUuMsgRJAwVhDNpg==", + "version": "13.3.3", + "resolved": "https://registry.npmjs.org/@schematics/angular/-/angular-13.3.3.tgz", + "integrity": "sha512-kX5ghVCmWHcMN+g0pUaFuIJzwrXsVnK4bfid8DckU4EEtfFSv3UA5I1QNJRgpCPxTPhNEAk+3ePN8nzDSjdU+w==", "dev": true, "requires": { - "@angular-devkit/core": "13.3.1", - "@angular-devkit/schematics": "13.3.1", + "@angular-devkit/core": "13.3.3", + "@angular-devkit/schematics": "13.3.3", "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": { diff --git a/frontend/package.json b/frontend/package.json index ce9abe3..0c9ad76 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -27,7 +27,7 @@ }, "devDependencies": { "@angular-devkit/build-angular": "~13.3.1", - "@angular/cli": "~13.3.1", + "@angular/cli": "~13.3.3", "@angular/compiler-cli": "~13.2.0", "@types/jasmine": "~4.0.2", "@types/node": "^17.0.25", -- 2.45.2 From 42a2a4e9bd600def828e7bd17c45bf61077104ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 17:52:42 +0000 Subject: [PATCH 57/66] Bump @types/jasmine from 4.0.2 to 4.0.3 in /frontend Bumps [@types/jasmine](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jasmine) from 4.0.2 to 4.0.3. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jasmine) --- updated-dependencies: - dependency-name: "@types/jasmine" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- frontend/package-lock.json | 14 +++++++------- frontend/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 5c4ab35..f47f376 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -27,7 +27,7 @@ "@angular-devkit/build-angular": "~13.3.1", "@angular/cli": "~13.3.3", "@angular/compiler-cli": "~13.2.0", - "@types/jasmine": "~4.0.2", + "@types/jasmine": "~4.0.3", "@types/node": "^17.0.25", "jasmine-core": "~4.1.0", "karma": "~6.3.18", @@ -2796,9 +2796,9 @@ } }, "node_modules/@types/jasmine": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.0.2.tgz", - "integrity": "sha512-mSPIWhDyQ4nzYdR6Ixy15VhVKMVw93mSUlQxxpVb4S9Hj90lBvg+7kkBw23uYcv8CESPPXit+u3cARYcPeC8Jg==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.0.3.tgz", + "integrity": "sha512-Opp1LvvEuZdk8fSSvchK2mZwhVrsNT0JgJE9Di6MjnaIpmEXM8TLCPPrVtNTYh8+5MPdY8j9bAHMu2SSfwpZJg==", "dev": true }, "node_modules/@types/json-schema": { @@ -13475,9 +13475,9 @@ } }, "@types/jasmine": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.0.2.tgz", - "integrity": "sha512-mSPIWhDyQ4nzYdR6Ixy15VhVKMVw93mSUlQxxpVb4S9Hj90lBvg+7kkBw23uYcv8CESPPXit+u3cARYcPeC8Jg==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-4.0.3.tgz", + "integrity": "sha512-Opp1LvvEuZdk8fSSvchK2mZwhVrsNT0JgJE9Di6MjnaIpmEXM8TLCPPrVtNTYh8+5MPdY8j9bAHMu2SSfwpZJg==", "dev": true }, "@types/json-schema": { diff --git a/frontend/package.json b/frontend/package.json index 0c9ad76..efbb8f8 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -29,7 +29,7 @@ "@angular-devkit/build-angular": "~13.3.1", "@angular/cli": "~13.3.3", "@angular/compiler-cli": "~13.2.0", - "@types/jasmine": "~4.0.2", + "@types/jasmine": "~4.0.3", "@types/node": "^17.0.25", "karma": "~6.3.18", "jasmine-core": "~4.1.0", -- 2.45.2 From 6db3a7ce32e1c65d5ff73bc8d292c23d115572a6 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Mon, 18 Apr 2022 23:32:19 +0200 Subject: [PATCH 58/66] Update message working, regularity still needs implementation --- telegram_bot/bot_updates.py | 40 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index ff0bf40..0121d32 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -7,6 +7,7 @@ __version__ = "0.0.1" __license__ = "None" from calendar import month +from symtable import Symbol from shares.share_fetcher import get_share_price import time import datetime @@ -42,17 +43,9 @@ def main_loop(): current_time_datetime = datetime.datetime.now() my_handler = API_Handler("https://gruppe1.testsites.info/api", "bot@example.com", "bot") - print(time.ctime()) # Debug - """p1 = Process(target= update_crontab, args=(current_time_datetime, my_handler )) - p1.start() - time.sleep(5) - p3 = Process(target= update_based_on_crontab, args=() ) - p3.daemon = True - p3.start() - p1.join() - p3.terminate() - p1.terminate()""" + # update_for_user(5270256395, my_handler) # Debug (running test update for kevins shares) + update_crontab(current_time_datetime, my_handler) @@ -122,8 +115,31 @@ def update_based_on_crontab(p_user_ids, p_user_crontab): my_scheduler.start() -def update_for_user(p_user_id): - print("updating for {p_user_id}") +def update_for_user(p_user_id, p_my_handler): + + 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.") + def send_to_user(pText, pUser_id = 1770205310): -- 2.45.2 From e9291d3a975021e49ab617c059450e2ce415cdd3 Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Tue, 19 Apr 2022 08:20:28 +0200 Subject: [PATCH 59/66] Use ISIN numbers instead of share symbols and add comment field to database. Fixes #65 --- api/app/blueprints/portfolio.py | 15 ++++++----- api/app/blueprints/share_price.py | 23 ++++++++-------- api/app/blueprints/shares.py | 43 +++++++++++++++++++----------- api/app/blueprints/transactions.py | 29 ++++++++++++++------ api/app/models.py | 10 ++++--- api/app/schema.py | 23 +++++++++++----- 6 files changed, 90 insertions(+), 53 deletions(-) diff --git a/api/app/blueprints/portfolio.py b/api/app/blueprints/portfolio.py index 2cefe4d..9ead66b 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.0" +__version__ = "1.0.1" import os @@ -27,22 +27,23 @@ def get_portfolio(): return_portfolio = [] # Get all transactions of current user - transactions = db.session.execute("SELECT symbol, SUM(count), SUM(price), MAX(time) FROM `transactions` WHERE email = '" + email + "' GROUP BY symbol;").all() + 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 = { - "symbol": row[0], - "count": row[1], - # "calculated_price": row[2], - "last_transaction": row[3], + "isin": row[0], + "comment": row[1], + "count": row[2], + # "calculated_price": row[3], + "last_transaction": row[4], 'current_price': 0 } # Add current share value to portfolio - query_share_price = db.session.query(SharePrice).filter_by(symbol=row[0]).order_by(SharePrice.date.desc()).first() + query_share_price = db.session.query(SharePrice).filter_by(isin=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 d63a844..50f57ae 100644 --- a/api/app/blueprints/share_price.py +++ b/api/app/blueprints/share_price.py @@ -2,17 +2,16 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.0" +__version__ = "1.0.1" import datetime import os from apiflask import APIBlueprint, abort - -from app.models import SharePrice +from app.auth import auth from app.db import database as db from app.helper_functions import make_response -from app.auth import auth +from app.models import SharePrice from app.schema import SymbolPriceSchema share_price_blueprint = APIBlueprint('share_price', __name__, url_prefix='/api') @@ -25,7 +24,7 @@ __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file @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 symbol FROM `transactions` GROUP BY symbol;").all() + symbols = db.session.execute("SELECT isin FROM `transactions` GROUP BY isin;").all() return_symbols = [] for s in symbols: @@ -38,11 +37,11 @@ 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="Returns all transaction symbols", description="Returns all transaction symbols for all users") +@share_price_blueprint.doc(summary="Adds new price for isin", description="Adds new price to database") def add_symbol_price(data): # Check if required data is available - if not check_if_symbol_data_exists(data): - abort(400, message="Symbol missing") + if not check_if_isin_data_exists(data): + abort(400, message="ISIN missing") if not check_if_price_data_exists(data): abort(400, message="Price missing") @@ -52,7 +51,7 @@ def add_symbol_price(data): # Add share price share_price = SharePrice( - symbol=data['symbol'], + isin=data['isin'], price=data['price'], date=datetime.datetime.strptime(data['time'], '%Y-%m-%dT%H:%M:%S.%fZ'), ) @@ -63,11 +62,11 @@ def add_symbol_price(data): return make_response(share_price.as_dict(), 200, "Successfully added price") -def check_if_symbol_data_exists(data): - if 'symbol' not in data: +def check_if_isin_data_exists(data): + if 'isin' not in data: return False - if data['symbol'] == "" or data['symbol'] is None: + if data['isin'] == "" or data['isin'] is None: return False return True diff --git a/api/app/blueprints/shares.py b/api/app/blueprints/shares.py index e015585..ad0ffe2 100644 --- a/api/app/blueprints/shares.py +++ b/api/app/blueprints/shares.py @@ -2,17 +2,16 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.0" +__version__ = "1.0.1" 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 +from app.schema import SymbolSchema, SymbolResponseSchema, DeleteSuccessfulSchema, SymbolRemoveSchema shares_blueprint = APIBlueprint('share', __name__, url_prefix='/api') __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) @@ -27,16 +26,20 @@ def add_symbol(data): email = get_email_or_abort_401() # Check if required data is available - if not check_if_symbol_data_exists(data): - abort(400, message="Symbol missing") + if not check_if_isin_data_exists(data): + abort(400, message="ISIN missing") + + if not check_if_comment_data_exists(data): + abort(400, message="Comment missing") # Check if share already exists - check_share = db.session.query(Share).filter_by(symbol=data['symbol'], email=email).first() + check_share = db.session.query(Share).filter_by(isin=data['isin'], email=email).first() if check_share is None: # Keyword doesn't exist yet for this user -> add it new_symbol = Share( email=email, - symbol=data['symbol'] + isin=data['isin'], + comment=data['comment'] ) db.session.add(new_symbol) db.session.commit() @@ -48,23 +51,23 @@ def add_symbol(data): @shares_blueprint.route('/share', methods=['DELETE']) @shares_blueprint.output(DeleteSuccessfulSchema, 200) -@shares_blueprint.input(schema=SymbolSchema) +@shares_blueprint.input(schema=SymbolRemoveSchema) @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_symbol_data_exists(data): - abort(400, message="Symbol missing") + if not check_if_isin_data_exists(data): + abort(400, message="ISIN missing") # Check if share exists - check_share = db.session.query(Share).filter_by(symbol=data['symbol'], email=email).first() + 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(symbol=data['symbol'], email=email).delete() + db.session.query(Share).filter_by(isin=data['isin'], email=email).delete() db.session.commit() return make_response({}, 200, "Successfully removed symbol") @@ -89,11 +92,21 @@ def get_symbol(): return make_response(return_symbols, 200, "Successfully loaded symbols") -def check_if_symbol_data_exists(data): - if "symbol" not in data: +def check_if_isin_data_exists(data): + if "isin" not in data: return False - if data['symbol'] == "" or data['symbol'] is None: + 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: return False return True diff --git a/api/app/blueprints/transactions.py b/api/app/blueprints/transactions.py index 2bc469b..d34c799 100644 --- a/api/app/blueprints/transactions.py +++ b/api/app/blueprints/transactions.py @@ -2,13 +2,12 @@ __author__ = "Florian Kaiser" __copyright__ = "Copyright 2022, Project Aktienbot" __credits__ = ["Florian Kaiser", "Florian Kellermann", "Linus Eickhof", "Kevin Pauer"] __license__ = "GPL 3.0" -__version__ = "1.0.0" +__version__ = "1.0.1" 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 @@ -28,12 +27,15 @@ def add_transaction(data): email = get_email_or_abort_401() # Check if required data is available - if not check_if_symbol_data_exists(data): - abort(400, "Symbol missing") + if not check_if_isin_data_exists(data): + abort(400, "ISIN 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") @@ -43,7 +45,8 @@ def add_transaction(data): # Add transaction new_transaction = Transaction( email=email, - symbol=data['symbol'], + isin=data['isin'], + comment=data['comment'], time=datetime.datetime.strptime(data['time'], '%Y-%m-%dT%H:%M:%S.%fZ'), count=data['count'], price=data['price'] @@ -74,11 +77,11 @@ def get_transaction(): return make_response(return_transactions, 200, "Successfully loaded transactions") -def check_if_symbol_data_exists(data): - if "symbol" not in data: +def check_if_isin_data_exists(data): + if "isin" not in data: return False - if data['symbol'] == "" or data['symbol'] is None: + if data['isin'] == "" or data['isin'] is None: return False return True @@ -94,6 +97,16 @@ 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/models.py b/api/app/models.py index 864ce32..8846184 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.0" +__version__ = "1.0.1" from app.db import database as db @@ -30,7 +30,8 @@ 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')) - symbol = db.Column('symbol', db.String(255)) + isin = db.Column('isin', db.String(255)) + comment = db.Column('comment', db.String(255)) time = db.Column('time', db.DateTime()) count = db.Column('count', db.Integer()) price = db.Column('price', db.Float()) @@ -53,7 +54,8 @@ 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')) - symbol = db.Column('symbol', db.String(255)) + isin = db.Column('isin', db.String(255)) + comment = db.Column('comment', db.String(255)) def as_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} @@ -62,7 +64,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) - symbol = db.Column('symbol', db.String(255)) + isin = db.Column('isin', 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 134c401..11be0e2 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.0" +__version__ = "1.0.1" from apiflask import Schema from apiflask.fields import Integer, String, Boolean, Field, Float @@ -72,18 +72,24 @@ class KeywordSchema(Schema): class SymbolSchema(Schema): - symbol = String() + isin = String() + comment = String() + + +class SymbolRemoveSchema(Schema): + isin = String() class TransactionSchema(Schema): - symbol = String() + isin = String() + comment = 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): - symbol = String() + isin = 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() @@ -103,7 +109,8 @@ class KeywordResponseSchema(Schema): class SymbolResponseSchema(Schema): - symbol = String() + isin = String() + comment = String() s_id = Integer() email = Email() @@ -115,14 +122,16 @@ class PortfolioShareResponseSchema(Schema): class TransactionResponseSchema(Schema): email = Email() - symbol = String() + isin = String() + comment = String() time = String() count = Integer() price = Float() class PortfolioResponseSchema(Schema): - symbol = String() + isin = String() + comment = String() last_transaction = String() count = Integer() # price = Float() -- 2.45.2 From 76df6f27becf788f8f304b290378d64c19f9f66e Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Tue, 19 Apr 2022 08:30:25 +0200 Subject: [PATCH 60/66] Forgot one user id in the code --- telegram_bot/bot_updates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index 0121d32..7c6a4a0 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -138,7 +138,7 @@ def update_for_user(p_user_id, p_my_handler): 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.") + 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): -- 2.45.2 From 71fed7fd18c5ab7eade55c67e07c84e8eab51edb Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 19 Apr 2022 21:08:47 +0200 Subject: [PATCH 61/66] added formatting and adapted to isin --- telegram_bot/bot.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index c3ab17e..0f32fe6 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -417,9 +417,12 @@ def send_portfolio(message): bot.send_message(chat_id=user_id, text='You do not have any stocks in your portfolio.') return else: - # tbd: format portfolio - - bot.send_message(chat_id=user_id, text=f'Your portfolio is: _{str(portfolio)}_', parse_mode="MARKDOWN") + 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']) #tbd not working rn @@ -458,7 +461,7 @@ def set_new_transaction_step(message): bot.send_message(chat_id=user_id, text=f'Failed adding transaction. (statuscode {status})') -@bot.message_handler(commands=['interval']) #tbd +@bot.message_handler(commands=['interval']) def send_interval(message): """ send interval for user :type message: message object bot -- 2.45.2 From 7a4a8aaedca5b0e6e0508980a3b1d8dedb72788e Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 19 Apr 2022 21:36:16 +0200 Subject: [PATCH 62/66] fixed case sensitive commands --- telegram_bot/api_handling/api_handler.py | 9 ++-- telegram_bot/bot.py | 55 ++++++++++++------------ 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index c5bc997..49751f0 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -270,22 +270,23 @@ class API_Handler: return self.get_user_transactions(user_id, max_retries-1) - def set_transaction(self, user_id, count, price, symbol, timestamp): + 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 - symbol (string): symbol of the transaction - timestamp (string): timestamp 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 = {"count": count, "price": price, "symbol": symbol, "time": timestamp} + 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 diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 0f32fe6..c194789 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -68,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 @@ -90,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 @@ -104,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 @@ -118,7 +118,7 @@ def send_welcome(message): 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 @@ -141,7 +141,7 @@ def send_all_users(message): bot.send_message(chat_id=user_id, text=answer) -@bot.message_handler(commands=['me']) +@bot.message_handler(commands=['me', 'Me']) # /me -> sending user info def send_user(message): """ Send user data :type message: message object bot @@ -160,7 +160,7 @@ def send_user(message): bot.reply_to(message, 'Your user data:\n' + str(user_data)) -@bot.message_handler(commands=['id', 'auth']) # /auth or /id -> Authentication with user_id over web tool +@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 @@ -176,7 +176,7 @@ def send_id(message): #function that sends telegram status(running or offline) as message from telegram bot to user -@bot.message_handler(commands=['status']) +@bot.message_handler(commands=['status', 'Status']) def send_status(message): """ Sends status to user @@ -190,7 +190,7 @@ def send_status(message): bot.reply_to(message, "bot is running") -@bot.message_handler(commands=['update']) +@bot.message_handler(commands=['update', 'Update']) # /update -> update shares def send_update(message): """ Send update on shares @@ -228,7 +228,7 @@ def send_update(message): bot.send_message(chat_id=user_id, text=my_update_message) -@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 @@ -251,7 +251,7 @@ def send_share_price(message): bot.reply_to(message, str_share_price) -@bot.message_handler(commands=['allnews']) +@bot.message_handler(commands=['allnews', 'Allnews']) # /allnews -> get all news def send_all_news(message): """ Get news for keywords of user @@ -290,7 +290,7 @@ def send_all_news(message): bot.send_message(chat_id=user_id, text='No news found for your keywords.') -@bot.message_handler(commands=['news']) +@bot.message_handler(commands=['news', 'News']) # /news -> get news for specific keyword def send_news(message): """ Get news for keywords of user @@ -326,7 +326,7 @@ def send_news(message): bot.send_message(chat_id=user_id, text=f"_keyword: {keyword}_\n\n" + formatted_article, parse_mode="MARKDOWN") -@bot.message_handler(commands=['addkeyword']) +@bot.message_handler(commands=['addkeyword', 'Addkeyword']) # /addkeyword -> add keyword to user def add_keyword(message): """ Add keyword to user :type message: message object bot @@ -348,10 +348,10 @@ def store_keyword(message): 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. (statuscode {status})') + 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']) +@bot.message_handler(commands=['removekeyword', 'Removekeyword']) # /removekeyword -> remove keyword from user def remove_keyword(message): """ Remove keyword from user :type message: message object bot @@ -375,7 +375,7 @@ def remove_keyword_step(message): bot.send_message(chat_id=user_id, text=f'Failed deleting keyword "{keyword}". (statuscode {status})') -@bot.message_handler(commands=['keywords']) +@bot.message_handler(commands=['keywords', 'Keywords']) # /keywords -> get keywords of user def send_keywords(message): """ Send keywords of user :type message: message object bot @@ -398,7 +398,7 @@ def send_keywords(message): bot.send_message(chat_id=user_id, text=f'Your keywords are: _{keywords_str}_', parse_mode="MARKDOWN") -@bot.message_handler(commands=['portfolio']) #tbd +@bot.message_handler(commands=['portfolio', 'Portfolio']) #tbd def send_portfolio(message): """ Send portfolio of user :type message: message object bot @@ -425,7 +425,7 @@ def send_portfolio(message): bot.send_message(chat_id=user_id, text=f'*{comment}*\n_{isin}_\namount: {count}\nworth: ${worth}', parse_mode="MARKDOWN") -@bot.message_handler(commands=['newtransaction']) #tbd not working rn +@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 @@ -436,24 +436,25 @@ def set_new_transaction(message): :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.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]+,[0-9]+(.[0-9]+)?,[0-9]+(.[0-9]+)?", message.text): - bot.send_message(chat_id=user_id, text='Invalid format \n(e.g. AAPL,53.2,120.4).\n Try again with /newtransaction.') + 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(',') - symbol = str(transaction_data[0]) - amount = float(transaction_data[1]) - price = float(transaction_data[2]) - time = dt.datetime.now() + 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, amount, price, symbol, 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.') @@ -461,7 +462,7 @@ def set_new_transaction_step(message): bot.send_message(chat_id=user_id, text=f'Failed adding transaction. (statuscode {status})') -@bot.message_handler(commands=['interval']) +@bot.message_handler(commands=['interval', 'Interval']) #tbd def send_interval(message): """ send interval for user :type message: message object bot @@ -485,7 +486,7 @@ def send_interval(message): bot.send_message(chat_id=user_id, text=f'Your update interval: {interval} (https://crontab.guru/#{formatted_interval})') -@bot.message_handler(commands=['setinterval']) +@bot.message_handler(commands=['setinterval', 'Setinterval']) #tbd def set_new_interval(message): """ Set new interval for user :type message: message object bot -- 2.45.2 From 2b18e026239a0c62fe7480270303c7efea79e0bc Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Wed, 20 Apr 2022 11:03:21 +0200 Subject: [PATCH 63/66] update /update function --- telegram_bot/bot.py | 68 +++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index c194789..c30bfdf 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -190,42 +190,50 @@ def send_status(message): bot.reply_to(message, "bot is running") -@bot.message_handler(commands=['update', 'Update']) # /update -> update shares -def send_update(message): +@bot.message_handler(commands=['update', 'Update']) # /update -> update shares +def update_for_user(message): - """ Send update on shares - :type message: message object bot - :param message: message that was reacted to, in this case always containing '/help' + p_user_id = int(message.from_user.id) + p_my_handler = api_handler + + 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 """ - user_id = int(message.from_user.id) - - #Can be deleted when getting from database - dirname = os.path.dirname(__file__) - json_path = os.path.join(dirname, 'shares/shares_example.json') - - 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) + bot.send_message(chat_id=pUser_id, text=pText) @bot.message_handler(commands=['share', 'Share']) # /share -> get share price -- 2.45.2 From fa8b511ef4757425e666620576e54fd679aa33de Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Thu, 21 Apr 2022 08:23:48 +0200 Subject: [PATCH 64/66] Scheduler working --- telegram_bot/bot_updates.py | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index 7c6a4a0..b0501c4 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -15,6 +15,7 @@ from bot import bot import sys from multiprocessing import Process from apscheduler.schedulers.blocking import BlockingScheduler +from apscheduler.schedulers.background import BackgroundScheduler from api_handling.api_handler import API_Handler @@ -63,7 +64,7 @@ def update_crontab(pCurrent_Time, p_my_handler): global user_crontab global user_ids - p_my_handler.set_cron_interval(user_id = 1770205310, cron_interval = "8 17 * * *") + #p_my_handler.set_cron_interval(user_id = 1770205310, cron_interval = "23 08 * * *") all_users = p_my_handler.get_all_users() @@ -76,44 +77,30 @@ def update_crontab(pCurrent_Time, p_my_handler): user_crontab.append(str(element["cron"])) print(user_ids) - update_based_on_crontab(user_ids, user_crontab) - - p1 = Process(target= sleeping_time, args=(pCurrent_Time, )) - p1.start() - p3 = Process(target= update_based_on_crontab, args=(user_ids, user_crontab ) ) - p3.daemon = True - p3.start() - p1.join() - p3.terminate() - p1.terminate() + + 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): -def sleeping_time(pCurrent_Time): - while True: - time_difference = datetime.datetime.now() - pCurrent_Time - print(time_difference) - if float(str(time_difference).split(':')[1]) >=1: # every minute (0:00:03.646070) -> example time code - update_crontab(datetime.datetime.now()) - break - -def update_based_on_crontab(p_user_ids, p_user_crontab): - - my_scheduler = BlockingScheduler() + my_scheduler = BackgroundScheduler() print("update based on cron") print(len(user_ids)) #Debug for i in range(len(p_user_ids)): - print("in loop") 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], )) + 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() + + print("60 second sleep") + time.sleep( 60 ) + my_scheduler.shutdown() def update_for_user(p_user_id, p_my_handler): -- 2.45.2 From cac5883b99d4b0e4689cd631e21668791ca605d0 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Thu, 21 Apr 2022 10:06:08 +0200 Subject: [PATCH 65/66] Better code documentation and removing unnecessary stuff --- telegram_bot/bot_updates.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index b0501c4..6269b5e 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -3,7 +3,7 @@ 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" +__version__ = "1.0.1" __license__ = "None" from calendar import month @@ -14,7 +14,6 @@ import datetime from bot import bot import sys from multiprocessing import Process -from apscheduler.schedulers.blocking import BlockingScheduler from apscheduler.schedulers.background import BackgroundScheduler from api_handling.api_handler import API_Handler @@ -85,9 +84,22 @@ def update_crontab(pCurrent_Time, p_my_handler): def update_based_on_crontab(p_user_ids, p_user_crontab, p_my_handler): - my_scheduler = BackgroundScheduler() + """ 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 + """ - print("update based on cron") + my_scheduler = BackgroundScheduler() print(len(user_ids)) #Debug @@ -98,12 +110,22 @@ def update_based_on_crontab(p_user_ids, p_user_crontab, p_my_handler): my_scheduler.start() - print("60 second sleep") - time.sleep( 60 ) + 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 = [] @@ -146,7 +168,7 @@ def send_to_user(pText, pUser_id = 1770205310): if __name__ == "__main__": - print('This script shall not be run directly. Starting main_loop for debugging purposes.') + print('bot_updates.py starting.') try: main_loop() sys.exit(-1) -- 2.45.2 From 78dfde7a869866d784c2535e3b84fc43e837f8a4 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Mon, 25 Apr 2022 08:05:30 +0200 Subject: [PATCH 66/66] new bot version --- telegram_bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index c30bfdf..6655ad5 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -34,7 +34,7 @@ from api_handling.api_handler import API_Handler load_dotenv(dotenv_path='.env') -bot_version = "0.2.1" +bot_version = "1.0.1" user_list = [] #create api handler -- 2.45.2