51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
__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"
|
|
|
|
import datetime
|
|
import os
|
|
import threading
|
|
import time
|
|
|
|
import requests
|
|
import yfinance
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
def thread_function(s):
|
|
my_share_info = yfinance.Ticker(s)
|
|
my_share_data = my_share_info.info
|
|
|
|
if my_share_data['regularMarketPrice'] is not None:
|
|
payload = {
|
|
"symbol": s,
|
|
"price": float(my_share_data['regularMarketPrice']),
|
|
"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})
|
|
|
|
|
|
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()
|
|
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']
|
|
|
|
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)
|