weather output script

Forum rules
General talk about software - if the program is not in the repos, please links to the developer's page or github.
User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

weather output script

Unread post by dkeg » Sun Mar 01, 2015 9:09 pm

I came across this weather script using json in unixporn the other day. I liked its simplicity and checked it out. Unfortunately, the output is a bit sloppy, going 3-5 decimal places and rendering the output almost unreadable. I have recently placed its output in my status bar, but again, the sloppy output limited what I would display. When I say sloppy, that includes not have nice columns for awk to poke and prod.

Here is the script -> https://github.com/CarloBarraco/getweather

The output would be something like

Code: Select all

Overcast clouds|Temp:-4.681C|Wind:11.736kph
or

Code: Select all

Overcast clouds|Temp:23.5742F|Wind:18.88721424mph
Stark and Dr.Chroot seemed interesed as well
So I wrote this little script to neaten it up a bit. Edit: version 2 with added weather types, eg, rain, snow
Also note the name of the script is getweather. I named it weather locally.

Code: Select all

#! /bin/bash

## script is from https://github.com/CarloBarraco/getweather
## I wrote this to clean up the output
## change location as needed
## weather icons are from lemon fonts
## 2015 dkeg

## get the weather and format nicely
## use an underscore with 2 word cities (New_York_City)
loc='where do you live?'
sky=$(weather -l $loc -d)
temp=$(weather -l $loc -t -i|cut -d ':' -f2|cut -d '.' -f1)"F"
wind=$(weather -l $loc -w -i |cut -d ':' -f2|cut -d '.' -f1)"mph"
sep="  "

case $sky in 
    "Sky is clear")
        glyph="⯇ " ;;
    "Overcast clouds")
        glyph="⯄ " ;;
    "Light rain")
        glyph="⮿ " ;;
    "Moderate rain")
        glyph="⯃ " ;;
    "Light snow")
        glyph="⯁ " ;;
    "Snow")
        glyph="⯁ " ;;
esac

echo $glyph $sky$sep $temp$sep⯈ $wind
output is now like this
weathr.png
weathr.png (677 Bytes) Viewed 4730 times
## Disclaimer: typical stuff. I'm no expert. I wrote this to solve my own issue. It works for me. It may prove useful to you. If so great. If not; bye. Please use it as needed or as a foundation for something better
Last edited by dkeg on Wed Mar 18, 2015 1:02 pm, edited 2 times in total.
Reason: updated script; its better!

Work hard; Complain less

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: weather output script

Unread post by rhowaldt » Sun Mar 01, 2015 11:11 pm

cool, thanks for sharing Drew. (looks good as fucking always :)
i was wondering: would it not be easier to change the weatherscript directly instead of using a seperate script? or could you not be bothered to learn JSON just to change some markup? :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: weather output script

Unread post by dkeg » Sun Mar 01, 2015 11:42 pm

Thanks.
I was caught up in my 'solution', and was determined to make it work. I played in the script a bit, but it was faster this way. Maybe now that I got this piece, I'll work on the original.

This was good learning session though. I thought of the idea while in church today.

Edit: Plus it gives more control over the output with regards to conditionals and color, icons, etc.

Work hard; Complain less

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: weather output script

Unread post by Dr_Chroot » Mon Mar 02, 2015 1:44 am

Looks great, dkeg! Will give it a try when I get home; on the move today :)
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: weather output script

Unread post by rhowaldt » Mon Mar 02, 2015 10:44 am

^^ cool, yeah, makes sense. thanks for explaining!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: weather output script

Unread post by machinebacon » Mon Mar 02, 2015 12:29 pm

anybody tried ansiweather and piped to bar?
..gnutella..

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: weather output script

Unread post by stark » Mon Mar 02, 2015 4:46 pm

@dkeg Thanks Again!

@bacon I haven't, this one also needs a json parser will look into it. Thanks!
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: weather output script

Unread post by Dr_Chroot » Mon Mar 02, 2015 5:53 pm

I tried pulling in several python libs, but I still get

Code: Select all

 ~  >>  getweather
bash: /usr/bin/getweather: /bin/python2: bad interpreter: No such file or directory
Am I missing a json library as well?
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: weather output script

Unread post by pidsley » Mon Mar 02, 2015 7:09 pm

Here is another simple script. If you are in the US just use your zip code for <locationcode>.

https://bbs.archlinux.org/viewtopic.php?id=37381

The script gives you a very simple output that can be piped to conky or another bar.

Image

I'm sure the raw output could be parsed with awk if you don't like perl.

There are other simple weather scripts in that arch topic.

Or you could just go outside :)

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: weather output script

Unread post by dkeg » Mon Mar 02, 2015 7:23 pm

Love that comment pids! It was more of an exercise for me.

@DC, sorry, forgot to mention that. The path is incorrect in the weather script. Should be

Code: Select all

/usr/bin/python2

Work hard; Complain less

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: weather output script

Unread post by Dr_Chroot » Mon Mar 02, 2015 7:52 pm

You da man, dkeg. Thanks!
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: weather output script

Unread post by pidsley » Mon Mar 02, 2015 7:58 pm

^^ dkeg, if you want an interesting exercise, take the raw output from accuweather (or another provider) and parse it yourself without using json. :)

Just be warned -- the way of the weather conky leads to madness.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: weather output script

Unread post by dkeg » Tue Mar 03, 2015 12:12 am

Ha! Then maybe scrots on munch!

Work hard; Complain less

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: weather output script

Unread post by dkeg » Wed Mar 18, 2015 2:41 am

Updated script in first post. Cleaned up and improved the case statement for better output. Added a couple of 'sky' types

Work hard; Complain less

Post Reply