You are not logged in.

#1 2013-08-21 19:49:14

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

shaman - A small C program to fetch weather

Hey all, I've been working on this project for a little while now, and it has finally reached a level of stability where I feel comfortable sharing it with y'all. Shaman very simply fetches weather information for a given location from the NOAA (the best weather service for the US ever).

The original inspiration behind it is the project weatherman, which is an awesome project. The goal of this was really to create a very simple and fast tool which could easily be used by a statusbar manager, however, it is fully functional and useful standalone from the command-line as well.

The project's github can be found here and a basic -git package can be found on the AUR.

Jesse McClure (a.k.a. Trilby) and Aaron Laursen have been extremely helpful to me in working out the kinks for the coding and deserve lots of love and kindness!

All comments, questions and concerns are welcome!

All the best,

-HG

Last edited by HalosGhost (2013-08-22 03:01:43)

Offline

#2 2013-08-21 21:19:25

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: shaman - A small C program to fetch weather

Moving to community contributions


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2013-08-21 21:32:07

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

ewaller wrote:

Moving to community contributions

Huh, I thought that's where I posted it originally. My apologies.

All the best,

-HG

Offline

#4 2013-08-21 23:07:11

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: shaman - A small C program to fetch weather

HalosGhost wrote:

...Huh, I thought that's where I posted it originally. My apologies.

No harm, no foul.   FYI,  It had been in Programming and Scripting.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2013-08-21 23:39:07

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

ewaller wrote:

No harm, no foul.   FYI,  It had been in Programming and Scripting.

Ahh, fair enough. Thanks for the move!

All the best,

-HG

Offline

#6 2013-08-22 01:19:02

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: shaman - A small C program to fetch weather

Neato!  Thanks HalosGhost, I like this.  It is super simple, and provides data that is actually much better than yahoo!  If you try to get data about Los Gatos, CA from weatherman, despite the fact that I live in the 95032 zip, it gives back nothing but 95030 (the other side of town).  This actually provides me with the correct data!

Offline

#7 2013-08-22 02:04:19

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

WonderWoofy wrote:

Neato!  Thanks HalosGhost, I like this.  It is super simple, and provides data that is actually much better than yahoo!  If you try to get data about Los Gatos, CA from weatherman, despite the fact that I live in the 95032 zip, it gives back nothing but 95030 (the other side of town).  This actually provides me with the correct data!

I'm glad you find it useful! I've just added pressure and visibility and am currently working on wind {speed,direction,type}. I'm also hoping to eventually allow the specification of a location through "City, ST", but that's not currently possible. And yeah, the NOAA is absolutely awesome, though admittedly they do some odd things with their XML pages (e.g., they don't correctly report metric units everywhere when requested) so I'll have to do some manual calculations rather than just reading values.

Who knows? Maybe I'll get it functioning with 7-day forecasts in the near future tongue

All the best,

-HG

Last edited by HalosGhost (2013-08-22 02:06:30)

Offline

#8 2013-08-22 02:17:48

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: shaman - A small C program to fetch weather

I think you should make of the options a default as well, so that if you omit a flag, something will still come up besides the "help".  So if I were to do shaman <zip> I could still get info.  I think the -a option would be a nice default.

Just a suggestion…

Offline

#9 2013-08-22 02:23:20

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

WonderWoofy wrote:

I think you should make of the options a default as well, so that if you omit a flag, something will still come up besides the "help".  So if I were to do shaman <zip> I could still get info.  I think the -a option would be a nice default

Totally valid recommendation. I was going to have -a be the default from the get-go, but that would have meant I'd have to do more stuff with variables (or just add another one), and I got lazy. But you are right, I will fix that in just a moment. this is now the default.

All the best,

-HG

Last edited by HalosGhost (2013-08-22 02:46:29)

Offline

#10 2013-08-22 02:53:16

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: shaman - A small C program to fetch weather

That is some unbelievably fast upstream support!  Thanks HalosGhost… rebuilding now.


Edit: Works great!

Edit2: I guess I should vote for this too, so that I can show my support!

Last edited by WonderWoofy (2013-08-22 02:54:27)

Offline

#11 2013-08-22 02:54:33

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

WonderWoofy wrote:

That is some unbelievably fast upstream support!  Thanks HalosGhost… rebuilding now.
Edit: Works great!

I've learned a lot from Trilby tongue You're more than welcome, this is better anyway. I'm glad it's working well!

Edit2: I guess I should vote for this too, so that I can show my support!

Much appreciated!

All the best,

-HG

Last edited by HalosGhost (2013-08-22 03:02:41)

Offline

#12 2013-08-22 14:34:51

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

Big update! Brief list of newly added things:

  1. Rudimentary Zsh completion

  2. Basic metric unit support

  3. Wind information

  4. Compound option support (e.g., -cdrt and -c -d -r -t are now both valid and functional)

Hope y'all enjoy it, and if there are any problems (or you'd like to see anything change), feel free to post your requests here or on the issues page of the github. The next bit (adding 7-day forecasts) will take a bit longer than the last few commits, but hopefully it should be out in not-too-long.

