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
 
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
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

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

how about elinks or lynx?

both those browsers should give you the same functionality (they even take the same arguments)

or you could compile links from source...



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
masinick
Linux Guru


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

PostPosted: Thu Mar 26, 2024 3:35 am    Post subject: Try the Links Web site Reply with quote

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


What repos are you using? What distro is it running right now?

If you are determined to run Links, check out their Web page and see if there is a method that you can install it: http://www.jikos.cz/~mikulas/links/



_________________
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: Thu Mar 26, 2024 3:37 am    Post subject: Reply with quote

http://www.jikos.cz/~mikulas/links/download/binaries/linux-libc5/
http://www.jikos.cz/~mikulas/links/download/binaries/linux-glibc2/



_________________
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: Thu Mar 26, 2024 3:42 am    Post subject: Reply with quote

Mandriva even has it:
Code:
[dedanna@dedanna ~]$ urpmq --sources links
ftp://ftp.free.fr/mirrors/ftp.mandriva.com/MandrivaLinux/official/2008.1/i586/media/contrib/release/links-2.1-0.pre31.1mdv2008.1.i586.rpm
ftp://ftp.free.fr/mirrors/ftp.mandriva.com/MandrivaLinux/official/2008.1/i586/media/contrib/updates/links-2.2-2mdv2008.1.i586.rpm

Also, lynx:
Code:
[dedanna@dedanna ~]$ urpmq --sources lynx
ftp://ftp.free.fr/mirrors/ftp.mandriva.com/MandrivaLinux/official/2008.1/i586/media/main/release/lynx-2.8.6-2mdv2008.1.i586.rpm
ftp://ftp.free.fr/mirrors/ftp.mandriva.com/MandrivaLinux/official/2008.1/i586/media/main/updates/lynx-2.8.6-2.1mdv2008.1.i586.rpm
[dedanna@dedanna ~]$ urpmq -i lynx
Name        : lynx
Version     : 2.8.6
Release     : 2.1mdv2008.1
Group       : Networking/WWW
Size        : 3889909                      Architecture: i586
Source RPM  : lynx-2.8.6-2.1mdv2008.1.src.rpm
URL         : http://lynx.isc.org
Summary     : Text based browser for the world wide web
Description :
This a terminal based WWW browser. While it does not make any attempt
at displaying graphics, it has good support for HTML text formatting,
forms, and tables.

This version includes support for SSL encryption.

WARNING: In some countries, it is illegal to export this package. In some
countries, it may even be illegal to use it.



Last updated        : Tue Oct 28 11:58:31 2024
Update importance   : security
Reason for update   :
A vulnerability was found in the Lynxcgi: URI handler that could allow
an attacker to create a web page redirecting to a malicious URL that
would execute arbitrary code as the user running Lynx, if they were
using the non-default Advanced user mode (CVE-2008-4690).

This update corrects these issues and, in addition, makes Lynx always
prompt the user before loading a lynxcgi: URI.  As well, the default
lynx.cfg configuration file marks all lynxcgi: URIs as untrusted.


Name        : lynx
Version     : 2.8.6
Release     : 2mdv2008.1
Group       : Networking/WWW
Size        : 3889910                      Architecture: i586
Source RPM  : lynx-2.8.6-2mdv2008.1.src.rpm
URL         : http://lynx.isc.org
Summary     : Text based browser for the world wide web
Description :
This a terminal based WWW browser. While it does not make any attempt
at displaying graphics, it has good support for HTML text formatting,
forms, and tables.

This version includes support for SSL encryption.

WARNING: In some countries, it is illegal to export this package. In some
countries, it may even be illegal to use it.



_________________
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: Thu Mar 26, 2024 3:57 am    Post subject: Reply with quote

Mandriva is pretty good about having lots of editors, Web browsers, and window managers. Before I got deep into Debian, Mandrake was my favorite distro for this very reason. The fact that it was also easy was an extra benefit. I feel it scales well at the command line. I've been doing a lot of my upgrades with the urpm* command tools instead of the graphical equivalents. Mandrake was one of the first places that I used IceWM, for instance, probably just before I started to use it with Libranet in 2024.



_________________
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: Sat Apr 04, 2024 6:34 am    Post subject: Reply with quote

