# Path: dynts/data/base.py
# class DataProvider:
#     '''Interface class for Data Providers.
# 
#     .. attribute:: code
# 
#         The string code for the provider.
#         This attribute is obtained from the class name in upper case.'''
# 
#     def __repr__(self):
#         return self.code + ' financial data provider'
# 
#     def load(self, symbol, startdate, enddate, logger, backend):
#         '''This is the function to implement.
#         It loads the actual data from the data rovider.
#         This function is not called directly, instead it is called by the
#         :meth:`dynts.data.TimeSerieLoader.load`.
# 
#         :parameter symbol: string id for the symbol to load (the ticker),
#                             including optional fields and providers.
#         :parameter startdate: start date of interval to load.
#         :parameter enddate: end date of interval to load.
#         :parameter logger: instance of :class:logging.Logger.
#         :parameter backend: :class:`dynts.TimeSeries` backend name.
# 
#         It should return either an instance of :class:`dynts.TimeSeries` or
#         a dictionary of the form::
# 
#             {'date': [list of dates],
#              'field1': [list of values for field1],
#              ...
#              'fieldN': [list of values for field1N]}
#         '''
#         raise NotImplementedError
# 
#     def isconnected(self):
#         '''Return ``True`` if data connection is available
#         '''
#         return True
# 
#     def __get_code(self):
#         return self.__class__.__name__.upper()
#     code = property(fget=__get_code)
# 
#     def allfields(self, ticker=None):
#         '''Return a list of all fields available for the providers.
# The first of the list will be treated as the default field.'''
#         raise NotImplementedError
# 
#     def weblink(self, ticker):
#         '''Optional web link for a given *ticker*. Default return ``None``.
#         '''
#         return None
# 
#     def external(self):
#         return True
# 
#     def hasfeed(self, live=False):
#         return not live
# 
#     def connect(self):
#         pass


import csv
            import requests
from io import StringIO
from ccy import dateFromString
from .base import DataProvider


    def string_to_date(self, sdte):
        return dateFromString(sdte)

    def request(self, url):
        response = self.http.get(url)
        if response.status_code == 200:
            return StringIO(response.text)

    def rowdata(self, ticker, startdate, enddate):
        url = self.hystory_url(str(ticker), startdate, enddate)
        res = self.request(url)
        if res:
            return csv.DictReader(res)

    def hystory_url(self, ticker, startdate, enddate, field = None):
        raise NotImplementedError

    def allfields(self, ticker = None):
        return ['Close','Open','Low','High','Volume']

    def load(self, symbol, startdate, enddate, logger, backend, **kwargs):
        ticker = symbol.ticker
        field  = symbol.field
        data = self.rowdata(ticker, startdate, enddate)
        if not data:
            return

        fields = {}
        datestr = None

# Path: dynts/data/base.py
# class DataProvider:
#     '''Interface class for Data Providers.
# 
#     .. attribute:: code
# 
#         The string code for the provider.
#         This attribute is obtained from the class name in upper case.'''
# 
#     def __repr__(self):
#         return self.code + ' financial data provider'
# 
#     def load(self, symbol, startdate, enddate, logger, backend):
#         '''This is the function to implement.
#         It loads the actual data from the data rovider.
#         This function is not called directly, instead it is called by the
#         :meth:`dynts.data.TimeSerieLoader.load`.
# 
#         :parameter symbol: string id for the symbol to load (the ticker),
#                             including optional fields and providers.
#         :parameter startdate: start date of interval to load.
#         :parameter enddate: end date of interval to load.
#         :parameter logger: instance of :class:logging.Logger.
#         :parameter backend: :class:`dynts.TimeSeries` backend name.
# 
#         It should return either an instance of :class:`dynts.TimeSeries` or
#         a dictionary of the form::
# 
#             {'date': [list of dates],
#              'field1': [list of values for field1],
#              ...
#              'fieldN': [list of values for field1N]}
#         '''
#         raise NotImplementedError
# 
#     def isconnected(self):
#         '''Return ``True`` if data connection is available
#         '''
#         return True
# 
#     def __get_code(self):
#         return self.__class__.__name__.upper()
#     code = property(fget=__get_code)
# 
#     def allfields(self, ticker=None):
#         '''Return a list of all fields available for the providers.
# The first of the list will be treated as the default field.'''
#         raise NotImplementedError
# 
#     def weblink(self, ticker):
#         '''Optional web link for a given *ticker*. Default return ``None``.
#         '''
#         return None
# 
#     def external(self):
#         return True
# 
#     def hasfeed(self, live=False):
#         return not live
# 
#     def connect(self):
#         pass


# Path: dynts/data/gy.py
import csv
            import requests
from io import StringIO
from ccy import dateFromString
from .base import DataProvider


    def string_to_date(self, sdte):
        return dateFromString(sdte)

    def request(self, url):
        response = self.http.get(url)
        if response.status_code == 200:
            return StringIO(response.text)

    def rowdata(self, ticker, startdate, enddate):
        url = self.hystory_url(str(ticker), startdate, enddate)
        res = self.request(url)
        if res:
            return csv.DictReader(res)

    def hystory_url(self, ticker, startdate, enddate, field = None):
        raise NotImplementedError

    def allfields(self, ticker = None):
        return ['Close','Open','Low','High','Volume']

    def load(self, symbol, startdate, enddate, logger, backend, **kwargs):
        ticker = symbol.ticker
        field  = symbol.field
        data = self.rowdata(ticker, startdate, enddate)
        if not data:
            return

        fields = {}
        datestr = None

        dates = []
