from logging import error, warn import os import json import time import urllib.request import requests from requests.models import HTTPError from Helper import logmngr as log, configmngr as config from DataConnector.EODHistData import common _logo_file_path = config.get_config('database', 'filesys-logo-path') log = log.get_logger() def get_index_constituents(index, incl_delist=False, only_ticker=True): log.info("request constituents of %s", index) url = common.baseurl_fundamental + index + '?' + \ "api_token=" + common.apitoken + "&fmt=json" log.info(url) result = requests.get(url).json() if not incl_delist: result = result["Components"] else: result = result["HistoricalTickerComponents"] if only_ticker: tickers = [] for i in result: entry = result[i] tickers.append(entry["Code"] + "." + entry["Exchange"]) result = tickers
import DataConnector.EODHistData.fundamentals_connector as eodhd import DBConnector.mongoconnector as mongo from Helper import logmngr, internalfilewriter as ifw log = logmngr.get_logger() US_EXCHANGE_DETAIL = False # Global Data for all US Exchanges def update_fundamentals(tickers): if isinstance(tickers, str): tickers = [tickers] start_len = len(tickers) end_len = 0 for ticker in tickers: # Workaround, check also last import date!!!! if mongo.check_fundamentals_ticker_exists(ticker): log.info("ticker %s allready imported", ticker) end_len += 1 continue try: data = eodhd.get_stock_fundamentals(ticker) except RuntimeError as r_e: log.error("Could not receive data for %s %s", ticker, r_e) continue try: mongo.update_stock_fundamentals(ticker, data) except RuntimeError as r_e: log.error("Could not add data for %s to database %s", ticker, r_e) continue end_len += 1