Register
It is currently Thu Feb 22, 2018 10:37 am

Latest incarnation of ~/weather.bash


All times are UTC


Post new topic Reply to topic  [ 44 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 PostPosted: Thu Feb 12, 2009 2:04 pm   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
hakova wrote:
I think I couldn't make myself very clear in the first message. It is not the e-link's menu interface being in my locale, it is the whole web page loading in my locale language.

Well, setting any of the environment parameters did not work. The only way I could get it work was to change the language in .elinks.conf. It was defaulted to "system", which obviously uses my locale settings. I changed it to English, so that now the web pages load in English, even though there is a translated version available.

If I have to get an output in my locale language, then I guess I should replace the words in search phrases of the original scripts with the ones in my locale language, right? In that way, may be I can contribute to the internationalization of your script ;)?

:D


That's great information! I wasn't planning on doing anything else with the script for my purposes, but you are welcome to take it and extend it as I did. I think it started out as a one liner from Crouse, another guy made some changes, and I modified that work. Feel free to do the same. All that I would ask is that if you choose to pass it on to anyone else, be sure to credit the original authors, whom I believe that I have already cited in the comments.

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Top
 Profile WWW YIM  
 PostPosted: Thu Feb 12, 2009 2:07 pm   
New Member
User avatar

Joined: Tue Feb 03, 2009 3:11 am
Posts: 49
Location: Iowa
crouse wrote:
I think you can do something like:
Code:
export LOCALE=UTF-8


It doesn't work. I think it is not an encoding issue but a language one.


Top
 Profile  
 PostPosted: Thu Feb 12, 2009 7:59 pm   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
hakova wrote:
crouse wrote:
I think you can do something like:
Code:
export LOCALE=UTF-8


It doesn't work. I think it is not an encoding issue but a language one.


UTF-8 by itself is not descriptive enough. It should read en_US.UTF-8, or whatever encoding you actually want to use.

export LOCALE=en_US.UTF-8
export LOCALE=C
export LANG=en_US.UTF-8
export LANG=C

are all possibilities that could work.

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Top
 Profile WWW YIM  
 PostPosted: Fri Feb 13, 2009 3:22 am   
New Member
User avatar

Joined: Tue Feb 03, 2009 3:11 am
Posts: 49
Location: Iowa
I reverted the elinks back to my locale. I localized the script with modified specific phrases that exist in the translated web page, so that now it produces an almost fully localized output. I am not posting it here, just because I don't think many people would be interested to get weather information at their console in Turkish :) . If there is anybody interested in that I will happily send it to them.

I just don't have a wind chill field in the output though. Maybe it is because it lacks in the local weather station report.

Thanks.

Hakan


Top
 Profile  
 PostPosted: Fri Feb 13, 2009 3:59 am   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
Congratulations Hakan! Good job sticking with it!

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Top
 Profile WWW YIM  
 PostPosted: Wed Mar 18, 2009 6:40 pm   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
I've modified my script, taking the efforts from a couple of different places. This script is clearly a "hack"; it uses two different weather services and two different text browsers. It could certainly be improved in that regard, but it does work reliably. If anyone wants to improve upon it, post your improvements here.

This is the latest script, containing both current conditions and a ten day forecast:

Code:
#!/bin/bash
# forecast
#desc Find current weather stats and forecast for your zip code
#desc Ex: forecast 03301
# weather 1.1 -Crouse
# With Updates by Jeo
# Modified to run stand alone by Brian Masinick
# NOTE: This tool uses the elinks text web browser
# Example:  forecast 03301
# Usage: forecast zipcode

  zipcode=$1
  if [ -z "$zipcode" ]; then
    echo "Please provide a zip code (Ex: weather 03301)"
  else
  unset response
