Merge branch 'main' into frontend
This commit is contained in:
commit
ad6b47056f
@ -1,16 +1,16 @@
|
||||
Flask~=2.1.1
|
||||
Flask~=2.1.2
|
||||
python-dotenv==0.20.0
|
||||
uwsgi==2.0.20
|
||||
Flask_SQLAlchemy==2.5.1
|
||||
python-dotenv==0.20.0
|
||||
pymysql==1.0.2
|
||||
pyjwt==2.3.0
|
||||
apiflask==0.12.0
|
||||
apiflask==1.0.0
|
||||
flask-cors==3.0.10
|
||||
bcrypt==3.2.0
|
||||
bcrypt==3.2.2
|
||||
pytest~=7.1.2
|
||||
pytest-cov
|
||||
marshmallow~=3.15.0
|
||||
faker~=13.6.0
|
||||
faker~=13.7.0
|
||||
yfinance~=0.1.70
|
||||
requests~=2.27.1
|
@ -1,6 +1,19 @@
|
||||
# Telegram bot api key
|
||||
BOT_API_KEY=
|
||||
|
||||
# News api key
|
||||
NEWS_API_KEY=
|
||||
|
||||
# Flask secret key
|
||||
SECRET_KEY=
|
||||
|
||||
# bot credentials
|
||||
BOT_EMAIL=
|
||||
BOT_PASSWORD=
|
||||
|
||||
# urls
|
||||
WEBSITE_URL=
|
||||
API_URL=
|
||||
|
||||
# timezone
|
||||
TZ=Europe/Berlin
|
BIN
documentation/Kurzdokumentation.docx
Normal file
BIN
documentation/Kurzdokumentation.docx
Normal file
Binary file not shown.
@ -18,35 +18,35 @@
|
||||
"@angular/compiler": "~13.2.0",
|
||||
"@angular/core": "~13.2.0",
|
||||
"@angular/forms": "~13.2.0",
|
||||
"@angular/material": "^13.2.6",
|
||||
"@angular/material": "^13.3.6",
|
||||
"@angular/platform-browser": "~13.2.0",
|
||||
"@angular/platform-browser-dynamic": "~13.2.0",
|
||||
"@angular/router": "~13.2.0",
|
||||
"bootstrap": "^5.1.3",
|
||||
"ngx-cron-editor": "^0.7.3",
|
||||
"rxjs": "~7.5.0",
|
||||
"tslib": "^2.3.0",
|
||||
"tslib": "^2.4.0",
|
||||
"zone.js": "~0.11.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~13.2.5",
|
||||
"@angular-devkit/build-angular": "~13.3.5",
|
||||
"@angular-eslint/builder": "13.2.1",
|
||||
"@angular-eslint/eslint-plugin": "13.2.1",
|
||||
"@angular-eslint/eslint-plugin-template": "13.2.1",
|
||||
"@angular-eslint/schematics": "13.2.1",
|
||||
"@angular-eslint/template-parser": "13.2.1",
|
||||
"@angular/cli": "~13.2.5",
|
||||
"@angular/cli": "~13.3.5",
|
||||
"@angular/compiler-cli": "~13.2.0",
|
||||
"@types/jasmine": "~3.10.0",
|
||||
"@types/jasmine": "~4.0.3",
|
||||
"@types/node": "^12.11.1",
|
||||
"@typescript-eslint/eslint-plugin": "5.17.0",
|
||||
"@typescript-eslint/parser": "5.17.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.22.0",
|
||||
"@typescript-eslint/parser": "5.22.0",
|
||||
"eslint": "^8.12.0",
|
||||
"jasmine-core": "~4.0.0",
|
||||
"karma": "~6.3.0",
|
||||
"jasmine-core": "~4.1.0",
|
||||
"karma": "~6.3.19",
|
||||
"karma-chrome-launcher": "~3.1.0",
|
||||
"karma-coverage": "~2.1.0",
|
||||
"karma-jasmine": "~4.0.0",
|
||||
"karma-coverage": "~2.2.0",
|
||||
"karma-jasmine": "~5.0.0",
|
||||
"karma-jasmine-html-reporter": "~1.7.0",
|
||||
"typescript": "~4.5.2"
|
||||
}
|
||||
|
@ -10,3 +10,10 @@ SECRET_KEY=
|
||||
# bot credentials
|
||||
BOT_EMAIL=
|
||||
BOT_PASSWORD=
|
||||
|
||||
# urls
|
||||
WEBSITE_URL=
|
||||
API_URL=
|
||||
|
||||
# timezone
|
||||
TZ=Europe/Berlin
|
@ -3,12 +3,13 @@
|
||||
Aktienbot telegram bot
|
||||
|
||||
## Development
|
||||
1. Create virtual environment `python -m venv venv env/Scripts/activate`
|
||||
2. Install requirements `pip install -r telegram_bot/requirements.txt`
|
||||
3. Set environment variables (see list below)
|
||||
1. Create virtual environment `python -m venv venv`
|
||||
2. Launch venv: `.\venv\Scripts\activate`
|
||||
3. Install requirements `pip install -r telegram_bot/requirements.txt`
|
||||
4. Set environment variables (see list below)
|
||||
1. Use `.env`-file in `api` directory like `.env.example`
|
||||
2. Or set variables using `export` or `set` commands. (Windows `set`, Linux `export`)
|
||||
4. Run api `python telegram_bot/bot.py`
|
||||
5. Run api `python telegram_bot/bot.py`
|
||||
|
||||
## Environment variables
|
||||
```
|
||||
|
@ -41,10 +41,10 @@ print("Webserver Token: " + str(api_handler.token))
|
||||
|
||||
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
|
||||
|
||||
@bot.message_handler(commands=['start', 'Start']) # /start -> saving as new user and sending welcome
|
||||
@bot.message_handler(commands=['start', 'Start'])
|
||||
def send_start(message):
|
||||
|
||||
""" Description
|
||||
""" Sending welcome message to new user
|
||||
:type message: message object bot
|
||||
:param message: message that was reacted to, in this case always containing '/start'
|
||||
|
||||
@ -52,7 +52,10 @@ def send_start(message):
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
bot.reply_to(message, "Welcome to this share bot project. Type /help to get information on what this bot can do")
|
||||
bot.reply_to(message, "Welcome to this share bot project. \
|
||||
\nType /help to get information on what this bot can do. \
|
||||
\nAlso see https://gruppe1.testsites.info \
|
||||
to start configuring your bot")
|
||||
|
||||
|
||||
@bot.message_handler(commands=['version', 'Version'])
|
||||
@ -273,14 +276,12 @@ def send_share_update(message):
|
||||
"""
|
||||
user_id = int(message.from_user.id)
|
||||
|
||||
#Get Information for user with this id
|
||||
bot.send_message(chat_id=user_id, text='Send symbol of share:')
|
||||
#str_share_price = shares.wait_for_share.main_loop(bot)
|
||||
bot.send_message(chat_id=user_id, text='Send Symbol/ISIN of share or name of company:')
|
||||
bot.register_next_step_handler(message, send_share_price)
|
||||
|
||||
def send_share_price(message):
|
||||
str_share_price = share_fetcher.get_share_price(str(message.text))
|
||||
bot.reply_to(message, str_share_price) # add dollar symbol etc.
|
||||
str_share_price = share_fetcher.get_share_information(str(message.text))
|
||||
bot.reply_to(message, str_share_price)
|
||||
|
||||
|
||||
@bot.message_handler(commands=['allnews', 'Allnews']) # /allnews -> get all news
|
||||
@ -465,13 +466,13 @@ def set_new_transaction(message):
|
||||
:rtype: none
|
||||
"""
|
||||
user_id = int(message.from_user.id)
|
||||
bot.send_message(chat_id=user_id, text='Type "<name of stock>,<isin>,<amount>,<price_per_stock_usd>" (time of transaction will be set to now):')
|
||||
bot.send_message(chat_id=user_id, text='Type "<name of stock>,<isin/name/symbol>,<amount>,<price_per_stock_usd>" (time of transaction will be set to now, negative amount is selling, positive is buying):')
|
||||
bot.register_next_step_handler(message, set_new_transaction_step)
|
||||
|
||||
def set_new_transaction_step(message):
|
||||
user_id = int(message.from_user.id)
|
||||
|
||||
if not re.match(r"[A-Za-z0-9]+,[A-Za-z0-9]+,[0-9]+(.[0-9]+)?,[0-9]+(.[0-9]+)?", message.text):
|
||||
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
|
||||
|
||||
|
@ -68,8 +68,13 @@ def update_crontab(p_my_handler):
|
||||
|
||||
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"]))
|
||||
try:
|
||||
user_ids.append(int(element["telegram_user_id"]))
|
||||
try:
|
||||
user_crontab.append(str(element["cron"]))
|
||||
except: continue
|
||||
except: continue
|
||||
|
||||
|
||||
print(user_ids)
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
pyTelegramBotAPI~=4.5.0
|
||||
Markdown~=3.3.6
|
||||
yfinance~=0.1.70
|
||||
newsapi-python~=0.2.6
|
||||
python-dotenv~=0.20.0
|
||||
requests~=2.27.1
|
||||
APScheduler~=3.9.1
|
||||
croniter~=1.3.4
|
||||
tzlocal==2.1
|
||||
investpy~=1.0.8
|
||||
pandas~=1.4.1
|
||||
currencyconverter~=0.16.12
|
@ -3,24 +3,110 @@ script for share fetching (by symbols (e.g. AAPL, TSLA etc.))
|
||||
"""
|
||||
__author__ = "Florian Kellermann, Linus Eickhoff"
|
||||
__date__ = "15.03.2022"
|
||||
__version__ = "0.0.2"
|
||||
__version__ = "1.0.0"
|
||||
__license__ = "None"
|
||||
|
||||
import yfinance
|
||||
import investpy
|
||||
import pandas
|
||||
from currency_converter import CurrencyConverter
|
||||
|
||||
def get_share_price(str_symbol):
|
||||
def get_share_price(str_search_for):
|
||||
"""get stock price per share for company name or isin or symbol
|
||||
|
||||
""" get current share price for a certain symbol
|
||||
:type str_symbol: string
|
||||
:param str_symbol: share symbol to get price for
|
||||
Args:
|
||||
str_search_for (string): search for this string/isin
|
||||
|
||||
:raises:
|
||||
|
||||
:rtype:
|
||||
Returns: none
|
||||
"""
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1, countries=['germany'])
|
||||
|
||||
my_share_info = yfinance.Ticker(str_symbol)
|
||||
my_share_data = my_share_info.info
|
||||
#my_return_string = f'{my_share_data["regularMarketPrice"]} {my_share_data["currency"]}'
|
||||
my_return_string = f'{my_share_data["regularMarketPrice"]}'
|
||||
return my_return_string
|
||||
currency = str(search_result.retrieve_currency())
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return =str(stock_price) + " " + str(currency)
|
||||
|
||||
return str_return
|
||||
|
||||
except RuntimeError:
|
||||
try:
|
||||
my_Converter = CurrencyConverter()
|
||||
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||
|
||||
currency = str(search_result.retrieve_currency())
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return =str(stock_price) + " EUR"
|
||||
|
||||
return str_return
|
||||
|
||||
except RuntimeError:
|
||||
return "None"
|
||||
|
||||
def get_share_price_no_currency(str_search_for):
|
||||
"""get stock price per share for company name or isin or symbol no currency
|
||||
|
||||
Args:
|
||||
str_search_for (string): search for this string/isin
|
||||
|
||||
Returns: none
|
||||
"""
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
return stock_price
|
||||
|
||||
except RuntimeError:
|
||||
my_Converter = CurrencyConverter()
|
||||
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||
|
||||
currency = str(search_result.retrieve_currency())
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return =str(stock_price)
|
||||
|
||||
return str_return
|
||||
|
||||
|
||||
def get_share_information(str_search_for):
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
str_return = "Company: " + search_result.name + "\nSymbol: " + search_result.symbol + "\nCurrent Price/Share: " + get_share_price(str_search_for)
|
||||
|
||||
return str_return
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_share_price("US2515661054"))
|
||||
print(get_share_price("DE0005557508"))
|
||||
print(get_share_price_no_currency("US2515661054"))
|
||||
print(get_share_price_no_currency("DE0005557508"))
|
Loading…
Reference in New Issue
Block a user