[dev] wego: a weather app for the terminal written in go

2015-01-14 Thread Markus Teich
Heyho,

since I was tired of fetching lots of unneeded html and js and images just to
get a weather forecast, I wrote wego[0]. Comments welcome.

--Markus

0: https://github.com/schachmat/wego



Re: [dev] wego: a weather app for the terminal written in go

2015-01-14 Thread Nick
Quoth Markus Teich: 
 since I was tired of fetching lots of unneeded html and js and images just to
 get a weather forecast, I wrote wego[0]. Comments welcome.

I did a similar thing a while ago in bourne shell. It's fragile, as 
shell scripts should be, and shouldn't be relied upon. But it's a 
nice example of another way to do this. It was never written for 
public use, but what the hell.

It uses Weather Underground, which means it has hourly info, and 
lots of other forecast stuff that the script is just ignoring for 
now. It also loads the json with the weather data without needing an 
API key, because that shit is for chumps.

Oh, and its output is far, far more basic than Markus'.

Attached.
#!/bin/sh
usage=$0 location

test $# -eq 0  echo $usage  exit 1

loc=`echo $@ | sed 's/ /+/g'`
resp=`curl 
'http://www.wunderground.com/cgi-bin/findweather/hdfForecast?query='$loc`

# build actual json url
key=`echo $resp | awk '/\tk:/ {print $2}' | sed s/[',]//g`
locationcode=`echo $resp | awk '/\tzmw:/ {print $2}' | sed s/[',]//g`
json=`curl 
http://api-ak.wunderground.com/api/${key}/forecast10day/hourly10day/labels/astronomy10day/lang:EN/units:metric/v:2.0/bestfct:1/q/zmw:${locationcode}.json`

usefuljson=`echo $json | jq 
'.forecast|.days|.[]|.hours|.[]|{epoch:.date.epoch, temperature, pop, snow, 
humidity, condition}'`

echo $json | jq -r '.current_observation.station|.id,.name,.city'

echo $usefuljson | sed 's///g; s/,//g; s/: /:/' | while read line; do
test $line = }  printf '\n'  continue
test $line = {  continue

epoch=`echo $line | awk -F : '($1 == epoch) {print $2}'`
if test $epoch !=   test $epoch != null; then
datestr=`printf @%s $epoch`
date=`date --date=$datestr +'%a %d, %R'`
oldcurday=$curday
curday=`echo $date | awk '{print $1}'`
test $curday != $oldcurday  printf '\n'
printf %s -  $date
epoch=
fi

echo $line | awk -F : '{
if ($1 == temperature) { printf(%-4.1f°C, , $2) }
if ($1 == pop) { printf(%2.0f%% rain, , $2) }
if ($1 == snow  $2  0) { printf(%2.0f%% snow, , $2) }
if ($1 == humidity) { printf(%2.0f%% humidity, , $2) }
if ($1 == condition) { printf(%s, $2) }
}'
done


Re: [dev] wego: a weather app for the terminal written in go

2015-01-14 Thread Pascal Wittmann
Hi Markus,

On 01/14/2015 10:42 PM, Markus Teich wrote:
 since I was tired of fetching lots of unneeded html and js and images just to
 get a weather forecast, I wrote wego[0]. Comments welcome.

Looks great! I will give it a try in the next few days.

Pascal



signature.asc
Description: OpenPGP digital signature


Re: [dev] wego: a weather app for the terminal written in go

2015-01-14 Thread Nick
Quoth Nick: 
 I did a similar thing a while ago in bourne shell.

I forgot to mention it depends on curl and jq. Any bourne shell 
should work though; I don't believe in bash.



Re: [dev] wego: a weather app for the terminal written in go

2015-01-14 Thread Markus Wichmann
On Wed, Jan 14, 2015 at 10:42:07PM +0100, Markus Teich wrote:
 Heyho,
 
 since I was tired of fetching lots of unneeded html and js and images just to
 get a weather forecast, I wrote wego[0]. Comments welcome.
 

When I tried to run it, it would just print Malformed response. I
added a line to dump the URL to stderr before that and tried to get it
with wget, and the response I get is 403 Forbidden. What am I doing
wrong?

Ciao,
Markus



Re: [dev] wego: a weather app for the terminal written in go

2015-01-14 Thread Markus Teich
Nick wrote:
 Oh, and its output is far, far more basic than Markus'.

Oh yes, one third of my SLOC are the ascii icons and nearly another third is for
the output formatting… :/

--Markus



Re: [dev] wego: a weather app for the terminal written in go

2015-01-14 Thread Markus Teich
Nick wrote:
 It uses Weather Underground, which means it has hourly info, and lots of other
 forecast stuff that the script is just ignoring for now. It also loads the
 json with the weather data without needing an API key, because that shit is
 for chumps.

For me, SSL support was more important than not having to use an API key. I did
not find a service providing both.

--Markus