Sponsored Content
Full Discussion: Geo Weather Challenge
Top Forums Shell Programming and Scripting Geo Weather Challenge Post 302394520 by o0110o on Thursday 11th of February 2010 05:12:59 PM
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
 

3 More Discussions You Might Find Interesting

1. 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

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. 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
Weather::Com::UVIndex(3pm)				User Contributed Perl Documentation				Weather::Com::UVIndex(3pm)

NAME
Weather::Com::UVIndex - class containing the uv index data SYNOPSIS
#!/usr/bin/perl -w use Weather::Com::Finder; # you have to fill in your ids from weather.com here my $PartnerId = 'somepartnerid'; my $LicenseKey = 'mylicense'; my %weatherargs = ( 'partner_id' => $PartnerId, 'license' => $LicenseKey, 'language' => 'de', ); my $weather_finder = Weather::Com::Finder->new(%weatherargs); my @locations = $weather_finder->find('Heidelberg'); my $currconditions = $locations[0]->current_conditions(); print "The current uv index is ", $currconditions->uv_index()->index(), " "; print "This is relatively ", $currconditions->uv_index()->description(), " "; DESCRIPTION
Via Weather::Com::UVIndex one can access the uv index and its description (whether it's high or low). An uv index is usually an object belonging to current conditions or to a forecast (not implemented yet). This class will not be updated automatically with each call to one of its methods. You need to call the "uv_index()" method of the parent object again to update your object. CONSTRUCTOR
You usually would not construct an object of this class yourself. This is implicitely done when you call the uv_index() method of one cur- rent conditions or forecast object. METHODS
index() Returns the uv index (number). description([$language]) Returns the description whether this index is high or low. This description is translated if you specified the language option as argument while instantiating your Weather::Com::Finder. This attribute is dynamic language enabled. AUTHOR
Thomas Schnuecker, <thomas@schnuecker.de> COPYRIGHT AND LICENSE
Copyright (C) 2004-2007 by Thomas Schnuecker This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The data provided by weather.com and made accessible by this OO interface can be used for free under special terms. Please have a look at the application programming guide of weather.com (<http://www.weather.com/services/xmloap.html>)! perl v5.8.8 2007-07-09 Weather::Com::UVIndex(3pm)
All times are GMT -4. The time now is 06:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy