dvdme / forecastiopy Goto Github PK
View Code? Open in Web Editor NEWA Python wrapper for the forecast.io API.
License: Eclipse Public License 1.0
A Python wrapper for the forecast.io API.
License: Eclipse Public License 1.0
xrange needs to move to range for python3. #7
Thanks for this library and your efforts! ๐
Looking into your source code, I would kindly suggest to replace all print calls with Python's logging module for the following reasons:
Your code uses print
a lot. For example, in file ForecastIO.py, there are a couple of print
s. IMHO, I see the following problems with this approach:
print
, redirect your output to stderr like this: print("error:", err, file=sys.stderr)
So better use logging.error
instead of print as stated above. ๐
>>> fio = ForecastIO.ForecastIO("fds", latitude=83.6906, longitude=-39.4176)
The API Key doesn't seam to be valid.
>>> fio
<forecastiopy.ForecastIO.ForecastIO object at 0x7f573b300940>
>>> FIODaily.FIODaily(fio)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/kousu/.local/lib/python3.4/site-packages/forecastiopy-0.1-py3.4.egg/forecastiopy/FIODaily.py", line 20, in __init__
if forecast_io.has_daily():
File "/home/kousu/.local/lib/python3.4/site-packages/forecastiopy-0.1-py3.4.egg/forecastiopy/ForecastIO.py", line 204, in has_daily
return 'daily' in self.forecast
AttributeError: 'ForecastIO' object has no attribute 'forecast'
The real mistake here is that the API key is wrong, but the exception that actually crashes is obscure and makes it seem like maybe there's a library version mismatch or something else frustratingly impossible to fix. I wrote a largish script, ported it to a new host, and accidentally misimported my API key, so I didn't notice the first message and was focusing on the second exception.
Would you make that initial line into an exception instead of just a print?
In FIODaily, day_1_* is actually day 8 and everything else is shifted by 1:
# daily_cycle_bug.py
from forecastiopy import *
import time
YOUR_API_KEY = open("FORECASTIO_API_KEY.txt").read().strip()
location=[25.5, -83.566667]
fio = ForecastIO.ForecastIO(YOUR_API_KEY, latitude=location[0], longitude=location[1])
d = FIODaily.FIODaily(fio)
print(time.ctime(d.day_1_time))
print(time.ctime(d.day_2_time))
print(time.ctime(d.day_3_time))
print(time.ctime(d.day_4_time))
print(time.ctime(d.day_5_time))
print(time.ctime(d.day_6_time))
print(time.ctime(d.day_7_time))
print(time.ctime(d.day_8_time))
output:
$ python daily_cycle_bug.py
Mon Sep 5 00:00:00 2016
Mon Aug 29 00:00:00 2016
Tue Aug 30 00:00:00 2016
Wed Aug 31 00:00:00 2016
Thu Sep 1 00:00:00 2016
Fri Sep 2 00:00:00 2016
Sat Sep 3 00:00:00 2016
Sun Sep 4 00:00:00 2016
I'm trying to exclude daily,alerts etc and can't seem to get the syntax correct.
I've tried: excludeList = ['daily,alerts,flags'] and this excludeList = 'daily,alerts,flags'
and
fio = ForecastIO.ForecastIO(apikey,exclude=excludeList,
units=ForecastIO.ForecastIO.UNITS_US,
lang=ForecastIO.ForecastIO.LANG_ENGLISH,
latitude=Prado[0], longitude=Prado[1])
and this
fio = ForecastIO.ForecastIO(apikey,
units=ForecastIO.ForecastIO.UNITS_US,
lang=ForecastIO.ForecastIO.LANG_ENGLISH,
latitude=Prado[0], longitude=Prado[1],
exclude=excludeList )
The results are always
https://api.darksky.net/forecast/apikey/lattitude,longittude?units=us&lang=en
Appreciate your help
Traceback (most recent call last):
File "/home/olaf/.local/lib/python2.7/site-packages/flask/app.py", line 2000, in __call__
return self.wsgi_app(environ, start_response)
File "/home/olaf/.local/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/olaf/.local/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/olaf/.local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/home/olaf/.local/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/olaf/.local/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/olaf/.local/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/home/olaf/.local/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/olaf/Hackathons/Brumhack5/BrumHack5/jasien.py", line 49, in checkStuff
weatherResult = getWeather(message_body_split[1])
File "/home/olaf/Hackathons/Brumhack5/BrumHack5/jasien.py", line 26, in getWeather
current = FIOCurrently.FIOCurrently(fio)
File "/usr/local/lib/python2.7/dist-packages/forecastiopy/FIOCurrently.py", line 25, in __init__
if forecast_io.has_currently():
File "/usr/local/lib/python2.7/dist-packages/forecastiopy/ForecastIO.py", line 185, in has_currently
return 'currently' in self.forecast
AttributeError: 'ForecastIO' object has no attribute 'forecast'
Are you planning to implement a time-machine request of the API?
Thanks,
3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.