Giter VIP home page Giter VIP logo

darkskylib's People

Contributors

lukaskubis avatar shakefu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

darkskylib's Issues

ModuleNotFoundError: No module named 'core'

I copied and pasted the bottom sample code, and each time I try to run it I keep getting this error

ModuleNotFoundError: No module named 'core'
I am running python 3.6.3, and I tried doing 'pip install core' but nothing worked.

Is there any way to fix this?

v0.3.6 throws TypeError: '_GeneratorContextManager' object is not subscriptable

Hello,
v0.3.6 doesn't seem to work anymore - example code:

from darksky import forecast
key='APIKEY'
boston = forecast(key, 42.3601, -71.0589)
boston['currently']

and then I get this traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '_GeneratorContextManager' object is not subscriptable

Downgraded to v0.3.5 and it worked again.

can you explain the code in data.py? maybe it wrong.

I am new to python. and I copy your code in my editor.

...
class DataBlock(DataPoint):
    def __iter__(self):
        return self.data.__iter__()

    def __getitem__(self, index):
        # keys in darksky API datablocks are always str
        if isinstance(index, str):
            return self._data[index]
        return self.data.__getitem__(index)

    def __len__(self):
        return self.data.__len__()
...

but it says:
the instance of 'DataBlock' has no 'data' member. maybe '_data'?
is there should assign it before use?
is an error or your intent.

Great job!

Love the app, just testing out "issues" on other people's pages.

No module named 'core'

Hi, I have issue with python code. When I try to start program "no module named 'core'" error happens.
from core.config import CoreConfig ModuleNotFoundError: No module named 'core'
this is a part of code:
image
I did install darkskylib, but nothing happened

forecast method returned object is un-picklable

The weather forecast data returned by forecast method, if written to disk as pickle files, later are unreadable due to :
RecursionError: maximum recursion depth exceeded while calling a Python object

To reproduce simply save forecast returned object as pickle and try to read it.

ModuleNotFoundError: No module named 'core' (again!)

I see this was a previous issue that was closed, but I was not able to resolve it with that thread so I'm hoping to get some help yet again.

This issue only began today, I went to run my program (which was fine a couple of days ago) and I got the following error:

  File "/home/evitali/Projects/analytics/src/analytics/utils/darkskyData.py", line 1, in <module>
    from darksky.api import DarkSky
  File "/home/evitali/Projects/venv/20190917/lib/python3.6/site-packages/darksky/__init__.py", line 1, in <module>
    from core import *
ModuleNotFoundError: No module named 'core'

Trying to simply import darksky on its own yields the same thing:

Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import darksky
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/evitali/Projects/venv/20190917/lib/python3.6/site-packages/darksky/__init__.py", line 1, in <module>
    from core import *
ModuleNotFoundError: No module named 'core'

Here are the contents of /home/evitali/Projects/venv/20190917/lib/python3.6/site-packages/darksky/:

├── api.py
├── base.py
├── core.py
├── data.py
├── exceptions.py
├── forecast.py
├── __init__.py
├── __pycache__
│   ├── api.cpython-36.pyc
│   ├── base.cpython-36.pyc
│   ├── core.cpython-36.pyc
│   ├── data.cpython-36.pyc
│   ├── exceptions.cpython-36.pyc
│   ├── forecast.cpython-36.pyc
│   ├── __init__.cpython-36.pyc
│   ├── request_manager.cpython-36.pyc
│   └── utils.cpython-36.pyc
├── request_manager.py
├── types
│   ├── __init__.py
│   ├── languages.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── languages.cpython-36.pyc
│   │   ├── units.cpython-36.pyc
│   │   └── weather.cpython-36.pyc
│   ├── units.py
│   └── weather.py
└── utils.py

where you can see core.py is clearly in the same top-level directory as __init__.py

Things I have tried

  1. Upgrading darksky and darkskylib

I was already on the latest version.

  1. Reading and implementing the solution discussed here

