detrous / darksky Goto Github PK
View Code? Open in Web Editor NEWPython API wrapper for the DarkSky (async&sync)
Home Page: https://pypi.org/project/darksky_weather/
License: MIT License
Python API wrapper for the DarkSky (async&sync)
Home Page: https://pypi.org/project/darksky_weather/
License: MIT License
Previously installed darksky_weather
via pip3
before this requirement. At the time aiohttp
was at around 3.6.1
or so, both my application and darksky_weather
functioned well.
Later, I go to recreate the environment on another system, only to end up in a world of broken dependencies because this aiohttp==3.5.4
requirement has appeared from nowhere, and the other libraries required aiohttp>=3.6.0
.
Installing darksky_weather
and forcing aiohttp==3.6.1
over the top of that has fixed my immediate problems, by why the dependency to this old and very specific version?
I'm having a problem getting the api to work in Linux. I used pip3 to install 1.7.1 on my Linux system (raspbian) and get a syntax error at api.py. I've been developing in windows on 1.5.1 and have had no issues. Just to be sure, I did pip3 installed 1.5.1 and get the same syntax error. I resorted to using your sample code with my API key and I get the same syntax error. Here's the trace I'm getting:
Traceback (most recent call last):
File "darkskyapp.py", line 1, in <module>
from darksky.api import DarkSky, DarkSkyAsync
File "/usr/local/lib/python3.5/dist-packages/darksky/api.py", line 15
self.api_key: str = api_key
can't access any attribute in the DailyForecast object other than summery and icon.
if i try accessing any other attribute i get an error stating thet it doesnt have this attribute for example: print(forecast.daily.time) AttributeError: 'DailyForecast' object has no attribute 'time'
I've been unable to access the .precip_type for the hourly and minutely forecast. For example, here is my code: print(forecast.hourly.data[0].precip_type)
I get the following error, showing that this is not part of the class: AttributeError: 'HourlyForecastItem' object has no attribute 'precip_type'
even though on forecast.py, it exists.
Describe the bug
Dark Sky, the provider on which this repo relies, will no longer accept new signups. The API will continue to function through the end of 2021.
To Reproduce
Steps to reproduce the behavior:
I put this on my repo:
Describe the bug
The asyncio session gets closed after the first request through the context manager
To Reproduce
Steps to reproduce the behavior:
session = aiohttp.ClientSession()
print('Start forecast')
forecast = await self.darksky.get_forecast(
latitude=CONFIG.location.latitude,
longitude=CONFIG.location.longitude,
lang='de',
client_session=session,
)
print(forecast.currently)
await asyncio.sleep(1)
print('Start forecast')
forecast = await self.darksky.get_forecast(
latitude=CONFIG.location.latitude,
longitude=CONFIG.location.longitude,
lang='de',
client_session=session,
)
print(forecast.currently)
output:
Start forecast
CurrentlyForecast(2020-04-19 06:24:43+02:00)
Start forecast
Error in func: Session is closed
Traceback (most recent call last):
File "C:\venv\lib\site-packages\darksky\api.py", line 139, in get_forecast
client_session=client_session,
File "C:\venv\lib\site-packages\darksky\request_manager.py", line 51, in make_request
url, params=params, headers=self.headers
File "C:\venv\lib\site-packages\aiohttp\client.py", line 1012, in __aenter__
self._resp = await self._coro
File "C:\venv\lib\site-packages\aiohttp\client.py", line 357, in _request
raise RuntimeError('Session is closed')
RuntimeError: Session is closed
Expected behavior
If a session is passed into the request it is not allowed to be closed
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
I am trying to make a storm direction indicator, however it looks as though this API does not include nearestStormBearing
Is your feature request related to a problem? Please describe.
Many libraries that expect weather data as an input use pandas dataframes as the standard data object (PVLib for example). Also, being able to return a pandas dataframe will make it easier to print, plot, and process data returned from darksky.
Describe the solution you'd like
A method called "to_frame()" which returns a DatetimeIndex'd dataframe of weather data.
weather = darksky.get_time_machine_forecast(...)
hourly_forecast_dataframe = weather.hourly.to_frame()
# print the start of the forecast
print(hourly_forecast_dataframe.head())
# plot the temperature
hourly_forecast_dataframe.plot(y='temperature')
Describe alternatives you've considered
Currently I use a function which accepts a forecast as an argument and returns a dataframe. This works just fine, but a built-in method would be nice."
Hi. Thanks for your package. I discovered it after looking to create my own home weather display.
I'm having trouble specifying the timezone when using the get_forecast
method from a DarkSky
object.
# nyc lat lon
lat = 40.7128
lon = 74.0060
darksky = DarkSky(API_KEY)
forecast = darksky.get_forecast(
lat, lon,
lang=languages.ENGLISH
)
I'm located in time zone US/Eastern (-5), but i'm getting Asia/Bishkek (+6).
Your GH profile says Ukraine which is +2, so also really confused where it's getting this particular timezone from. And according to darksky, they're located in Cambridge, MA (i.e., US/Eastern)...
>>> currently.time
datetime.datetime(2019, 12, 11, 5, 54, 58, tzinfo=<DstTzInfo 'Asia/Bishkek' +06+6:00:00 STD>)
I'm able to manually convert it
>>> forecast_time = currently.time.astimezone()
>>>
>>> fmt = "%Y-%m-%d %H:%M:%S %Z%z"
>>> print(forecast_time.strftime(fmt))
2019-12-10 18:54:58 Eastern Standard Time-0500
But that would require me to do this manual conversion for each forecast item, e.g.,
>>> forecast.hourly.data[0]
<darksky.forecast.HourlyForecastItem object at 0x0000029A24C7CAC0>
>>> hourly.data[0].time
datetime.datetime(2019, 12, 11, 5, 0, tzinfo=<DstTzInfo 'Asia/Bishkek' +06+6:00:00 STD>)
But ideally, we can specify the timezone during the API request.
I looked into the __ini__
functions for BaseDarkSky
and DarkSky
but they do not provide any way to input a timezone. The get_forecast
method returns a Forecast
object, but am I missing something about not being able to pass in a timezone: str
value? Or would I have to manually call the *Forecast
objects manually?
edit: On further investigation, it seems that it's capturing the correct lat/lon for the weather, but because the timezone is off, it's giving me weather values from around that time in the future.
For example it is not this cold (temp in F) at the moment (it's closer to 52F), and even if the units were in 27C, that would be around 80F....
>>> hourly.data[0].time
datetime.datetime(2019, 12, 11, 5, 0, tzinfo=<DstTzInfo 'Asia/Bishkek' +06+6:00:00 STD>)
>>> hourly.data[0].temperature
27.11
"Get started" instructions no longer work (nor do my existing programs using this code):
root@e8bf857ed40c:/workspace/src/weather/weatherWHAT# pip3 install darksky_weather
root@e8bf857ed40c:/workspace/src/weather/weatherWHAT# python3
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
from darksky.api import DarkSky, DarkSkyAsync
from darksky.types import languages, units, weatherAPI_KEY = 'xxxxxxxx'
darksky = DarkSky(API_KEY)
latitude = 42.3601
longitude = -71.0589
forecast = darksky.get_forecast(
... latitude, longitude,
... extend=False, # defaultFalse
... lang=languages.ENGLISH, # defaultENGLISH
... units=units.AUTO, # defaultauto
... exclude=[weather.MINUTELY, weather.ALERTS], # default[]
,
... timezone='UTC' # default None - will be set by DarkSky API automatically
... )
Traceback (most recent call last):
File "", line 7, in
TypeError: get_forecast() got an unexpected keyword argument 'units'
Hi,
I'd like to use your library but instead of requests I'd like to use aiohttp.
Edit:
It's not quite as simple as I have thought since the functions would have to be async functions which have to be awaited.
Maybe adding an option to pass the data after the http request to the DarkSky
instance would be an easy and clean solution?
Otherwise a check with
if asyncio.iscoroutinefunction(self.__request_manager.make_request):
data = await self.__request_manager.make_request(url, **params)
else:
data = self.__request_manager.make_request(url, **params)
could be a solution if the self.__request_manager is made non-private.
I have version 1.9.0 of the package installed using pip3. However, attempting to run my code with python3 results in:
Traceback (most recent call last):
File "log_cabin_control_server.py", line 12, in <module>
from darksky.api import DarkSky # Used for getting weather data from the Dark Sky API
ModuleNotFoundError: No module named 'darksky'
This code:
from darksky.api import DarkSkyAsync
import asyncio
client = DarkSkyAsync('DARKSKY_API_KEY')
loop = asyncio.new_event_loop()
loop.run_until_complete(client.get_forecast(40, -80))
raises this error from aiohttp
:
Traceback (most recent call last):
File "test.py", line 10, in <module>
loop.run_until_complete(client.get_forecast(40, -80))
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 608, in run_until_complete
return future.result()
File "/usr/local/lib/python3.8/site-packages/darksky/api.py", line 133, in get_forecast
data = await self.request_manager.make_request(
File "/usr/local/lib/python3.8/site-packages/darksky/request_manager.py", line 45, in make_request
async with self.session.get(url, params=params, headers=self.headers) as resp:
File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 1005, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 417, in _request
with timer:
File "/usr/local/lib/python3.8/site-packages/aiohttp/helpers.py", line 568, in __enter__
raise RuntimeError('Timeout context manager should be used '
RuntimeError: Timeout context manager should be used inside a task
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f90cd389d60>
This is because an event loop is attached to a ClientSession instance, so the DarkSkyAsync instance doesn't reference the event loop that is calling run_until_complete
, but some other non-running event loop that was attached when the client was initialized.
This is strange behavior, and I think it could create very confusing situations when multiple event loops are being used. It also means that this package is incompatible with pytest-asyncio (how I noticed the issue).
Rather than initializing a session when the client is initialized, a session should be initialized for each request, as shown in the aiohttp docs. Or, perhaps better would be for the DarkSkyAsync to have a session
method to be used much like ClientSession. Or get_forecast
could take a session as an argument. Many possibilities.
It appears, even after checking my VS Code install for:
It doesn't appear to be able to load.
thank you for creating this library it is definitely one of the better ones that wrap the dark sky API.
the only thing I find missing is the historical feature on the DS API.
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.