2022-04-12 07:50:24 +00:00
|
|
|
__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"
|
|
|
|
|
2022-04-05 13:08:57 +00:00
|
|
|
import datetime
|
|
|
|
import os
|
|
|
|
import threading
|
2022-04-06 10:34:03 +00:00
|
|
|
import time
|
2022-04-05 13:08:57 +00:00
|
|
|
|
2022-05-09 12:22:17 +00:00
|
|
|
import investpy
|
|
|
|
import pandas
|
2022-04-05 13:08:57 +00:00
|
|
|
import requests
|
2022-05-09 12:22:17 +00:00
|
|
|
from currency_converter import CurrencyConverter
|
2022-04-06 10:34:03 +00:00
|
|
|
from dotenv import load_dotenv
|
2022-04-05 13:08:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
def thread_function(s):
|
2022-05-09 12:22:17 +00:00
|
|
|
try:
|
|
|
|
search_result = investpy.search_quotes(text=s, products=['stocks'], countries=['germany'], n_results=1)
|
|
|
|
|
|
|
|
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
|
|
|
|
|
|
|
stock_price = round(float(recent_data.iloc[-1]["Close"]), 2)
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
"isin": s,
|
|
|
|
"price": round(float(stock_price), 2),
|
|
|
|
"time": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
|
|
|
}
|
|
|
|
|
|
|
|
requests.post(os.getenv("API_URL") + '/symbol', json=payload, headers={'Authorization': 'Bearer ' + token})
|
|
|
|
except RuntimeError:
|
|
|
|
my_converter = CurrencyConverter()
|
|
|
|
|
|
|
|
search_result = investpy.search_quotes(text=s, products=['stocks'], n_results=1)
|
|
|
|
|
|
|
|
currency = str(search_result.retrieve_currency())
|
|
|
|
|
|
|
|
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
|
|
|
|
|
|
|
stock_price = my_converter.convert(float(recent_data.iloc[-1]["Close"]), str(currency), 'EUR')
|
2022-04-05 13:08:57 +00:00
|
|
|
|
|
|
|
payload = {
|
2022-05-09 12:22:17 +00:00
|
|
|
"isin": s,
|
|
|
|
"price": round(float(stock_price), 2),
|
2022-04-05 13:08:57 +00:00
|
|
|
"time": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
|
|
|
}
|
|
|
|
|
|
|
|
requests.post(os.getenv("API_URL") + '/symbol', json=payload, headers={'Authorization': 'Bearer ' + token})
|
|
|
|
|
|
|
|
|
2022-04-06 10:34:03 +00:00
|
|
|
def split(a, n):
|
|
|
|
k, m = divmod(len(a), n)
|
|
|
|
return (a[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n))
|
|
|
|
|
|
|
|
|
|
|
|
load_dotenv()
|
2022-04-05 13:08:57 +00:00
|
|
|
username = os.getenv('ADMIN_EMAIL')
|
|
|
|
password = os.getenv('ADMIN_PASSWORD')
|
|
|
|
|
|
|
|
token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": username, "password": password}).json()['data']['token']
|
|
|
|
|
|
|
|
response = requests.get(os.getenv("API_URL") + '/symbols', headers={'Authorization': 'Bearer ' + token}).json()['data']
|
|
|
|
|
2022-04-06 10:34:03 +00:00
|
|
|
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()
|
2022-04-05 13:08:57 +00:00
|
|
|
|
2022-04-06 10:34:03 +00:00
|
|
|
time.sleep(10)
|