Weather Underground Plugin
-
- Experienced User
- Posts: 60
- Joined: Sun Apr 28, 2013 12:25 pm
Re: Weather Underground Plugin
Lame indeed. Looks like I need to update my skill set to HTML scraping
- kgschlosser
- Site Admin
- Posts: 5508
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Weather Underground Plugin
It's pretty simple to do.
if you open a webpage and click on view source. you will see the source code for the webpage.. In terms of weather I did a google search for local forecast.. and it brought up a link to weather.com with all the proper search parameters filled in for where I live. I used that URL and added some options to the URL so you would be able to specify your location.
I then opened the url in my browser. and then right clicked on the page and clicked on "View Source code". this showed me the raw data.. I scanned the source code looking for the information I wanted... It happened to be that this one was really simple because everything is stored in a JSON structure. so i needed to find a marker I could use at the start and at the end. where there is only a single occurrence of the start marker in the source. ctrl + F told me that. now that I had my start marker. i located the end of the structure which is a }; the brace and semicolon is not going to be in the structure at all. it will only appear at the end of it. so i did a find for the start marker.. then i did another find for the }; telling find to start at the position i got when i searched for the start. and that gave me the end of the structure.. fed it into the json library (json.loads()) and this spat out a python dict... and I know you know what that is.. from there just found the elements i wanted pulled them out and printed them
so enough of my babbling.. here is the code..
follow the instructions at the top of the code...
if you open a webpage and click on view source. you will see the source code for the webpage.. In terms of weather I did a google search for local forecast.. and it brought up a link to weather.com with all the proper search parameters filled in for where I live. I used that URL and added some options to the URL so you would be able to specify your location.
I then opened the url in my browser. and then right clicked on the page and clicked on "View Source code". this showed me the raw data.. I scanned the source code looking for the information I wanted... It happened to be that this one was really simple because everything is stored in a JSON structure. so i needed to find a marker I could use at the start and at the end. where there is only a single occurrence of the start marker in the source. ctrl + F told me that. now that I had my start marker. i located the end of the structure which is a }; the brace and semicolon is not going to be in the structure at all. it will only appear at the end of it. so i did a find for the start marker.. then i did another find for the }; telling find to start at the position i got when i searched for the start. and that gave me the end of the structure.. fed it into the json library (json.loads()) and this spat out a python dict... and I know you know what that is.. from there just found the elements i wanted pulled them out and printed them
so enough of my babbling.. here is the code..
follow the instructions at the top of the code...
Code: Select all
# you need to set these to get the proper forecast
ZIP_CODE = '80439'
COUNTRY = 'US'
LOCALE = 'en-US'
import requests
import json
response = requests.get('https://weather.com/weather/today/l/{0}:4:{1}'.format(ZIP_CODE, COUNTRY))
content = response.content
start = content.find('window.__data={') + 14
end = content.find('};', start) + 1
data = json.loads(content[start:end])
location = data['dal']['Location']['locId:{0}:4:{1}:locale:{2}'.format(ZIP_CODE, COUNTRY, LOCALE)]
hourly_forecast = data['dal']['HourlyForecast']
pollen_forecast = data['dal']['PollenForecast']
observation = data['dal']['Observation']
daily_forecast = data['dal']['DailyForecast']
print '*' * 40
print('LOCATION')
print '*' * 40
print json.dumps(location, indent=4)
print
print
print '*' * 40
print('HOURLY FORECAST')
print '*' * 40
print json.dumps(hourly_forecast, indent=4)
print
print
print '*' * 40
print('DAILY FORECAST')
print '*' * 40
print json.dumps(daily_forecast, indent=4)
print
print
print '*' * 40
print('POLLEN FORECAST')
print '*' * 40
print json.dumps(pollen_forecast, indent=4)
print
print
print '*' * 40
print('OBSERVATION')
print '*' * 40
print json.dumps(observation, indent=4)
-
- Experienced User
- Posts: 60
- Joined: Sun Apr 28, 2013 12:25 pm
Re: Weather Underground Plugin
OK I've got the data for my area. Under observation is the temperature:
10:08:05 AM "altimeter": 30,
10:08:05 AM "temperature": 58,
10:08:05 AM "uvDescription": "Moderate",
I 'm trying to get that into a variable to use and can't figure it out.
10:08:05 AM "altimeter": 30,
10:08:05 AM "temperature": 58,
10:08:05 AM "uvDescription": "Moderate",
I 'm trying to get that into a variable to use and can't figure it out.
- kgschlosser
- Site Admin
- Posts: 5508
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Weather Underground Plugin
Code: Select all
print observation['altimeter']
print observation['temperature']
print observation['uvDescription']
Code: Select all
print observation['layer1']['layer2']['data']
-
- Experienced User
- Posts: 60
- Joined: Sun Apr 28, 2013 12:25 pm
Re: Weather Underground Plugin
Thanks, The data was nested 4 deep.
print observation['geocode:32.82,-116.91:language:en-US:units:e']['data']['vt1observation']['temperature']
Works!
print observation['geocode:32.82,-116.91:language:en-US:units:e']['data']['vt1observation']['temperature']
Works!
- kgschlosser
- Site Admin
- Posts: 5508
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Weather Underground Plugin
anything else I can help you with??
Re: Weather Underground Plugin
https://api.weather.com/v2/pws/observat ... xxxxxxxxxx
I have this returning a json output in my browser, with my key that i get for uploading data from my personal weather station. Are there any updated plugins, or suggestions how to scrape the data into eventghost, please?
Cheers!
I have this returning a json output in my browser, with my key that i get for uploading data from my personal weather station. Are there any updated plugins, or suggestions how to scrape the data into eventghost, please?
Cheers!
- kgschlosser
- Site Admin
- Posts: 5508
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Weather Underground Plugin
I do not have an API key for weather underground. as it is now a pay service. If you need this plugin to work I can modify it but I would need the API key to be able to do it. Let me do some digging into it.
-
- Experienced User
- Posts: 133
- Joined: Thu Dec 10, 2015 12:09 am
Re: Weather Underground Plugin
kg! You've done some amazing work on this plugin and I and many others are thankful for it. It really sucks that weather underground folded their free api service. For now Open Weather Map is working though. Sadly it can only work in 10 minute increments but I suppose that is safer in some ways.
- kgschlosser
- Site Admin
- Posts: 5508
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Weather Underground Plugin
This is what happens when something that was free and OpenSource gets bought out by a corporate conglomerate (The Weather Channel)
-
- Experienced User
- Posts: 133
- Joined: Thu Dec 10, 2015 12:09 am
Re: Weather Underground Plugin
kgschlosser wrote: ↑Sat Jan 25, 2020 9:02 pmThis is what happens when something that was free and OpenSource gets bought out by a corporate conglomerate (The Weather Channel)