Specifically, changing the line in __init__.py to:

  • from .core import *
  • from darksky.core import *

Neither of which solved the problem and both resulted this Traceback:

Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import darksky
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/evitali/Projects/venv/20190917/lib/python3.6/site-packages/darksky/__init__.py", line 1, in <module>
    from darksky.core import *
  File "/home/evitali/Projects/venv/20190917/lib/python3.6/site-packages/darksky/core.py", line 8, in <module>
    import mapq
  File "/home/evitali/Projects/venv/20190917/lib/python3.6/site-packages/mapq/__init__.py", line 1, in <module>
    from .core import key, address, batch, geocode, latlng, reverse
  File "/home/evitali/Projects/venv/20190917/lib/python3.6/site-packages/mapq/core.py", line 5, in <module>
    from .geo import Geo
  File "/home/evitali/Projects/venv/20190917/lib/python3.6/site-packages/mapq/geo.py", line 8, in <module>
    from urllib import unquote
ImportError: cannot import name 'unquote'

At this point I am at a loss. Any insight is appreciated

Edit: Looking at your repository, it seems that core.py is not even part of it anymore? But the last commit was almost 2 years ago and this problem began for me today and was talked about last year in Issue #4

ImportError: cannot import name forecast

I installed via:

$ sudo pip uninstall darksky && pip install darkskylib --upgrade --no-cache- --force-reinstall

and get the following error:

$ python darksky_example.py 
Traceback (most recent call last):
  File "darksky_example.py", line 1, in <module>
    from darksky import forecast
  File "darksky_example.py", line 4, in <module>
    from darksky import forecast
ImportError: cannot import name 'forecast'

Using this exact code:

from darksky import forecast
from datetime import date, timedelta

BOSTON = 42.3601, 71.0589

weekday = date.today()
with forecast('API_KEY', *BOSTON) as boston:
    print(boston.daily.summary)
    for day in boston.daily:
        day = dict(day = date.strftime(weekday, '%a'),
                   sum = day.summary,
                   tempMin = day.temperatureMin,
                   tempMax = day.temperatureMax
                   )
        print('{day}: {sum} Temp range: {tempMin} - {tempMax}'.format(**day))
        weekday += timedelta(days=1)

Info: Python 3.6.9

Problem with alerts

Hello - anyone still working on this?

I seem to be having trouble with alerts.

Based on the exact example language (as I am just fiddling around as I begin my project), I have:

alerts = oneonta.alerts[0].title

This then returns the following error:

Traceback (most recent call last):
  File "cloudweathertest.py", line 41, in <module>
    getWeather()
  File "cloudweathertest.py", line 37, in getWeather
    alerts = oneonta.alerts[0].title
  File "/usr/local/lib/python3.5/dist-packages/darksky/forecast.py", line 27, in              __getattr__
    return object.__getattribute__(self, key)
AttributeError: 'Forecast' object has no attribute 'alerts'

Reuse requests session between calls

Turning on logs for urllib3 indicates that darkskylib does not re-use the HTTP session between calls to the darksky server:

