marians / openweather

Rudimentary python client for OpenWeatherMap.org
9 stars 4 forks source link

ValueError: Invalid format string on Windows 7 with Python 2.7.8 #6

Open johnjohndoe opened 9 years ago

johnjohndoe commented 9 years ago

I am trying to run the library on Windows 7 having Python 2.7.8 installed. It basically works. When I use the -d parameter to specify a date the following error occurs:

$ openweather -s 4885 -d 20131022
Traceback (most recent call last):
  File "D:\Wetter\openweather.py", line 235, in <module>
    main()
  File "D:\Wetter\openweather.py", line 225, in main
    resolution="hour")
  File "D:\Wetter\openweather.py", line 76, in get_historic_weather
    from_ts = int(from_date.strftime('%s'))
ValueError: Invalid format string

This post might be helpful.

marians commented 9 years ago

Thanks for the notice! Please note that I'm not able to test code against Windows. But maybe someone could send a pull request.

johnjohndoe commented 9 years ago

@ptrv Do you know how to fix this so it works for Windows too?

ptrv commented 9 years ago

@johnjohndoe What kind of format is %s? It's not in the list here https://docs.python.org/2/library/time.html#time.strftime

johnjohndoe commented 9 years ago

Probably seconds in unix time? @marians Can you tell the truth?

ptrv commented 9 years ago

A bit of googling: http://stackoverflow.com/a/11743262

Python doesn't actually support %s as an argument to strftime (if you check at http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior it's not in the list), the only reason it's working is because Python is passing the information to your system's strftime, which uses your local timezone.

The usage of strftime("%s") is platform dependent and seems to not work on windows.

johnjohndoe commented 9 years ago

@ptrv Thank you for the research.