View previous topic :: View next topic |
Author |
Message |
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Thu Feb 12, 2024 2:04 pm Post subject: Copy it freely, just give credit to the authors |
|
|
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 ?
|
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. |
|
Back to top |
|
hakova New Member
Joined: 03 Feb 2024 Posts: 40 Location: Virginia
|
Posted: Thu Feb 12, 2024 2:07 pm Post subject: |
|
|
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 |
|
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Thu Feb 12, 2024 7:59 pm Post subject: You have to specify a valid encoding value |
|
|
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. |
|
Back to top |
|
hakova New Member
Joined: 03 Feb 2024 Posts: 40 Location: Virginia
|
|
Back to top |
|
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Fri Feb 13, 2024 3:59 am Post subject: |
|
|
Congratulations Hakan! Good job sticking with it! |
|
Back to top |
|
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Wed Mar 18, 2024 6:40 pm Post subject: Current weather conditions and forecast |
|
|
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 |
Last edited by masinick on Wed Mar 25, 2024 1:26 am; edited 1 time in total |
|
Back to top |
|
inactive Sr. Member
Joined: 29 Aug 2024 Posts: 1207
|
Posted: Sat Mar 21, 2024 5:07 am Post subject: Re: Current weather conditions and forecast |
|
|
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!
_________________ Mandriva 2024.1 PWP
Mandriva Cooker
ArtistX live
|
|
Back to top |
|
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Sat Mar 21, 2024 5:59 am Post subject: |
|
|
DedannaRocks! I like your forecast, so I am glad my script gave you a nice one! |
|
Back to top |
|
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Sat Mar 21, 2024 5:43 pm Post subject: refinement of forecast to use just links, not elinks |
|
|
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 % |
Last edited by masinick on Wed Mar 25, 2024 1:28 am; edited 1 time in total |
|
Back to top |
|
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Sat Mar 21, 2024 5:44 pm Post subject: |
|
|
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! |
|
Back to top |
|
inactive Sr. Member
Joined: 29 Aug 2024 Posts: 1207
|
Posted: Tue Mar 24, 2024 6:35 pm Post subject: |
|
|
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 |
|
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Wed Mar 25, 2024 12:00 am Post subject: |
|
|
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. |
|
Back to top |
|
crouse Site Admin
Joined: 17 Apr 2024 Posts: 11833 Location: Iowa
|
|
Back to top |
|
masinick Linux Guru
Joined: 03 Apr 2024 Posts: 8615 Location: Concord, NH
|
Posted: Wed Mar 25, 2024 1:24 am Post subject: |
|
|
crouse wrote: | Masinick, the bash hacker 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. |
|
Back to top |
|
mmmna . . . .
Joined: 21 Apr 2024 Posts: 7224
|
Posted: Thu Mar 26, 2024 3:16 am Post subject: |
|
|
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 |
|
|