Comments (17)
Thanks for reaching out. Can you please provide me the full station name from which you are trying to retrieve the data?
from simple_dwd_weatherforecast.
from simple_dwd_weatherforecast.
Ok, so then it might be related to connection problems. This error can only occur if there were retrieved no or only erroneous data. I could improve the error handling to make this more transparent and make troubleshooting more easily.
from simple_dwd_weatherforecast.
from simple_dwd_weatherforecast.
Oh, now I understand you. Can you please provide a code snippet which produces the error?
from simple_dwd_weatherforecast.
from simple_dwd_weatherforecast.
This hasn't worked unfortunately. The code is not visible for me. Can you please send me the snippet again?
from simple_dwd_weatherforecast.
from simple_dwd_weatherforecast.
Hi, first of all, sorry for the late replies. I was not at home. Unfortunately, I can't see your code. Can you please try to attach the code via the webbrowser instead of mail?
from simple_dwd_weatherforecast.
Hi, here is the code:
from geopy.geocoders import Nominatim
# Initialize Nominatim API
geolocator = Nominatim(user_agent="MyChatbot")
# For the weather forecast the dwd (Deutscher Wetter Dfrom simple_dwd_weatherforecast import dwdforecast
from simple_dwd_weatherforecast import dwdforecast
from datetime import datetime, timedelta, timezone
# Weather functions
# Return the location information for a given city name
def getLocation(name):
if name is None:
return None
try:
location = geolocator.geocode(name)
except:
global errorMessage
errorMessage = "Error while looking for location"
return None
return location
# Returns the weather (the temperature and the cloud coverage) for a location
# This is just an example. A lot of more values are possible.
def getWeather(location, time):
if location is None:
return None
# Attention: There is a bug in the simple_dwd_weatherforecast library. If you call the next functions multiple times for the
# same locationit crashes. I have sent a bug report to the developers on github.com.
try:
next_weather_station = dwdforecast.get_nearest_station_id(location.latitude, location.longitude)
if next_weather_station is not None:
print("Station ID found: ", next_weather_station)
dwd_weather = dwdforecast.Weather(next_weather_station)
# print("Looking for weather at ", next_weather_station, " for time ", time)
temperature = dwd_weather.get_forecast_data(dwdforecast.WeatherDataType.TEMPERATURE, time) - 273.16
cloud_coverage = dwd_weather.get_forecast_data(dwdforecast.WeatherDataType.CLOUD_COVERAGE, time)
return temperature, cloud_coverage
else:
return None
except:
global errorMessage
errorMessage = "Error while looking for weather"
return None, None
myLocation = getLocation('Altenstadt')
time_now = datetime.today()
time_tomorrow = datetime.today() + timedelta(days=+1)
print(getWeather(myLocation, time_now))
print(getWeather(myLocation, time_tomorrow))
from simple_dwd_weatherforecast.
Ok, I see. You are forcing a new init of the Weather class without actually requesting the new weather data. With your approach there will be a second request to the DWD server which is unnecessary, as the class stores the data for the next days in a single request.
Here is a modified version of your code, which performs your request:
from geopy.geocoders import Nominatim
# Initialize Nominatim API
geolocator = Nominatim(user_agent="MyChatbot")
# For the weather forecast the dwd (Deutscher Wetter Dfrom simple_dwd_weatherforecast import dwdforecast
from simple_dwd_weatherforecast import dwdforecast
from datetime import datetime, timedelta, timezone
# Weather functions
# Return the location information for a given city name
def getLocation(name):
if name is None:
return None
try:
location = geolocator.geocode(name)
except:
global errorMessage
errorMessage = "Error while looking for location"
return None
return location
class CustomWeather:
weather_station = None
def __init__(self, location):
next_station_id = dwdforecast.get_nearest_station_id(location.latitude, location.longitude)
print("Station ID found: ", next_station_id)
self.weather_station = dwdforecast.Weather(next_station_id)
def getWeather(self, time):
# print("Looking for weather at ", next_weather_station, " for time ", time)
temperature = round(self.weather_station.get_forecast_data(dwdforecast.WeatherDataType.TEMPERATURE, time) - 273.16, 2)
cloud_coverage = self.weather_station.get_forecast_data(dwdforecast.WeatherDataType.CLOUD_COVERAGE, time)
return temperature, cloud_coverage
myLocation = getLocation('Altenstadt')
# Init the CustomWeatherClass
myWeather = CustomWeather(myLocation)
time_now = datetime.today()
time_tomorrow = datetime.today() + timedelta(days=+1)
print(myWeather.getWeather(time_now))
print(myWeather.getWeather(time_tomorrow))
I hope this helps.
from simple_dwd_weatherforecast.
from simple_dwd_weatherforecast.
Ok. Glad you could resolve it. May I close this issue then?
from simple_dwd_weatherforecast.
from simple_dwd_weatherforecast.
I agree. But can you please give me then a code example which produces this error? I was unable to reproduce this.
from simple_dwd_weatherforecast.
from simple_dwd_weatherforecast.
You have found indeed a little bug, which will be fixed if I release the new version in a few days. However, I would like to advise not calling the same station_id from different Weather objects. The problem is, that there will be seperate calls to the DWD server which is avoided otherwise. Best regards
from simple_dwd_weatherforecast.
Related Issues (14)
- Data are downloaded on every get request HOT 11
- ICON-D2 for more precise 48h forecasts HOT 3
- Inquiry Regarding Sun Irradiance Values Returned by API HOT 1
- Deprecated forecast attribute HOT 1
- Issue with predefined station list (stations.json) HOT 2
- Wrong geographic coordinates in stations.json HOT 1
- Latitude and Longitude from DWD are not decimal values HOT 2
- The order of the requested layers does matter HOT 1
- Time shift at day change HOT 16
- Integration does not shown after install - ha version 0.117.2 HOT 1
- aktuelle Wettermesswerte HOT 4
- Typo in stations.py HOT 1
- KML parsing error HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple_dwd_weatherforecast.