#  Should be one distinct line (using repeated slashes to help):
###################################################################################################################################################
  WEATHER="$(elinks -dump -dump-width 300 "http://mobile.wunderground.com/cgi-bin/findweather/getForecast?query=${zipcode}" | grep -A16 Updated)"

  if [ -z "$WEATHER" ]; then
    response="No Results for $zipcode"
    echo "${response}"
  else
    response[1]="$(echo "$WEATHER" | grep -Eo 'Observed.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print "Weather: " $1}')"
    response[2]="$(echo "$WEATHER" | grep -Eo 'Updated.*' |sed s/\ *\|\ */\|/g |awk -F\| '{print $1}')"
    response[3]="$(echo "$WEATHER" | grep -Eo 'Temperature.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}' | sed s/DEG/\ /g )"
    response[4]="$(echo "$WEATHER" | grep -Eo 'Windchill.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}'| sed s/DEG/\ /g)"
    response[5]="$(echo "$WEATHER" | grep -Eo 'Wind .*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[6]="$(echo "$WEATHER" | grep -Eo 'Conditions.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[7]="$(echo "$WEATHER" | grep -Eo 'Humidity.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[8]="$(echo "$WEATHER" | grep -Eo 'Dew.Point.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}'| sed s/DEG/\ /g)"
    response[9]="$(echo "$WEATHER" | grep -Eo 'Pressure.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"

    for index in `seq 1 9`; do
      if [ -n "${response[$index]}" ]; then
        echo "${response[$index]}"
      fi
      let "index = $index + 1"
    done
  fi
  fi

# This is contributed by Daenyth

DEFAULTZIP=03301

getforecast() {
        echo "Your 10 Day Weather Forecast as follows:"
        echo "Day, Weather, High/Low (F), Precip. %"
        links -dump "http://www.weather.com/weather/print/$1" | perl -ne '/\d %\s+$/ && s/DEG//g && print'
        echo ""
}

if   [ $# -eq 1 ]; then
        if (echo "$1" | egrep -q '^[0-9][0-9][0-9][0-9][0-9]$'); then
                getforecast $1
        fi
else
        getforecast $DEFAULTZIP
fi

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Last edited by masinick on Wed Mar 25, 2009 1:26 am, edited 1 time in total.

Top
 Profile WWW YIM  
 PostPosted: Sat Mar 21, 2009 5:07 am   
User avatar
masinick wrote:
I've modified my script, taking the efforts from a couple of different places. This script is clearly a "hack"; it uses two different weather services and two different text browsers. It could certainly be improved in that regard, but it does work reliably. If anyone wants to improve upon it, post your improvements here.

This is the latest script, containing both current conditions and a ten day forecast:

Code:
#!/bin/bash
# forecast
#desc Find current weather stats and forecast for your zip code
#desc Ex: forecast 03301
# weather 1.1 -Crouse
# With Updates by Jeo
# Modified to run stand alone by Brian Masinick
# NOTE: This tool uses the elinks text web browser
# Example:  forecast 03301
# Usage: forecast zipcode

  zipcode=$1
  if [ -z "$zipcode" ]; then
    echo "Please provide a zip code (Ex: weather 03301)"
  else
  unset response
#  Should be one distinct line (using repeated slashes to help):
###################################################################################################################################################
  WEATHER="$(elinks -dump -dump-width 300 "http://mobile.wunderground.com/cgi-bin/findweather/getForecast?query=${zipcode}" | grep -A16 Updated)"

  if [ -z "$WEATHER" ]; then
    response="No Results for $zipcode"
    echo "${response}"
  else
    response[1]="$(echo "$WEATHER" | grep -Eo 'Observed.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print "Weather: " $1}')"
    response[2]="$(echo "$WEATHER" | grep -Eo 'Updated.*' |sed s/\ *\|\ */\|/g |awk -F\| '{print $1}')"
    response[3]="$(echo "$WEATHER" | grep -Eo 'Temperature.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}' | sed s/DEG/\ /g )"
    response[4]="$(echo "$WEATHER" | grep -Eo 'Windchill.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}'| sed s/DEG/\ /g)"
    response[5]="$(echo "$WEATHER" | grep -Eo 'Wind .*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[6]="$(echo "$WEATHER" | grep -Eo 'Conditions.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[7]="$(echo "$WEATHER" | grep -Eo 'Humidity.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[8]="$(echo "$WEATHER" | grep -Eo 'Dew.Point.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}'| sed s/DEG/\ /g)"
    response[9]="$(echo "$WEATHER" | grep -Eo 'Pressure.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"

    for index in `seq 1 9`; do
      if [ -n "${response[$index]}" ]; then
        echo "${response[$index]}"
      fi
      let "index = $index + 1"
    done
  fi
  fi

DEFAULTZIP=03301

getforecast() {
        echo "Your 10 Day Weather Forecast as follows:"
        echo "Day, Weather, High/Low (F), Precip. %"
        links -dump "http://www.weather.com/weather/print/$1" | perl -ne '/\d %\s+$/ && s/DEG//g && print'
        echo ""
}

if   [ $# -eq 1 ]; then
        if (echo "$1" | egrep -q '^[0-9][0-9][0-9][0-9][0-9]$'); then
                getforecast $1
        fi
else
        getforecast $DEFAULTZIP
fi

Code:
[[email protected] ~]$ ./weather.bash 88130
Weather: Observed at S of ENMU, Portales, New Mexico
Updated: 11:07 PM MDT on March 20, 2009
Temperature: 58.8 F / 14.9 C
Wind: SSE at 29.5 mph / 47.5 km/h
Conditions: Mostly Cloudy
Humidity: 55%
Dew Point: 43 F / 6 C
Pressure: 30.02 in / 1016.5 hPa (Falling)
Your 10 Day Weather Forecast as follows:
Day, Weather, High/Low (F), Precip. %
Tonight  Isolated T-Storms      49      30 %
Sat      AM Clouds / PM Sun  77/47   20 %
Sun      Cloudy              79/50   20 %
Mon      Mostly Sunny / Wind 72/37    0 %
Tue      Sunny               70/33    0 %
Wed      Sunny               77/39    0 %
Thu      Mostly Sunny        77/39   10 %
Fri      Partly Cloudy       72/35   10 %
Sat      Mostly Sunny        72/38    0 %
Sun      Sunny               78/42    0 %


Nice, masinick!

:D


Top
  
 PostPosted: Sat Mar 21, 2009 5:59 am   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
DedannaRocks! I like your forecast, so I am glad my script gave you a nice one!

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Top
 Profile WWW YIM  
 PostPosted: Sat Mar 21, 2009 5:43 pm   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
Code:
#!/bin/bash
# forecast
#desc Find current weather stats and forecast for your zip code
#desc Ex: forecast 03301
# weather 1.1 -Crouse
# With Updates by Jeo
# Modified to run stand alone by Brian Masinick
# NOTE: This tool uses the links text web browser
# Example:  forecast 03301
# Usage: forecast zipcode

DEFAULTZIP=03301

  zipcode=$1
  if [ -z "$zipcode" ]; then
    echo "Please provide a zip code (Ex: weather 03301)"
    zipcode=$DEFAULTZIP
  else
  unset response
#  Should be one distinct line (using repeated slashes to help):
###################################################################################################################################################
  WEATHER="$(links -dump "http://mobile.wunderground.com/cgi-bin/findweather/getForecast?query=${zipcode}" | grep -A16 Updated)"

  if [ -z "$WEATHER" ]; then
    response="No Results for $zipcode"
    echo "${response}"
  else
    response[1]="$(echo "$WEATHER" | grep -Eo 'Observed.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print "Weather: " $1}')"
    response[2]="$(echo "$WEATHER" | grep -Eo 'Updated.*' |sed s/\ *\|\ */\|/g |awk -F\| '{print $1}')"
    response[3]="$(echo "$WEATHER" | grep -Eo 'Temperature.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}' | sed s/DEG/\ /g )"
    response[4]="$(echo "$WEATHER" | grep -Eo 'Windchill.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}'| sed s/DEG/\ /g)"
    response[5]="$(echo "$WEATHER" | grep -Eo 'Wind .*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[6]="$(echo "$WEATHER" | grep -Eo 'Conditions.*' | sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[7]="$(echo "$WEATHER" | grep -Eo 'Humidity.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"
    response[8]="$(echo "$WEATHER" | grep -Eo 'Dew.Point.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}'| sed s/DEG/\ /g)"
    response[9]="$(echo "$WEATHER" | grep -Eo 'Pressure.*' |sed s/\ *\|\ */\|/g | awk -F\| '{print $1 ": " $2}')"

    for index in `seq 1 9`; do
      if [ -n "${response[$index]}" ]; then
        echo "${response[$index]}"
      fi
      let "index = $index + 1"
    done
  fi
  fi

# This section was contributed by Daenyth

getforecast() {
        echo "Your 10 Day Weather Forecast as follows:"
        echo "Day, Weather, High/Low (F), Precip. %"
        links -dump "http://www.weather.com/weather/print/$1" | perl -ne '/\d %\s+$/ && s/DEG//g && print'
        echo ""
}

if   [ $# -eq 1 ]; then
        if (echo "$1" | egrep -q '^[0-9][0-9][0-9][0-9][0-9]$'); then
                getforecast $1
        fi
else
        getforecast $DEFAULTZIP
fi


Example output with slightly cleaner version:

./forecast 03301
Quote:
Weather: Observed at Concord, New Hampshire
Updated: 1:31 PM EDT on March 21, 2009
Temperature: 44.6 F / 7.0 C
Windchill: 45 F / 7 C
Wind: East at 1.0 mph / 1.6 km/h
Conditions: Clear
Humidity: 22%
Dew Point: 8 F / -13 C
Pressure: 30.43 in / 1030.4 hPa (Falling)
Your 10 Day Weather Forecast as follows:
Day, Weather, High/Low (F), Precip. %
Today Sunny 45/24 0 %
Sun Mostly Cloudy 46/20 20 %
Mon Mostly Cloudy 37/21 10 %
Tue Partly Cloudy 46/25 10 %
Wed Mostly Cloudy 54/27 10 %
Thu Cloudy 54/32 20 %
Fri Few Showers 59/37 30 %
Sat Few Showers 52/33 30 %
Sun Showers 52/32 60 %
Mon Showers 50/30 30 %

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Last edited by masinick on Wed Mar 25, 2009 1:28 am, edited 1 time in total.

Top
 Profile WWW YIM  
 PostPosted: Sat Mar 21, 2009 5:44 pm   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
By the way, I was able to get that going from my IN MEMORY copy of Puppy 4.2 RC 4. All I had to do was grab the PET package for links and it was ready to go! Works great!

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Top
 Profile WWW YIM  
 PostPosted: Tue Mar 24, 2009 6:35 pm   
User avatar
Great job, btw.

Just one question. My weather.bash goes from the area S of ENMU in Portales. How can I get it to display another area of Portales, such as (on wunderground.com, zip 88130 you'll see the drop-down for the source) just Portales for the source?

Thanks.


Top
  
 PostPosted: Wed Mar 25, 2009 12:00 am   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
DedannaRocks! wrote:
Great job, btw.

Just one question. My weather.bash goes from the area S of ENMU in Portales. How can I get it to display another area of Portales, such as (on wunderground.com, zip 88130 you'll see the drop-down for the source) just Portales for the source?

Thanks.


I am not sure whether this will work with a script or not, but on wunderground.com, you can sign up for an account and it then remembers your settings, including if you selected a major reporting station or a personal weather site instead. Try that and see if it makes any difference at all. Login to wunderground from the web and create an account, then select a different reporting station for that zip, then call up the script and see if it behaves any differently. It may, it may not, but it is worth a try.

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Top
 Profile WWW YIM  
 PostPosted: Wed Mar 25, 2009 1:12 am   
Site Admin
User avatar

Joined: Thu Apr 17, 2003 3:44 am
Posts: 12300
Location: Iowa
Masinick, the bash hacker :D :D :D It's kind of cool what you've done :)

_________________

Zbook (Laptop)- Mint 18 64-bit - I7-4800mq - 32GB ram
Phantom (Desktop)- Mint 64-bit - i7-5770 - 32GB ram
Nas4Free (NAS) - 6X3TB File Server.
Sky (HP BladeCenter) - 16 blades - 536 GB ram-G7/G6/G5 blades.


Top
 Profile WWW  
 PostPosted: Wed Mar 25, 2009 1:24 am   
Linux Guru
User avatar

Joined: Sat Apr 03, 2004 12:39 am
Posts: 12346
Location: Clinton Township, Michigan
crouse wrote:
Masinick, the bash hacker :D :D :D It's kind of cool what you've done :)


... and the coolest thing about all of it is that the only innovation that I can take credit for is combining the existing work of at least three other people. I added Daenyth to the list of contributers and modified the comments in my code above.

I guess I am like Anticapitalista in that sense. He did not write any of the applications in antiX, he is not a programmer, and he gets help from others. But he puts it all together and decides how it should fit and does a great job.

I will not write new code unless I have to. I read other people's work and leverage upon it when I have the freedom to do so. I do not try to call it my own, except to take credit for integrating it together. You can see that Crouse and Jeo are responsible for the majority of the code, but I accidentally missed the citation of a third person, Daenyth. I have corrected this in the comments.

This is not the first time that I have benefitted from the help and work of others. When I was still at Fidelity, I had an idea for a script to save me a lot of time, but in that particular case, I was lacking some technology know how. VHockey86 spent quite a bit of time with me and practically wrote the entire script based on my spec. I sure appreciated that one!

I wrote a few other scripts where I grabbed Perl code from others, made a few changes, and got some cool stuff working.

My personal .emacs and .bashrc files over the years have been collections both of my own work and the collective work and ideas of many others as well. When I have names, I credit others for their work. When I do not have names, I try to at least cite where the idea came from. When it is my work, I want credit for what I do, so I try to be careful to grant that same courtesy to others.

_________________
Brian Masinick
Distros: MX-16, antiX, Debian


Top
 Profile WWW YIM  
 PostPosted: Thu Mar 26, 2009 3:16 am   
. . . .
User avatar

Joined: Mon Apr 21, 2003 3:56 pm
Posts: 8284
Aww, rats. I can't use it on my EeePC 900A... 'links' is not in my repository.

_________________
eMachines T5246 AMD 64 X2 w/Antix 16.2 for AMD64
EeePC 900A w/ Antix 16.2 32 bit
Dell Inspiron 1545 w/ Fedora something recent for 32 bit


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 44 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


Powered by phpBB © 2012 phpBB Group
© 2003 - 2012 USA LINUX USERS GROUP