USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

Latest incarnation of ~/weather.bash
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming
View previous topic :: View next topic  
Author Message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Thu Feb 12, 2024 2:04 pm    Post subject: Copy it freely, just give credit to the authors Reply with quote

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 Wink?

Very Happy


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: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
hakova
New Member


Joined: 03 Feb 2024
Posts: 40
Location: Virginia

PostPosted: Thu Feb 12, 2024 2:07 pm    Post subject: Reply with quote

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.


Back to top
View user's profile Send private message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Thu Feb 12, 2024 7:59 pm    Post subject: You have to specify a valid encoding value Reply with quote

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: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
hakova
New Member


Joined: 03 Feb 2024
Posts: 40
Location: Virginia

PostPosted: Fri Feb 13, 2024 3:22 am    Post subject: Reply with quote

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


Back to top
View user's profile Send private message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Fri Feb 13, 2024 3:59 am    Post subject: Reply with quote

Congratulations Hakan! Good job sticking with it!



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Wed Mar 18, 2024 6:40 pm    Post subject: Current weather conditions and forecast Reply with quote

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: SimplyMEPIS
sidux - no CAPS!, antiX, Debian


Last edited by masinick on Wed Mar 25, 2024 1:26 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
inactive
Sr. Member


Joined: 29 Aug 2024
Posts: 1207

PostPosted: Sat Mar 21, 2024 5:07 am    Post subject: Re: Current weather conditions and forecast Reply with quote

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:
[dedanna@dedanna ~]$ ./weather.bash 88130
Weather: Observed at S of ENMU, Portales, New Mexico
Updated: 11:07 PM MDT on March 20, 2024
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!

Very Happy



_________________
Mandriva 2024.1 PWP
Mandriva Cooker
ArtistX live
Back to top
View user's profile Send private message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Sat Mar 21, 2024 5:59 am    Post subject: Reply with quote

DedannaRocks! I like your forecast, so I am glad my script gave you a nice one!



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Sat Mar 21, 2024 5:43 pm    Post subject: refinement of forecast to use just links, not elinks Reply with quote

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, 2024
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: SimplyMEPIS
sidux - no CAPS!, antiX, Debian


Last edited by masinick on Wed Mar 25, 2024 1:28 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Sat Mar 21, 2024 5:44 pm    Post subject: Reply with quote

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: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
inactive
Sr. Member


Joined: 29 Aug 2024
Posts: 1207

PostPosted: Tue Mar 24, 2024 6:35 pm    Post subject: Reply with quote

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.



_________________
Mandriva 2024.1 PWP
Mandriva Cooker
ArtistX live
Back to top
View user's profile Send private message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Wed Mar 25, 2024 12:00 am    Post subject: Reply with quote

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: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Wed Mar 25, 2024 1:12 am    Post subject: Reply with quote

Masinick, the bash hacker Very Happy Very Happy Very Happy It's kind of cool what you've done Smile



_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Wed Mar 25, 2024 1:24 am    Post subject: Reply with quote

crouse wrote:
Masinick, the bash hacker Very Happy Very Happy Very Happy It's kind of cool what you've done Smile


... 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: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
mmmna
. . . .


Joined: 21 Apr 2024
Posts: 7224

PostPosted: Thu Mar 26, 2024 3:16 am    Post subject: Reply with quote

Aww, rats. I can't use it on my EeePC 900A... 'links' is not in my repository.



_________________
-Kubuntu 10.04 LTS Beta2 on Celeron D desktop
-PCLinuxOS 2024 LXDE on EeePC 900A with Atom n270 (modded with 32G SATA drive and 2G ram).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
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 vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse