• BASH mk III

    From Spectre@21:3/101 to Anybody on Tuesday, February 18, 2020 08:45:00
    Morning

    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.

    humid. showers and storms.
    partly cloudy. late smoke haze.
    early shower. partly cloudy.
    showers developing. windy.
    partly cloudy. cool and windy afternoon.
    possible late shower.

    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.

    I have no real idea how to manage that effectively.. any ideas?

    Spec


    *** THE READER V4.50 [freeware]
    --- SuperBBS v1.17-3 (Eval)
    * Origin: Scrawled in haste at The Lower Planes (21:3/101)
  • From tenser@21:1/101 to Spectre on Tuesday, February 18, 2020 12:31:43
    On 18 Feb 2020 at 08:45a, Spectre pondered and said...

    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.

    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.

    [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.

    It sounds like what you may want is an ordered set of
    regular 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
    }

    Etc....

    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.

    --- Mystic BBS v1.12 A44 2020/02/04 (Windows/32)
    * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101)
  • From Spectre@21:3/101 to tenser on Tuesday, February 18, 2020 16:26:00
    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.

    But there is also, when all you have is a hammer, everything looks like a nail.

    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.

    Chuckle, like I said its a massive case statement.. match case, copy file.. about the only intelligent thing in there is that it shows what the conditions tend to look like.

    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.

    Spec


    *** THE READER V4.50 [freeware]
    --- SuperBBS v1.17-3 (Eval)
    * Origin: Scrawled in haste at The Lower Planes (21:3/101)
  • From Vk3jed@21:1/109 to Spectre on Wednesday, February 19, 2020 09:12:00
    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.

    I've never tried AWK, other than using scripts others have written, 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. :)


    ... Guests being stalked by zombies stay at Best Western.
    === MultiMail/Win v0.51
    --- SBBSecho 3.10-Linux
    * Origin: Freeway BBS Bendigo,Australia freeway.apana.org.au (21:1/109)
  • From Spectre@21:3/101 to Vk3jed on Wednesday, February 19, 2020 15:14:00
    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.

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: < Scrawled in blood at The Lower Planes > (21:3/101)
  • From Vk3jed@21:1/109 to Spectre on Wednesday, February 19, 2020 19:15:00
    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.

    That's what I use sed for, including converting all input to lower or uppercase as needed. :)


    ... Shock me, say something intelligent!
    === MultiMail/Win v0.51
    --- SBBSecho 3.10-Linux
    * Origin: Freeway BBS Bendigo,Australia freeway.apana.org.au (21:1/109)