2019-11-06 13:32:20,518 18047-140558302398272 urllib3.connectionpool [connectionpool.py:959] : DEBUG: Starting new HTTPS connection (1): api.darksky.net:443 2019-11-06 13:32:20,865 18047-140558302398272 urllib3.connectionpool [connectionpool.py:437] : DEBUG: https://api.darksky.net:443 "GET /forecast/<api_key>/53.569008,-2.193415,2019-11-06T00:00:00+00:00?exclude=currently%2Cminutely%2Cdaily%2Calerts%2Cflags&lang=en&units=si HTTP/1.1" 200 None 2019-11-06 13:32:20,892 18047-140558302398272 urllib3.connectionpool [connectionpool.py:959] : DEBUG: Starting new HTTPS connection (1): api.darksky.net:443 2019-11-06 13:32:21,197 18047-140558302398272 urllib3.connectionpool [connectionpool.py:437] : DEBUG: https://api.darksky.net:443 "GET /forecast/<api_key>/53.575094,-2.08528,2019-11-06T00:00:00+00:00?exclude=currently%2Cminutely%2Cdaily%2Calerts%2Cflags&lang=en&units=si HTTP/1.1" 200 None 2019-11-06 13:32:21,221 18047-140558302398272 urllib3.connectionpool [connectionpool.py:959] : DEBUG: Starting new HTTPS connection (1): api.darksky.net:443 2019-11-06 13:32:21,418 18047-140558302398272 urllib3.connectionpool [connectionpool.py:437] : DEBUG: https://api.darksky.net:443 "GET /forecast/<api_key>/53.574674,-2.139347,2019-11-06T00:00:00+00:00?exclude=currently%2Cminutely%2Cdaily%2Calerts%2Cflags&lang=en&units=si HTTP/1.1" 200 None 2019-11-06 13:32:21,439 18047-140558302398272 urllib3.connectionpool [connectionpool.py:959] : DEBUG: Starting new HTTPS connection (1): api.darksky.net:443 2019-11-06 13:32:21,706 18047-140558302398272 urllib3.connectionpool [connectionpool.py:437] : DEBUG: https://api.darksky.net:443 "GET /forecast/<api_key>/53.556223,-2.178783,2019-11-06T00:00:00+00:00?exclude=currently%2Cminutely%2Cdaily%2Calerts%2Cflags&lang=en&units=si HTTP/1.1" 200 None

Is it possible to allow reuse of HTTP connections in darkskylib?

Possibility to pass more parameters

Hello, thank you for the library, it's a nice work :)

I'm writing you because I would like to pass additional parameters like "&units=si" to directly get values in Celsius and m/s, or to change the language for the summary.

I could not find how to do this through your library, perhaps I'm just too dumb... If not, can you add this possibilities in a future update?

Thank you!

HTTPError: Bad response when making requests in loop

I am getting a

HTTPError: Bad response

I was so free to actually get the correct error code. It is a 400 bad request code.

It seems it only happens when I use a loop through my pandas dataframe instances because when I run my code for a single instance I am getting the correct values as well as when I am using a direct URL request in my browser.

Here is my function which is called later (with df being the dataframe)

def engineer_features(df):
    from datetime import datetime as dt
    from darksky import forecast

    print("Add weather data...")
    
    # Add Windspeed
    df['ISSTORM'] = 0
    
    # Add Temperature
    df['ISHOT'] = 0
    df['ISCOLD'] = 0
    
    # Add Precipitation probability 
    #    (because the weather station is not at the coordinate of the taxi 
    #    only a probability is added, but in regard to the center of Porto 
    #    (because else the API calls would have been costly))
    df['PRECIPPROB'] = 0
    
    # sort data frame
    data_times = df.sort_values(by='TIMESTAMP')
    
    # initialize variable for previous day's date day (day before the first day)
    prevDay = data_times.at[0,'TIMESTAMP'].date().day - 1
    
    #initialize hour counter
    hourCount = 0
    
    # add personal DarkSky API key and asssign with location data
    key = 'MYKEY'
    PORTO = key, 41.1579, -8.6291
    
    # loop through the sorted dataframe and add weather related data to the main dataframe
    for index, row in data_times.iterrows():
        
        # if the new row is a new day make a new API call for weather data of that new day
        if row["TIMESTAMP"].day != prevDay:
            
            # get Weather data
            t = row["TIMESTAMP"].date().isoformat()
            porto = forecast(*PORTO, time=t)
            porto.refresh(units='si')
           
        ###...more code

No way to add timeout to request

I run into this code locking up if API endpoint are not available. requests.get() supports timeout parameter, but it is not used and I see no way to set it.

Feature Request: Add option to enable HTTP compression

