Todays bash question comes from my weather script. Which is the bit that assembles all the various components into the ANSI/ASCII pages for the bbs and conversion to png for the web page. Now the bureau of meteorology throw out a string like so.
[snip]
Based on this, I try and select 1 appropriate icon to add to the page. The present logic which seemed alright originally but has spiralled
wildly out of control is a case statement that contains every
permutation of weather that has ever come along. Making it both realllllly long and reallly inefficient.
I have a series of 9 icons for varying weather conditions. Cloud, partly cloudy (or partly sunny), sunny, rain, lightning, snow, thunder storm, rain clearing or showers. So I need to try and search the above strings for a keyword to select to most applicable icon.
There comes a point in every Unix user's life where you start to
realize that the shell has limits and isn't the best tool for
everything. In particular, the program you are writing may not be well-suited as a shell script.
expressions, and mapping those to an icon. You use the ordering
to model weights; "it's raining cats and dogs" means "rain" even
if it also says, "it may clear up later."
This implies a pattern/action language may be well suited to the
task; I'd take a close look at `awk`. Something like:
/it is raining/ { print "rain" next } /it is kinda (cloudy|sunny)/
{ print "partly cloudy" next }
It'd be helpful to see what your script does now, but please goodness
not in the BBS interface; put it on github or in a gist or on a web
page somewhere.
On 02-18-20 16:26, Spectre wrote to tenser <=-
I'll have to consider AWK never had much joy with it, even less than
I've had with sed which is pretty hard to manage. Ta.
but I have found sed extremely useful for many things. I love sed,
though I generally refer to the man page each time I use it. :)
On 02-19-20 15:14, Spectre wrote to Vk3jed <=-
but I have found sed extremely useful for many things. I love sed,
though I generally refer to the man page each time I use it. :)
The only thing I use said for is string substitution or deletion... the rest of
it seems to be an obscure alien science to me.
Sysop: | sneaky |
---|---|
Location: | Ashburton,NZ |
Users: | 31 |
Nodes: | 8 (0 / 8) |
Uptime: | 231:18:37 |
Calls: | 2,088 |
Calls today: | 2 |
Files: | 11,140 |
Messages: | 948,566 |