diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 72d6034..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,27 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - # API - - package-ecosystem: "pip" - directory: "/api" - schedule: - interval: "daily" - open-pull-requests-limit: 100 - - # Bot - - package-ecosystem: "pip" - directory: "/telegram_bot" - schedule: - interval: "daily" - open-pull-requests-limit: 100 - - # Frontend - - package-ecosystem: "npm" - directory: "/frontend" - schedule: - interval: "daily" - open-pull-requests-limit: 100 diff --git a/.renovaterc.json b/.renovaterc.json new file mode 100644 index 0000000..6091b8b --- /dev/null +++ b/.renovaterc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "schedule": ["* 5 * * *"] +} \ No newline at end of file diff --git a/.woodpecker/pipeline.yml b/.woodpecker.yml similarity index 93% rename from .woodpecker/pipeline.yml rename to .woodpecker.yml index 7a0d6a1..201f398 100644 --- a/.woodpecker/pipeline.yml +++ b/.woodpecker.yml @@ -77,9 +77,9 @@ pipeline: password: from_secret: ssh_password script: - - cd /root/docker/aktienbot + - cd ~/docker-compose-files/telegram_aktien_bot - docker-compose pull - - docker-compose -p "aktienbot" up -d + - docker-compose --env-file ~/docker-compose-env/telegram_aktien_bot.env up -d when: path: [ "frontend/**", "telegram_bot/**", "api/**" ] event: push diff --git a/README.md b/README.md index 0bb8abd..66d415e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://woodpecker.flokaiser.com/api/badges/WebEngineering2/TelegramAktienBot/status.svg)](https://woodpecker.flokaiser.com/WebEngineering2/TelegramAktienBot/) +[![Build Status](https://gitea.woodpecker.flokaiser.com/api/badges/DHBW/TelegramAktienBot/status.svg)](https://gitea.woodpecker.flokaiser.com/DHBW/TelegramAktienBot) # TelegramAktienBot WebEngineering2 Projekt: Aktien und News Bot für Telegram @@ -21,16 +21,4 @@ WebEngineering2 Projekt: Aktien und News Bot für Telegram * Florian Kaiser * Florian Kellermann * Linus Eickhoff -* Kevin Pauer - -## Nützliche Tools -- Portainer (https://gruppe1.testsites.info/portainer/) \ - *Container Management System* -- phpMyAdmin (https://gruppe1.testsites.info/phpmyadmin/) \ - *Administration von MySQL-Datenbanken* -- goaccess (https://gruppe1.testsites.info/goaccess/) \ - *Webanalyseanwendung* -- Uptimekuma (https://uptimekuma.flokaiser.com/status/aktienbot) \ - *Monitoring* -- Woodpecker (https://woodpecker.flokaiser.com/WebEngineering2/TelegramAktienBot) \ - *Continuous Integration platform* +* Kevin Pauer \ No newline at end of file diff --git a/api/load_share_price.py b/api/load_share_price.py index 80bf4a3..27db24d 100644 --- a/api/load_share_price.py +++ b/api/load_share_price.py @@ -64,10 +64,15 @@ token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": usern response = requests.get(os.getenv("API_URL") + '/symbols', headers={'Authorization': 'Bearer ' + token}).json()['data'] -symbols = split(response, int(len(response) / 5)) -for symbol_list in symbols: - for symbol in symbol_list: - x = threading.Thread(target=thread_function, args=(symbol,)) - x.start() +if len(response) > 5: + symbols = split(response, int(len(response) / 5)) + for symbol_list in symbols: + for symbol in symbol_list: + x = threading.Thread(target=thread_function, args=(symbol,)) + x.start() - time.sleep(10) + time.sleep(10) +else: + for symbol in response: + x = threading.Thread(target=thread_function, args=(symbol,)) + x.start() \ No newline at end of file diff --git a/deploy/aktienbot/.env.bot b/deploy/aktienbot/.env.bot index 8a24d57..bb2474a 100644 --- a/deploy/aktienbot/.env.bot +++ b/deploy/aktienbot/.env.bot @@ -12,7 +12,7 @@ BOT_EMAIL= BOT_PASSWORD= # urls -WEBSITE_URL= +APP_URL= API_URL= # timezone diff --git a/documentation/README.md b/documentation/README.md index 80c8665..7eae60b 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -1,7 +1,7 @@ # Dokumentation ## Swagger Documentation -Visit https://gruppe1.testsites.info/api/docs +Visit \ + /docs ## API - `api/openapi.json` diff --git a/frontend/src/app/Services/auth.service.ts b/frontend/src/app/Services/auth.service.ts index 9ab2ff1..1fff7be 100644 --- a/frontend/src/app/Services/auth.service.ts +++ b/frontend/src/app/Services/auth.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; -const AUTH_API = 'https://gruppe1.testsites.info/api/user'; +const AUTH_API = '/api/user'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }), diff --git a/frontend/src/app/Services/bot.service.ts b/frontend/src/app/Services/bot.service.ts index afe1618..4d0246c 100644 --- a/frontend/src/app/Services/bot.service.ts +++ b/frontend/src/app/Services/bot.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { TokenStorageService } from './token.service'; -const API_URL = 'https://gruppe1.testsites.info/api/'; +const API_URL = '/api/'; @Injectable({ providedIn: 'root', diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index c97439a..7869962 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -2,7 +2,7 @@ import { Injectable, OnInit } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { delay, Observable } from 'rxjs'; import { TokenStorageService } from './token.service'; -const API_URL = 'https://gruppe1.testsites.info/api/'; +const API_URL = '/api/'; @Injectable({ providedIn: 'root', }) diff --git a/frontend/src/app/Services/profile.service.ts b/frontend/src/app/Services/profile.service.ts index 2645ad5..32ae0ac 100644 --- a/frontend/src/app/Services/profile.service.ts +++ b/frontend/src/app/Services/profile.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { TokenStorageService } from './token.service'; -const API_URL = 'https://gruppe1.testsites.info/api/'; +const API_URL = '/api/'; @Injectable({ providedIn: 'root', @@ -77,7 +77,7 @@ export class ProfileService { */ public addCronString(cron: string): Observable { return this.http.put( - 'https://gruppe1.testsites.info/api/user' + '/setCron', + '/api/user' + '/setCron', { cron, }, diff --git a/telegram_bot/.env.example b/telegram_bot/.env.example index 8a24d57..bb2474a 100644 --- a/telegram_bot/.env.example +++ b/telegram_bot/.env.example @@ -12,7 +12,7 @@ BOT_EMAIL= BOT_PASSWORD= # urls -WEBSITE_URL= +APP_URL= API_URL= # timezone diff --git a/telegram_bot/api_handling/api_handler.py b/telegram_bot/api_handling/api_handler.py index 9975f6d..053f02d 100644 --- a/telegram_bot/api_handling/api_handler.py +++ b/telegram_bot/api_handling/api_handler.py @@ -19,7 +19,7 @@ from dotenv import load_dotenv load_dotenv() # loads environment vars -# note: for more information about the api visit swagger documentation on https://gruppe1.testsites.info/api/docs#/ +# note: for more information about the api visit swagger documentation on os.getenv("API_URL")/docs#/ class API_Handler: """class for interacting with the api webservice @@ -392,7 +392,7 @@ class API_Handler: if __name__ == "__main__": # editable, just for basic on the go testing of new functions print("This is a module for the telegram bot. It is not intended to be run directly.") - handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) # get creds from env + handler = API_Handler(os.getenv("API_URL"), str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) # get creds from env print(handler.token) keywords = handler.get_user_keywords(user_id=1709356058) # user_id here is currently mine (Linus) print(keywords) diff --git a/telegram_bot/bot.py b/telegram_bot/bot.py index 48b7b72..4e105df 100644 --- a/telegram_bot/bot.py +++ b/telegram_bot/bot.py @@ -50,7 +50,7 @@ def send_start(message): """ bot.reply_to(message, "Welcome to this share bot project. \ \nType /help to get information on what this bot can do. \ - \nAlso see " + os.getenv("WEBSITE_URL") + " \ + \nAlso see " + os.getenv("APP_URL") + " \ to start configuring your bot") @@ -78,7 +78,7 @@ def send_help(message): :rtype: none """ bot.reply_to(message, - "/id or /auth get your user id\n/shares get update on interesting shares\n/setAdmin set admin rights of user (ADMIN)\n/users see all users. (ADMIN)\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/transactions get all transactions\n/newtransaction create new transaction\n/share get price of specific share\n/portfolio see own stock portfolio\n/removeshare removes share from portfolio\n/interval get update interval\n/setinterval set update interval\n For further details see " + os.getenv("WEBSITE_URL")) + "/id or /auth get your user id\n/shares get update on interesting shares\n/setAdmin set admin rights of user (ADMIN)\n/users see all users. (ADMIN)\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/transactions get all transactions\n/newtransaction create new transaction\n/share get price of specific share\n/portfolio see own stock portfolio\n/removeshare removes share from portfolio\n/interval get update interval\n/setinterval set update interval\n For further details see " + os.getenv("APP_URL")) @bot.message_handler(commands=['users', 'Users']) # /users -> sending all users @@ -170,7 +170,7 @@ def send_user(message): user_id = int(message.from_user.id) user_data = api_handler.get_user(user_id) if not user_data or user_data == None: # true if user is not registered - bot.reply_to(message, "This didn\'t work. Make sure to connect your telegram id (/id) on " + os.getenv("WEBSITE_URL")) + bot.reply_to(message, "This didn\'t work. Make sure to connect your telegram id (/id) on " + os.getenv("APP_URL")) return username = user_data['username'] email = user_data['email'] @@ -190,7 +190,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 ' + os.getenv("WEBSITE_URL") + ' to get updates on your shares.' + answer = 'Your ID/Authentication Code is: [' + str(message.from_user.id) + ']. Enter this code in the settings on ' + os.getenv("APP_URL") + ' to get updates on your shares.' bot.reply_to(message, answer) @@ -219,7 +219,7 @@ def update_for_user(message): my_portfolio = p_my_handler.get_user_portfolio(p_user_id) if my_portfolio == None: # true if user is not registered - bot.send_message(chat_id=p_user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL")) + bot.send_message(chat_id=p_user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("APP_URL")) return my_user = p_my_handler.get_user(p_user_id) @@ -240,7 +240,7 @@ def update_for_user(message): my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {amounts}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR' bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2") else: - send_to_user("No shares found for your account. Check " + os.getenv("WEBSITE_URL") + " to change your settings and add shares.", pUser_id=p_user_id) + send_to_user("No shares found for your account. Check " + os.getenv("APP_URL") + " to change your settings and add shares.", pUser_id=p_user_id) def send_to_user(pText, pUser_id): @@ -294,7 +294,7 @@ def send_all_news(message): keywords = api_handler.get_user_keywords(user_id) # get keywords of user if keywords == None: # true if user is not registered - bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL")) + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("APP_URL")) return if not keywords: # true if user is registered but does not have any keywords @@ -330,7 +330,7 @@ def send_news(message): keywords = api_handler.get_user_keywords(user_id) # get keywords of user if keywords == None: # true if user is not registered - bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL")) + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("APP_URL")) return if not keywords: # true if user is registered but does not have any keywords @@ -375,7 +375,7 @@ def store_keyword(message): if status == 200: # statuscode 200 means keyword was added successfully without errors bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" added.') # duplicate keywords are denied by Database, so no need to check for that here else: - bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" could not be stored. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info (statuscode {status})') + bot.send_message(chat_id=user_id, text=f'Keyword "{keyword}" could not be stored. Make sure to connect your telegram id (/id) on {os.getenv("APP_URL")} (statuscode {status})') @bot.message_handler(commands=['removekeyword', 'Removekeyword']) # /removekeyword -> remove keyword from user @@ -417,7 +417,7 @@ def send_keywords(message): keywords = api_handler.get_user_keywords(user_id) # get keywords of user if keywords == None: # true if user is not registered - bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL")) + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("APP_URL")) return if not keywords: # true if user is registered but does not have any keywords @@ -513,7 +513,7 @@ def send_interval(message): user_id = int(message.from_user.id) user_data = api_handler.get_user(user_id) # get cron interval of user (stored in user data) if user_data == None: # true if user is not registered in DB - bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL") + ' and set an interval with /setinterval') + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("APP_URL") + ' and set an interval with /setinterval') return else: # send interval interval = str(user_data['cron']) # get cron from user data @@ -538,7 +538,7 @@ def send_transactions(message): transactions = api_handler.get_user_transactions(user_id) # get transactions of user if transactions == None: # true if user does not exist - bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL")) + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("APP_URL")) return if not transactions: # true if user has no transactions @@ -571,9 +571,9 @@ def send_shares(message): shares = api_handler.get_user_shares(user_id) # get shares of user if shares == None: # true if user does not exist - bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("WEBSITE_URL")) + bot.send_message(chat_id=user_id, text='This didn\'t work. Make sure to connect your telegram id (/id) on ' + os.getenv("APP_URL")) elif not shares: # true if user has no shares - bot.send_message(chat_id=user_id, text='You do not have any shares. Add shares on ' + os.getenv("WEBSITE_URL")) + bot.send_message(chat_id=user_id, text='You do not have any shares. Add shares on ' + os.getenv("APP_URL")) else: for element in shares: bot.send_message(chat_id=user_id, text=share_fetcher.get_share_information_markdown(element), parse_mode="MARKDOWNV2") diff --git a/telegram_bot/bot_updates.py b/telegram_bot/bot_updates.py index f01a318..ba19b38 100644 --- a/telegram_bot/bot_updates.py +++ b/telegram_bot/bot_updates.py @@ -156,7 +156,7 @@ def update_for_user(p_user_id, p_my_handler): my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {hf.make_markdown_proof(share_amounts[i])}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR' bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2") else: - send_to_user("No shares found for your account. Check " + os.getenv("WEBSITE_URL") + " to change your settings and add shares.", pUser_id=p_user_id) + send_to_user("No shares found for your account. Check " + os.getenv("APP_URL") + " to change your settings and add shares.", pUser_id=p_user_id) if len(shares) != 0: # Send updates on watchlist shares if existing send_to_user("Your watchlist shares:", pUser_id=p_user_id)