From the DarkSky docs (https://darksky.net/dev/docs/response):

The Forecast Data API supports HTTP compression. We heartily recommend using it, as it will make responses much smaller over the wire. To enable it, simply add an Accept-Encoding: gzip header to your request. (Most HTTP client libraries wrap this functionality for you, please consult your library’s documentation for details.)

The requests library can do this, but it seems that the option needs to be built into the library.

http://docs.python-requests.org/en/master/user/quickstart/#custom-headers

I could probably submit a PR for this but I don't have a timeline.

forecast is not callable

Can I get some help with the following issue.
from darksky import forecast
key = 'key_value'
boston = forecast(key, 42.3601, -71.0589)

Obtain the following error:
TypeError Traceback (most recent call last)
in
1 key = 'key_value'
----> 2 boston = forecast(key, 42.3601, -71.0589)

TypeError: 'module' object is not callable

Seem to be missing precipType

Hi - i just found this repository and setup a bit of code to pull the data for my neighborhood. I am somewhat naive to Python programming but think i generally have things setup right.

I got an error when i requested precipType attribute which appears in the DarkSky API docs.

Traceback (most recent call last):
File "sky_data_colletion.py", line 54, in
process_darksky()
File "sky_data_colletion.py", line 30, in process_darksky
for_precip_type = home_forecast.precipType
File "build/bdist.linux-armv7l/egg/darksky/forecast.py", line 27, in getattr

Here's a code snippet surrounding this - other calls work and when i comment out that line the entire code executes and prints out the relevant ozone levels:

for_summary = home_forecast.summary
for_nearest_storm = home_forecast.nearestStormDistance
for_precip_intensity = home_forecast.precipIntensity
for_precip_probability = home_forecast.precipProbability
**### #    for_precip_type = home_forecast.precipType**
for_temperature = home_forecast.temperature
for_apparent_temperature = home_forecast.apparentTemperature
for_dew_point = home_forecast.dewPoint
for_humidity = home_forecast.humidity
for_bar_pressure = home_forecast.pressure
for_wind_speed = home_forecast.windSpeed
for_wind_gust = home_forecast.windGust
for_windBearking = home_forecast.windBearing
for_cloud_cover = home_forecast.cloudCover
for_uv_index = home_forecast.uvIndex
for_visibility = home_forecast.visibility
for_ozone = home_forecast.ozone

print ("Ozone {0}".format(for_ozone))

add units option

please add the '?units=si' or other options for the unit conversion. Thanks.

How to fill missing historical data between two dates

When there is no data for a specific date inside the queried range, it gives a "KeyError: 'temperature'. I would like to add some logic to avoid this error by fill the missing dates with NaN, and completing the query.

For now, I've been fetching the last date from the previous query, and running a new query starting from the time from the last query. This is pretty cumbersome and involves a lot of guess and check.

# grab only weather of interest
attributes = [u'temperature', u'humidity']
#initalize
times = []
data = {}
for attr in attributes:
    data[attr] = []

# Start date date 
date = datetime.datetime(2019, 3, 1, 0, 0)


for offset in range(1, 2): #range is in hours
    forecast = forecastio.load_forecast(api_key, lon, lat, time=date+datetime.timedelta(offset), units = 'ca' )
    h = forecast.hourly() # get forecase
    d = h.data # d = forecastio.models.ForecastioDataPoint
    for p in d:
        times.append(p.time)
        for i in attributes:
            try:
                data[i].append(p.d[i]) # try to append temp/humid data to timestamped list
            except KeyError as e:
                # FILL missing temp data from API with Nan until there is data 
                print(e.message) # printing error for now,

#Covernt to dataframe 
df1 = pd.DataFrame(data)
df2 = pd.DataFrame(times)

df = pd.concat([df1, df2], axis=1)

I expect the outputting dataframe of times to be the hours between the requested timedelta date-range, and the times df to be populated with the API's temperature data, or NaNs if there was not any data available.

How to get historical data

I couldn't find in the documentation an example on how to retrieve historical data for a time range.
Is this possible?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.