Exemplo n.º 1
0
 def income_statement(stock_number):
     logger.info(f"Scraping the income statement of {stock_number}")
     res = requests.get(
         url.findata(stock_number, FinDataType.INCOME_STATEMENT.value),
         cookies=LANG_COOKIE,
     )
     return res.content
Exemplo n.º 2
0
 def daily_bulletin(date):
     logger.info(f"Scraping daily bulletin on {date}")
     res = requests.post(url.bulletin,
                         headers=JSON_HEADER,
                         cookies=LANG_COOKIE,
                         json={"d": date})
     return res.content
Exemplo n.º 3
0
 def wrapper(*args, recompute=False, **kwargs):
     if "verbose" in kwargs and kwargs["verbose"]:
         logger.disabled = not kwargs["verbose"]
     val = None
     key = func.__name__
     for arg in args:
         if isinstance(arg, str):
             key += "_" + arg
         elif isinstance(arg, int):
             key += "_" + str(arg)
     for cache in caches:
         enabled = cache.__class__.enabled
         if not enabled:
             continue
         if key in cache and not recompute:
             logger.info(f"Cache hit in {cache} for {key}")
             val = cache[key]
             break
     if val == None:
         val = func(*args, **kwargs)
     for cache in caches:
         enabled = cache.__class__.enabled
         if not enabled:
             continue
         if key not in cache or recompute:
             cache[key] = val
     return val
Exemplo n.º 4
0
 def __setitem__(self, key, value):
     if not JsonCache.cache_path.exists():
         JsonCache.cache_path.mkdir()
     with (JsonCache.cache_path /
           (key + self._file_extension)).open("w+") as file:
         logger.info(f"Saved {key} to disk")
         file.write(json.dumps(value))
Exemplo n.º 5
0
 def price_history(ticker):
     logger.info(f"Scraping the profile of {ticker}")
     res = requests.get(url.price_history(ticker),
                        headers={'content-type': 'application/json'})
     return res.content
Exemplo n.º 6
0
 def listing():
     logger.info(f"Scraping the listed companies page")
     res = requests.post(url.listing, )
     return res.content
Exemplo n.º 7
0
 def __getitem__(self, key):
     with (JsonCache.cache_path /
           (key + self._file_extension)).open() as file:
         logger.info(f"Loaded {key} from disk")
         return json.loads(file.read())