def __request(symbol): response = yql.YQLQuery().execute('select * from yahoo.finance.quotes where symbol = "{0}"'.format(symbol)) try: return response['query']['results'] except KeyError: try: raise YQLQueryError(response['error']['description']) except KeyError: raise YQLResponseMalformedError()
def __request_historical(symbol, start_date, end_date): response = yql.YQLQuery().execute( 'select * from yahoo.finance.historicaldata where symbol = "{0}" ' 'and startDate = "{1}" and endDate = "{2}"'.format(symbol, start_date, end_date) ) try: return response['query']['results'] except KeyError: try: raise YQLQueryError(response['error']['description']) except KeyError: raise YQLResponseMalformedError()
def _request(self, query): response = yql.YQLQuery().execute(query) try: results = response['query']['results'].itervalues().next() except (KeyError, StopIteration): try: raise YQLQueryError(response['error']['description']) except KeyError: raise YQLResponseMalformedError() else: if self._is_error_in_results(results): raise YQLQueryError(self._is_error_in_results(results)) self._change_incorrect_none(results) return results