Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the currency at midnight raises ValueError. #15

hayd opened this issue Apr 20, 2015 · 4 comments

Getting the currency at midnight raises ValueError. #15

hayd opened this issue Apr 20, 2015 · 4 comments


Copy link

@hayd hayd commented Apr 20, 2015

It looks like (yahoo?) is returning a bad dateformat e.g. '4/21/2015 0:13am' Note: the 0 rather than 12 to indicate midnight. This means it isn't parseable with %I (which is used here).

In [1]: from yahoo_finance import Currency

In [2]: eur_pln = Currency("EURPLN")
ValueError                                Traceback (most recent call last)
<ipython-input-2-df89e7129008> in <module>()
----> 1 eur_pln = Currency("EURPLN")

/Users/andy/proj/yahoo-finance/yahoo_finance/ in __init__(self, symbol)
    147         self._table = 'xchange'
    148         self._key = 'pair'
--> 149         self.refresh()
    151     def _fetch(self):

/Users/andy/proj/yahoo-finance/yahoo_finance/ in refresh(self)
    139         """
--> 140         self.data_set = self._fetch()

/Users/andy/proj/yahoo-finance/yahoo_finance/ in _fetch(self)
    152         data = super(Currency, self)._fetch()
    153         if data['Date'] and data['Time']:
--> 154             data[u'DateTimeUTC'] = edt_to_utc('{0} {1}'.format(data['Date'], data['Time']))
    155         return data

/Users/andy/proj/yahoo-finance/yahoo_finance/ in edt_to_utc(date, mask)
     19     utc = pytz.utc
     20     eastern = pytz.timezone('US/Eastern')
---> 21     date_ = datetime.strptime(date, mask)
     22     date_eastern = eastern.localize(date_, is_dst=None)
     23     date_utc = date_eastern.astimezone(utc)

/Users/andy/anaconda/envs/py34/lib/python3.4/ in _strptime_datetime(cls, data_string, format)
    498     """Return a class cls instance based on the input string and the
    499     format string."""
--> 500     tt, fraction = _strptime(data_string, format)
    501     tzname, gmtoff = tt[-2:]
    502     args = tt[:6] + (fraction,)

/Users/andy/anaconda/envs/py34/lib/python3.4/ in _strptime(data_string, format)
    335     if not found:
    336         raise ValueError("time data %r does not match format %r" %
--> 337                          (data_string, format))
    338     if len(data_string) != found.end():
    339         raise ValueError("unconverted data remains: %s" %

ValueError: time data '4/21/2015 0:13am' does not match format '%m/%d/%Y %I:%M%p'
Copy link

@kris7ian kris7ian commented May 5, 2015

I'm experiencing exactly the same problem:

time data '5/6/2015 0:35am' does not match format '%m/%d/%Y %I:%M%p'

Copy link
Contributor Author

@hayd hayd commented May 5, 2015

One solution is just to replace the 0:.. with 12:...

In [11]: t, f = '4/21/2015 0:13am', '%m/%d/%Y %I:%M%p'

In [12]: datetime.datetime.strptime(t.replace(" 0:", " 12:"), f)
Out[12]: datetime.datetime(2015, 4, 21, 0, 13)

bit of a hack, but not sure there is a % for this.

hayd added a commit to hayd/yahoo-finance that referenced this issue May 5, 2015
Fix lukaszbanasiak#15.

yahoo returns a date of the form '4/21/2015 0:13am', rather than '4/21/2015 12:13am'.

There is not format to parse this so just replace it.
lukaszbanasiak added a commit that referenced this issue May 6, 2015
Copy link

@lukaszbanasiak lukaszbanasiak commented May 6, 2015

Merged and pubished in version 1.2.1
I have added test case for this.

thx! :)

Copy link

@kris7ian kris7ian commented May 6, 2015

Thanks a lot!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.