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
CURLINFO_PROTOCOL(3)					     curl_easy_getinfo options					      CURLINFO_PROTOCOL(3)

NAME
CURLINFO_PROTOCOL - get the protocol used in the connection SYNOPSIS
#include <curl/curl.h> CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PROTOCOL, long *p); DESCRIPTION
Pass a pointer to a long to receive the version used in the last http connection. The returned value will be one of the CURLPROTO_* val- ues. PROTOCOLS
All EXAMPLE
CURL *curl = curl_easy_init(); if(curl) { CURLcode res; curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); res = curl_easy_perform(curl); if(res == CURLE_OK) { long protocol; curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol); } curl_easy_cleanup(curl); } AVAILABILITY
Added in 7.52.0 RETURN VALUE
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. SEE ALSO
CURLINFO_RESPONSE_CODE(3), curl_easy_getinfo(3), curl_easy_setopt(3), libcurl 7.54.0 November 23, 2016 CURLINFO_PROTOCOL(3)
All times are GMT -4. The time now is 10:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy