lumina-desktop / lumina

Lumina Desktop Environment
http://lumina-desktop.org
BSD 3-Clause "New" or "Revised" License
531 stars 116 forks source link

feature request: Weather Desktop / Panel Plugin #268

Open sk8harddiefast opened 8 years ago

sk8harddiefast commented 8 years ago

Hi. It would be nice to have a Weather Desktop and panel plugin like xfce4.

q5sys commented 7 years ago

The reason we do not already have this an an option already is that we've had trouble finding a good service that offered a free API to use. I think I've found one though, so hopefully we'll we able to get something coded sooner than later.

q5sys commented 7 years ago

I'm going to mark this as Help Wanted as Ken and I haven't had the time to get to this, and if someone else wants to tackle this it'd be awesome.
There are a few options:

1) Use the NOAA or WeatherUnderground API. This would require users to sign up on their own for their API token and then add that into the panel widget. 2) Use the Free API from the Norwegian Meteorological Institute http://api.met.no/weatherapi/documentation

The downside to #1 is that it requires a user to sign up on their own. The downside to #2 is that the free service may go away at any point in time.

jayveesea commented 7 years ago

NOAA has an existing service that might be of use found here, and the existing MenuScript could be hacked to display weather in a panel, below is an example. Yes, it's just a hack, but the MenuScript is a nice feature and if it was expanded with a little more functionality it could become more powerful.

#!/bin/sh
# uses curl and sed

# CONFIG #######################################################
# the XML location for NOAA weather
# see http://w1.weather.gov/xml/current_obs/ 

URL='http://w1.weather.gov/xml/current_obs/KDET.xml'

################################################################

DIR=`pwd`
XML="${DIR}/.wthr.xml"
ICN="${DIR}/.wthr.png"

#use curl to get weather XML
curl --silent ${URL} > $XML
#WTHR="$(curl --silent http://w1.weather.gov/xml/current_obs/KOZW.xml)"

#using sed extract out desired details, seems like there should be a way to do this wihout creating a file
location="$(sed -n 's|<location>\(.*\)</location>|\1|p' ${XML})"
observation_time="$(sed -n 's|<observation_time>\(.*\)</observation_time>|\1|p' ${XML})"
weather="$(sed -n 's|<weather>\(.*\)</weather>|\1|p' ${XML})"
temperature_string="$(sed -n 's|<temperature_string>\(.*\)</temperature_string>|\1|p' ${XML})"
wind_string="$(sed -n 's|<wind_string>\(.*\)</wind_string>|\1|p' ${XML})"
windchill_string="$(sed -n 's|<windchill_string>\(.*\)</windchill_string>|\1|p' ${XML})"
icon_url_base="$(sed -n 's|<icon_url_base>\(.*\)</icon_url_base>|\1|p' ${XML})"
icon_url_name="$(sed -n 's|<icon_url_name>\(.*\)</icon_url_name>|\1|p' ${XML})"
rm "${XML}"

#for some reason i'm getting spaces in sed's extraction, so for now...
icon_url_base="${icon_url_base#"${icon_url_base%%[![:space:]]*}"}"
icon_url_base="${icon_url_base%"${icon_url_base##*[![:space:]]}"}"
icon_url_name="${icon_url_name#"${icon_url_name%%[![:space:]]*}"}"
icon_url_name="${icon_url_name%"${icon_url_name##*[![:space:]]}"}"
#echo "$icon_url_base$icon_url_name"
curl --silent -o "${ICN}" "$icon_url_base$icon_url_name"

#build json output, it's going to be sorted
#start out with location
OUT=" \" LOCATION ${location} \" : { \"type\" : \"item\", \"icon\":\"${ICN}\", \"action\" : \"xdg-open ${URL}\"}"

#add weather
OUT=" ${OUT}, \"\+ CURRENTLY ${weather} \" : { \"type\" : \"item\", \"icon\":\"none\", \"action\" : \"xdg-open ${URL}\"}"

#add temperature
OUT=" ${OUT}, \"\+ TEMPERATURE ${temperature_string} \" : { \"type\" : \"item\", \"icon\":\"none\", \"action\" : \"xdg-open ${URL}\"}"

#add wind
OUT=" ${OUT}, \"\+ WIND ${wind_string} \" : { \"type\" : \"item\", \"icon\":\"none\", \"action\" : \"xdg-open ${URL}\"}"

#add windchill
OUT=" ${OUT}, \"\+ WIND CHILL ${windchill_string} \" : { \"type\" : \"item\", \"icon\":\"none\", \"action\" : \"xdg-open ${URL}\"}"

#add last update
OUT=" ${OUT}, \"\-${observation_time} \" : { \"type\" : \"item\", \"icon\":\"none\", \"action\" : \"xdg-open ${URL}\"}"

echo "{ ${OUT} }"
jayveesea commented 7 years ago

A more complete solution, still using NOAA, would be to use the http://forecast.weather.gov/MapClick.php service, by appending the latitude and longitude of the desired weather station to this link you can request the current conditions and forecast in a nice json or xml formatted response.

example: http://forecast.weather.gov/MapClick.php?lat=42.6273&lon=-83.992&FcstType=json

to get the latitude and longitude you could then use http://forecast.weather.gov/zipcity.php?inputstring= which will redirect to the correct url, and then strip off the latitude and longitude. Something like this:

#!/bin/sh
zip=48855
QRY="http://forecast.weather.gov/zipcity.php?inputstring=$zip"
ASK="$(curl -w '%{url_effective}\n' -I -L -s -S $QRY -o /dev/null)"
LL="${ASK#"${ASK%lat=*}"}"

BASE="http://forecast.weather.gov/MapClick.php?"
jsonResponse="curl --silent $BASE$LL&FcstType=json"

the response even has links to icons of the corresponding weather which can be used for the display.

markusalbertgraf commented 7 years ago

That forecast.weather.gov site seems to do US only.

lbartoletti commented 5 years ago

I think we should not limit ourselves to a single service. It would require several services (with options to integrate user/password). On the other hand, some will offer more information than others

For information, I use curl on wttr.in which uses wego https://github.com/schachmat/wego