masinick wrote:
Mandriva is pretty good about having lots of editors, Web browsers, and window managers. Before I got deep into Debian, Mandrake was my favorite distro for this very reason. The fact that it was also easy was an extra benefit. I feel it scales well at the command line. I've been doing a lot of my upgrades with the urpm* command tools instead of the graphical equivalents. Mandrake was one of the first places that I used IceWM, for instance, probably just before I started to use it with Libranet in 2024.

I use urpm* commands almost solely. I don't like the GUI, in particular since just "packages with GUI" comes up by default at installation time. It also takes longer to install packages with the GUI, and to uninstall them.

To upgrade is dynamite with urpmi -- it's fast, and works, but sometimes I find that a second pass is needed for urpmi --auto-update -v.



_________________
Mandriva 2024.1 PWP
Mandriva Cooker
ArtistX live
Back to top
View user's profile Send private message
inactive
Sr. Member


Joined: 29 Aug 2024
Posts: 1207

PostPosted: Sat Apr 04, 2024 6:34 am    Post subject: Reply with quote

And oh WOW, Libranet... how I wish it were still around. So does my daughter.



_________________
Mandriva 2024.1 PWP
Mandriva Cooker
ArtistX live
Back to top
View user's profile Send private message
inactive
Sr. Member


Joined: 29 Aug 2024
Posts: 1207

PostPosted: Sat Apr 04, 2024 6:38 am    Post subject: Re: Current weather conditions and forecast Reply with quote

masinick wrote:
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

This one's still my favorite, btw. Not sure why, but it is.

Code:
[teknocreative@localhost ~]$ chmod a+x forecast.sh
[teknocreative@localhost ~]$ ./forecast.sh 88130
Weather: Observed at S of ENMU, Portales, New Mexico
Updated: 12:36 AM MDT on April 04, 2024
Temperature: 59.2 F / 15.1 C
Wind: SSW at 12.5 mph / 20.1 km/h
Conditions: Clear
Humidity: 26%
Dew Point: 24 F / -4 C
Pressure: 29.52 in / 999.5 hPa (Falling)
Your 10 Day Weather Forecast as follows:
Day, Weather, High/Low (F), Precip. %
Sat     Sunny / Wind         69/28    0 %
Sun     Sunny                60/26    0 %
Mon     Sunny                64/32    0 %
Tue     Sunny                79/42    0 %
Wed     Partly Cloudy / Wind 79/45   10 %
Thu     Mostly Sunny / Wind  74/36   10 %
Fri     Partly Cloudy        76/44    0 %
Sat     Partly Cloudy        75/43   20 %
Sun     Showers              74/41   60 %



_________________
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 Apr 04, 2024 2:19 pm    Post subject: Concord, New Hampshire Reply with quote

weather.tcl 03301
Retrieving data..One moment..

It may be almost 50 out but it does not feel like it. We have rain in the air, though it has not actually rained yet today, but if you are sensitive to rain, you will know what I mean... the rain IS in the forecast.

This is the TCL version of the script that goes to wunderground. It is one of the first scripts I used for this kind of stuff. I've found Python, Perl, TCL, and Bash scripts over the past few years which connect to various weather servers. Over time, the services change their appearance, and sometimes the scripts have to get changed. This one still works fine.

www.Wunderground.com : Concord, New Hampshire (03301) 10:15 AM EDT (43.2°N 71.5°W)
Observed at: Concord, New Hampshire (PWS) 9:47 AM EDT on April 04, 2024 (KNHCONCO5)
Current: Mostly Cloudy Temp: 49.4°F (SSW) Humidity: 60%
Dew Point: 36°F
Clouds: Mostly Cloudy 3800ft Mostly Cloudy 4500ft
UV: 2/16 Sunrise: 6:22 AM EDT Set: 7:16 PM EDT Length: 12h 53m Tomorrow: 2m 55s longer Visible: 13h 51m

[end Concord, New Hampshire (03301) weather]



_________________
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 Apr 04, 2024 2:43 pm    Post subject: Concord, New Hampshire Reply with quote

