Geo Weather Challenge


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Geo Weather Challenge
# 1  
Old 02-11-2010
CPU & Memory Geo Weather Challenge

Hi everybody, I'm new to these forums and this is my first post. A couple days ago I was trying to find a simple script that would return an individual's local weather conditions using I.P. based geolocation. After many failed search attempts, I began my quest to create this for myself. I have to admit, it was a bit of a challenge for me as I'm very new to doing "cool" things on the command line. However, though the process of trial and error I have prevailed. Here is what I came up with:

Code:
xmlstarlet fo http://www.google.com/ig/api?weather=$(curl -s "http://api.hostip.info/get_html.php?ip=$(curl -s icanhazip.com)" | sed -e '1d' -e '3d' -e 's|C.*:||' -e's/ /%20/g' -e "s/'/%27/g" -e "s/-/%2d/g" -e 's/...\(.*\)/\1/') | sed -e 's|<f.*_i.*>|Locale|' -e 's|<ci.*=|Origin |' -e 's|<c.*_d.*=|Date+Time |' -e 's|<c.*_c.*>|Today|' -e 's|<co.*=|Conditions |' -e 's|<f.*_c.*>|Forecast|' -e 's|<t.*_f.*=|Temperature (°F) |' -e 's|<t.*_c.*=|Temperature (°C) |' -e 's|"H.*: |Humidity "|' -e 's|"W.*: |Wind "|' -e 's|<day.*=|For |' -e 's|<l.*=|Low (°F) |' -e 's|<hi.*=|High (°F) |' -e 's|<.*=||' -e 's|/>||' -e 's|<.*>||' -e 's|</.*>||' -e "s/'/'/g" -e '1,3d;6,9d;11d;18d;25d;28d;32d;35d;39d;42d;46d;48,49d'

This script will return your current local weather conditions as well as a four day forecast. As you can see, the script utilizes CURL, SED and XMLStarlet. As of right now, this is the best I could do.

Can you do better? Let's see how small and simple we can get this script, because it has the potential to develop into something useful for many people. If you find this challenge too simple for your master skills than perhaps you might like to take this script to the next level and add some features. Whatever the case may be, I look forward to your input.

Thanks,
Jared


Last edited by o0110o; 02-11-2010 at 07:53 PM.. Reason: Typo
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for weather / forecast

#!/bin/sh #Argentina Only :s # This script requires curl and iconv, iconv is because they do not use Weather Service utf-8 ¬¬ # 87938 = Ushuaia # 87934 = Rio Grande # 87418 = Mendoza # 87582 = Capital Federal # 87692 = Mar del Plata # 87480 = Rosario # 87344 = Cordoba # 87371 = Santa Fe ... (8 Replies)
Discussion started by: yamirokuay
8 Replies

2. Linux

Check weather a file is in use or not?

Hi, Hi want to check weather a file is being used by using a command or java code or shell script. So, can any body give me some idea.. Thanks Buddhika (3 Replies)
Discussion started by: cse.buddhika
3 Replies

3. UNIX for Dummies Questions & Answers

How to verify weather it is a ebcdic file or not

Hi all, Please tell me how to verify weather it is a ebcdic file or not . I checked with file commond but it is giving like International Language text. Regards, Chaitu (0 Replies)
Discussion started by: c_chaitanya
0 Replies
Login or Register to Ask a Question