Please support VectorLinux!

Author Topic: weather on the command line  (Read 1364 times)

InTheWoods

  • Vectorite
  • ***
  • Posts: 302
weather on the command line
« on: January 24, 2010, 08:17:22 pm »
I discovered this curiosity
http://cb.vu/
and tried the command "weather" on VL
It gave me the correct weather for my Canadian location. So I tried the command in a terminal. This however gave me some menus then a Washington D.C. weather report another menu and then a
"connection closed by foreign host"
message.

I also tried
Code: [Select]
weather kingston,canadawhich works on the above mentioned site but still fails on my system.

How would I get this to work in VL 6.0 standard?
There is no 'man', 'info', or 'help' pages.

nightflier

  • Administrator
  • Vectorian
  • *****
  • Posts: 4072
Re: weather on the command line
« Reply #1 on: January 25, 2010, 03:35:00 am »
It appears to be a simple bash script hard-wired for three letter airport codes in USA.

I changed line 3, substituting a 2 for the 1, then used command "weather yyz", which gave me Toronto.

InTheWoods

  • Vectorite
  • ***
  • Posts: 302
Re: weather on the command line
« Reply #2 on: January 25, 2010, 05:52:41 am »
Not working here. I changed line 3 to
Quote
exec expect -f "$0" ${2+"$@"}
and ran
Quote
weather yyz
with the same result. Washington weather
so I changed line 21 to
Quote
if {$argc>0} {set code $argv} else {set code "YYC"}
Now I get
Quote
No data available.
/wx/data/DAT/YYC.DAT
Is this because I am trying to access from outside the U.S.? It seems to work on the site I mentioned above. Perhaps because http://cb.vu/ is accessing http://www.wunderground.com/ from inside the U.S.?

Secondly, where do you get the 3 letter city codes?

nightflier

  • Administrator
  • Vectorian
  • *****
  • Posts: 4072
Re: weather on the command line
« Reply #3 on: January 25, 2010, 03:03:10 pm »
Don't know if it matters where you connect from, but you can get the airport codes here: http://www.faacodes.com/

BTW, check your syntax; yyz / YYC

InTheWoods

  • Vectorite
  • ***
  • Posts: 302
Re: weather on the command line
« Reply #4 on: January 26, 2010, 10:49:16 am »
Quote
BTW, check your syntax; yyz / YYC
Doh!...Still no go

I searched around a little and found there are several weather scripts, none of which I could understand. So I thought I would waste some time and write my second ever bash script!

First I found you can use a text browser to dump an html file to a text file.
Code: [Select]
lynx -dump http://www.mysite.com/page.html > page.txt
This works fine except for RSS feeds which for some reason have html tags still intact in the dump. To get around this I dumped into an html file and then re-dumped into a text file.
Code: [Select]
lynx -dump http://text.weatheroffice.gc.ca/rss/city/on-69_e.xml > pageRSS.html
lynx -dump pageRSS.html > pageRSS.txt
Next I extracted and printed the lines I wanted (from some tutorial) with sed
Code: [Select]
sed -n 7,11p pageRSS.txtand removed the dump files when no longer needed. so the whole thing looks like this.
Code: [Select]
#!/bin/bash
#script for weather from http://text.weatheroffice.gc.ca/rss

lynx -dump http://text.weatheroffice.gc.ca/rss/city/on-69_e.xml > pageRSS.html
lynx -dump pageRSS.html > pageRSS.txt
rm pageRSS.html
sed -n 7,11p pageRSS.txt
rm pageRSS.txt
fi

exit 0

There are a couple of obvious problems. I copied the ending off of another script and it throws an error
Quote
can2.sh: line 9: syntax error near unexpected token `fi'
can2.sh: line 9: `fi'

Second If there is a weather warning above line 7 in my txt file I will be printing the wrong lines.

I would also like to shave 5 characters off of the first line for formatting the output.


Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
Re: weather on the command line
« Reply #5 on: January 26, 2010, 11:25:06 am »
There are a couple of obvious problems. I copied the ending off of another script and it throws an error
Quote
can2.sh: line 9: syntax error near unexpected token `fi'
can2.sh: line 9: `fi'

"fi" is the ending for an "if" statement.

example:

if i = 0; then
#do some stuff
fi
The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM