def _parse_quote(self, quotes_dict): try: quotes = quotes_dict['indicators']['quote'][0] dates = quotes_dict['timestamp'] adj_close = quotes_dict['indicators']['adjclose'][0] except Exception as e: return None, YahooExceptions.YahooIndicatorNotFoundError(e) try: # Combine the two dictionaries. quote_dictionary = {**quotes, **adj_close} # Turn the dictionary into a dataframe. quote_dataframe = pd.DataFrame.from_dict(quote_dictionary) # Get the timestamp (datetime) for each quote entry in the data and parse it. quote_dataframe['date'] = dates quote_dataframe.reindex(columns=[ 'date', 'open', 'high', 'low', 'close', 'adjclose', 'volume' ]) except Exception as e: return None, YahooExceptions.YahooIndicatorFormatError(e) return quote_dataframe, None
def _parse_quote_splits(self, quotes_dict): try: # Get the splits dictionary from the JSON API output. splits_dict = quotes_dict['chart']['result'][0]['events']['splits'] except Exception as e: return None, YahooExceptions.YahooIndicatorNotFoundError(e) try: # Convert the splits dictionary to a Dataframe. splits_dataframe = pd.DataFrame.from_dict(splits_dict, orient='index') splits_dataframe.index = pd.Index( range(0, splits_dataframe.shape[0])) except Exception as e: return None, YahooExceptions.YahooIndicatorFormatError(e) return splits_dataframe, None