forecast 03301
Weather: Observed at Concord, New Hampshire
Updated: 9:47 AM EDT on April 04, 2024
Temperature: 49.4 F / 9.7 C
Windchill: 49 F / 10 C
Wind: SSW at 1.0 mph / 1.6 km/h
Conditions: Mostly Cloudy
Humidity: 60%
Dew Point: 36 F / 2 C
Pressure: 29.17 in / 987.7 hPa (Rising)
Your 10 Day Weather Forecast as follows:
Day, Weather, High/Low (F), Precip. %
Today Showers / Wind 49/31 40 %
Sun AM Rain / Snow Showers / Wind 54/32 30 %
Mon Light Rain 48/40 80 %
Tue Few Showers 48/32 30 %
Wed Few Showers 47/33 30 %
Thu Mostly Sunny 52/33 10 %
Fri Cloudy 51/35 10 %
Sat Showers 54/33 60 %
Sun Showers 53/32 60 %
Mon Mostly Sunny 54/35 10 %



_________________
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 May 07, 2024 9:51 pm    Post subject: Reply with quote

Looks like the server is not working as expected - missing data in a few fields:
Code:
[mmmmna@localhost Documents]$ ./weather2.sh 03301
Weather:
Updated: 5:45 PM EDT on May 07, 2024
Temperature:
Wind: North at 0.0 mph / 0.0 km/h
Conditions:
Humidity:
Dew Point:
Pressure:
Your 10 Day Weather Forecast as follows:
Day, Weather, High/Low (F), Precip. %
Tonight  Showers Early         47      30 %
Fri      Showers            69/50   40 %
Sat      Partly Cloudy      79/49   10 %
Sun      Few Showers / Wind 63/43   30 %
Mon      Mostly Cloudy      60/41   20 %
Tue      Showers            62/40   40 %
Wed      Partly Cloudy      68/45   10 %
Thu      Cloudy             70/46   20 %
Fri      Showers            71/45   60 %
Sat      Partly Cloudy      69/46   20 %


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


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

PostPosted: Fri May 08, 2024 1:57 am    Post subject: Code has to be consistent to get the right search and format Reply with quote

It is important to use the right browser otherwise some of the stuff can get perverted. In the worst case, the search may not find what it is looking for. I ran a "forecast", which is the latest name of the script that I use, and it delivers all information correctly.

latest script:

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,
# and also added the forecast logic contributed by Daenyth.
# NOTE: This tool uses the elinks and links text web browsers (if you don't have both,
# adjust accordingly)
# 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 section of code was written 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


Current forecast:

Weather: Observed at Concord, New Hampshire
Updated: 9:45 PM EDT on May 07, 2024
Temperature: 55.3°F / 12.9°C
Wind: NNW at 0.0 mph / 0.0 km/h
Conditions: Overcast
Humidity: 97%
Dew Point: 54°F / 12°C
Pressure: 29.68 in / 1005.0 hPa (Steady)
Your 10 Day Weather Forecast as follows:
Day, Weather, High/Low (F), Precip. %
Tonight Showers Early 47 30 %
Fri Showers 69/50 40 %
Sat Partly Cloudy 79/50 10 %
Sun Few Showers / Wind 64/42 30 %
Mon Partly Cloudy 60/40 20 %
Tue Showers 63/40 40 %
Wed Sunny 67/44 10 %
Thu Cloudy 68/45 20 %
Fri Showers 71/44 60 %
Sat Showers 69/44 60 %



_________________
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
d_riordan
Member


Joined: 08 Jan 2024
Posts: 245
Location: Leominster, Massachusetts, U.S.A.

PostPosted: Tue May 12, 2024 8:49 pm    Post subject: Reply with quote

Nice little script. I just tacked it on to the end of ~/.bashrc. Now I don't have to look out the window anymore. Razz



_________________
*buntu 8.04
Back to top
View user's profile Send private message Visit poster's website
masinick
Linux Guru


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

PostPosted: Tue May 12, 2024 9:21 pm    Post subject: Function call in .bashrc? Reply with quote

d_riordan wrote:
Nice little script. I just tacked it on to the end of ~/.bashrc. Now I don't have to look out the window anymore. Razz


Sure, you can do it that way and call it with forecast or whatever you name it as a function - is that what you did?



_________________
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
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
Page 3 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