All the best,

-HG

Last edited by HalosGhost (2013-08-22 15:04:12)

Offline

#13 2013-08-22 15:34:07

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: shaman - A small C program to fetch weather

Building now!

One thing I like about weatherman, is that I can give it "default" arguments.  Admittedly, I have never tried the command line arg, but I created a config, which allows me to just run "weatherman" with no args, and it will parse/use that config file.  Would this be possible to implement?

Looking at weatherman, there is a flag to set the default location and units.  In reality, these I think are really the only two things that I think should really be included in a config file... in other words, minimal.

Offline

#14 2013-08-22 15:41:01

Supplantr
Member
From: a state of sunshine
Registered: 2011-12-12
Posts: 149
Website

Re: shaman - A small C program to fetch weather

This is a handy little utility. Bullet points of interest:

  • Visibility is misspelled in the output.

  • Visibility is printed when using -r. Is this intentional?

  • "Temperature:" is missing from -t.

Along these lines, I think it would allow for easier integration with status bars/other scripts if these descriptive strings were omitted from the output. Except for the case of -d (since it prints two numbers), a user would know the context of the output because they specifically requested it with the respective flag. However, this might not be viable now that compound options are supported, unless the order in which options are passed is taken into account (which doesn't appear to be the case as of now, and might be unnecessarily complicated).


I use linux and I dont understand nothing in this post.

Offline

#15 2013-08-22 15:44:17

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: shaman - A small C program to fetch weather

Interestingly, when I have dnsmasq on, it gives me back no info.  But if I turn it off, run shaman again, I get info.  Where I find it particularly odd is if I then turn dnsmasq back on, I continue to get info... confused.

Offline

#16 2013-08-22 15:57:48

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: shaman - A small C program to fetch weather

Nice.  A couple critiques though.

When a string has an initializer, you do not need to specify the number of characters.  you could just say:
provider[]="http://forecast.weather.gov/zipcity.php"

Also, you may want to look at glibc.  In particular, the command line parsing capability.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#17 2013-08-22 16:29:06

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

Supplantr wrote:

Visibility is misspelled in the output.

Fixed.

Visibility is printed when using -r. Is this intentional?

This doesn't happen for me, nor does the code appear to reflect this…

"Temperature:" is missing from -t.

This will be added along with "Condition:" to `-c`.

Along these lines, I think it would allow for easier integration with status bars/other scripts if these descriptive strings were omitted from the output. Except for the case of -d (since it prints two numbers), a user would know the context of the output because they specifically requested it with the respective flag. However, this might not be viable now that compound options are supported, unless the order in which options are passed is taken into account (which doesn't appear to be the case as of now, and might be unnecessarily complicated).

At the moment, the order of the options does not determine the order in which the information is printed, and actually, I think the descriptive text should make it simpler to use in a status bar program/script.

WonderWoofy wrote:

One thing I like about weatherman, is that I can give it "default" arguments.  Admittedly, I have never tried the command line arg, but I created a config, which allows me to just run "weatherman" with no args, and it will parse/use that config file.  Would this be possible to implement?

Looking at weatherman, there is a flag to set the default location and units.  In reality, these I think are really the only two things that I think should really be included in a config file... in other words, minimal.

I've never planned for a config file, but this wouldn't be terribly difficult to implement; I will consider it.

Interestingly, when I have dnsmasq on, it gives me back no info.  But if I turn it off, run shaman again, I get info.  Where I find it particularly odd is if I then turn dnsmasq back on, I continue to get info... confused.

I have no idea why that would be the case; this program literally just calls `curl`, so there's not much I can change that would affect that behavior.

ewaller wrote:

When a string has an initializer, you do not need to specify the number of characters.  you could just say:
provider[]="http://forecast.weather.gov/zipcity.php"

Good to know! This will be changed shortly.

Also, you may want to look at glibc.

Yes, I'm aware of that, however, I don't think there would actually be a perceivable difference in performance, so I'd rather not add another library to the includes list. Besides, I don't imagine this utility will ever get complex enough options that it would be worth it. If it ever does, then I imagine I'll make the switch.

[Edit]: Commits pushed.

All the best,

-HG

Last edited by HalosGhost (2013-08-22 16:37:48)

Offline

#18 2013-08-22 21:47:09

SolarBoyMatt
Member
Registered: 2012-01-07
Posts: 263

Re: shaman - A small C program to fetch weather

I just downloaded it and I'm getting segfaults no matter what I enter. Tried various (US) zip codes and options and they all lead to segfaults.

$ shaman 43201

This is the right way to call it, right?

EDIT:

Rebuilt it and it's working now... Weird.

Great job so far! I can probably find a way to incorporate it into my statusbar script!

Last edited by SolarBoyMatt (2013-08-22 22:20:08)

Offline

#19 2013-08-22 22:03:28

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: shaman - A small C program to fetch weather

For the wind direction you are systematically off by half of a direction.  As is if the wind is at 44.9 degrees you'd present it as "N" rather than "NE" when it is almost directly NE and if it was at 89.9 degrees you'd present it as "NE" when it is almost perfectly E.

To remedy this, I'd suggest changing "switch( (wdir/45) )" to "switch ( (wdir-22.5)/45 )" on line 71.  EDIT: I suppose then you'd want to check if it was below zero after the subtraction too.  "switch ( (wdir > 22.5 ? wdir-22.5 : wdir) / 45)" would do it.

Last edited by Trilby (2013-08-22 22:05:59)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#20 2013-08-22 23:13:45

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

WonderWoofy, I went ahead and added in very basic support for a very minimalist rc file. Let me know if that's what you were hoping for.

Trilby wrote:

For the wind direction you are systematically off by half of a direction.  As is if the wind is at 44.9 degrees you'd present it as "N" rather than "NE" when it is almost directly NE and if it was at 89.9 degrees you'd present it as "NE" when it is almost perfectly E.

To remedy this, I'd suggest changing "switch( (wdir/45) )" to "switch ( (wdir-22.5)/45 )" on line 71.  EDIT: I suppose then you'd want to check if it was below zero after the subtraction too.  "switch ( (wdir > 22.5 ? wdir-22.5 : wdir) / 45)" would do it.

Good call. I've updated this; however, because wdir is an int (which is needs to be for switch), I just went with '22' rather than '22.5'. There shouldn't be very many cases when this is off, so it should be alright.

SolarBoyMatt wrote:

Rebuilt it and it's working now... Weird.

I'm sorry to hear you were having trouble with it, but I'm glad you got it resolved, though I'm not sure why it would have been throwing errors. It should be working fine now.

All the best,

-HG

Last edited by HalosGhost (2013-08-22 23:14:55)

Offline

#21 2013-08-23 16:49:54

Supplantr
Member
From: a state of sunshine
Registered: 2011-12-12
Posts: 149
Website

Re: shaman - A small C program to fetch weather

HalosGhost wrote:
Supplantr wrote:

Visibility is printed when using -r. Is this intentional?

This doesn't happen for me, nor does the code appear to reflect this…

It appears this only happens with certain locations.


I use linux and I dont understand nothing in this post.

Offline

#22 2013-08-23 17:06:14

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

Supplantr wrote:

It appears this only happens with certain locations.

Well, that's confusing. I'll take a look at this shortly.

[EDIT]: Alright, I got this figured out. It was a stack overflow (the amount of space I allocated for the reporter line wasn't large enough). The fix will be pushed upstream shortly. I pushed a fix for this temporarily (just increased the allowable amount of space in the provider variable), however, I will eventually also make some changes that will make this less likely to happen. The safer checks have been pushed, from now on, if something like this happens, the only negative behavior will be a cut-off reporter line rather than odd extra printings.

Stay tuned, fun things are afoot.

All the best,

-HG

Last edited by HalosGhost (2013-08-24 03:36:28)

Offline

#23 2013-08-25 21:46:47

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

Another big update folks!

Now added:

  • Heat Indices!

  • Basic hazardous weather warnings (only prints the first warning at the moment)

  • Separated dewpoint and humidity printing

Zsh completion has also been updated for the changes. The last two major features I'm planning on (7-day forecasts and searching by "city, st") are under-way. I hope to have them published soon!

All the best,

-HG

Offline

#24 2013-08-25 22:18:27

bslackr
Member
Registered: 2012-01-27
Posts: 131

Re: shaman - A small C program to fetch weather

When using a config file, simply typing shaman just prints the help menu. Shouldn't it default to -a like the help menu says?

Offline

#25 2013-08-25 22:29:15

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: shaman - A small C program to fetch weather

At the moment, running shaman with no arguments at all will just print the help, even with the config. Using `shaman -a` will do what you want. I can, however change this pretty easily (hopefully). I'll try and merge it when I get home.

[Edit]: This has been merged.

All the best,

-HG

Last edited by HalosGhost (2013-08-25 23:20:28)

Offline

Board footer

Powered by FluxBB