Conky and Wunderground Weather

0

I am editing my question for clarification... I am sorry for any confusion... The Conky syntax has changed with the latest version (I assumed users of the latest version of Conky was aware of that).

My Problem Clarified:

I create an xml file that takes weather information from Wunderground.com.

I would prefer to find a simple way to extract specific information out of the xml file to display in Conky (including the weather icon).

Most information I have found so far does not do what I need, and I can't cobble together my own solution from what I have found because the information seems needlessly complex. I want the method used to not require a lot of extra programs and/or scripting gymnastics.

Example:

  1. I use "curl -s http://api.wunderground.com/api/[key]/conditions/q/TX/[mycity].xml -o ~/path/weather.xml" to create my xml file using Wunderground.com.

  2. Within the xml file is the path to the current weather's icon (Let us say: "http://icons.wxug.com/i/c/k/cloudy.gif")

  3. Within the xml file is specific data I want to display, such as the current temperature (the xml files shows '<'temp_f'>'68.9'<'/temp_f'>'"... Note: I am using '<' otherwise my post won't show the tag). Therefore, I would like to take the 68.9 and display it (or round it to 69).

In the end, using the example above, my Conky would then show a "Cloudy" Icon, and 69F (or 68.9F). I could then (easily I hope) extract and display other information in a similar fashion.

Thank you in advance for any help you can offer.

Curtis

Posted 2017-09-27T22:19:01.550

Reputation: 33

1We are not actually aware.... – Ramhound – 2017-09-27T22:39:24.070

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. – Ramhound – 2017-09-27T22:41:11.860

I found an answer to part of my question. To extract the specific information I want, I simply do as follows: curl http://api.wunderground.com/api/%5Bkey%5D/conditions/q/TX/%5Bmycity%5D.xml | awk -F'[<|>]' '/<temp_f>/ {print "Current Temperature:"$3}/<windchill_f>/ {print "Windchill:"$3}'

– Curtis – 2017-10-08T02:21:43.650

I now need an answer to the other part of my question... how do I get conky to display the current weather icon from the url found in the tag '<icon_url>'. The url will change as the weather changes. – Curtis – 2017-10-08T02:25:38.123

Answers

1

Part 1:

In order to extract the information directly from the web url you would use the following command:

curl api.wunderground.com/api/[key]/conditions/q/[state]/[mycity].xml | awk -F'[<|>]' '/<temp_f>/ {print "Current Temperature:"$3"°F"}/<windchill_f>/ {print "Windchill:"$3"°F"}'

...or, alternately, you can extract the information from a downloaded xml file:

curl 'file:///home/path/weather.xml' | awk -F'[<|>]' '/<temp_f>/ {print "Current Temperature:"$3"°F"}/<windchill_f>/ {print "Windchill:"$3"°F"}'

You can replace

'/<temp_f>/' {print "Current Temperature:"$3"°F"}

with any other tag and information you want to display.

Part 2:

In order to extract the icon url and then get the icon to display in Conky, you would need to extract the url to a file as follows:

curl api.wunderground.com/api/[key]/conditions/q/[state]/[mycity].xml | awk -F'[<|>]' '/<icon_url>/ {print $3}' >~/path/image

You then need to download the icon, give it a generic name, and then move it to the folder you desire:

wget -O weather.gif -i ~/path/image

mv ~/weather.gif ~/path/

Create a sh script (we'll call it "weather.sh") with the above steps, and place it where you desire.

You would then place commands in your ".conkyrc" along the lines of:

${execi 300 sh ~/path/weather.sh}

${image ~/path/weather.gif -p 10,40 -s 32x32}

In the "image" command, "-p" = the position and "-s" = the pixel size of the image. Change the coordinates and size to suit your purpose.

This should be a lot simpler than many of the weather scripts, etc. that I have found for Conky.

Curtis

Posted 2017-09-27T22:19:01.550

Reputation: 33