• Weather alerts to IRC room

    From ansunent@VERT/ANSUN to all on Monday, January 23, 2023 00:41:10
    Hey can anyone check out this script and tell me where it may have gone wrong? I keep getting a syntax error on line 17

    Line 17: https.get(weatherURL, (res) => {

    The purpose of the script is to periodically check weather.gov for new or updated severe weather alerts and to post those in my IRC room. Below is the whole script. I appreciate any help you can give.

    const https = require("http.js");
    const irc = require("irc.js");

    const weatherURL = "https://api.weather.gov/alerts/active/zone/";

    const client = new irc.Client("mybbs.synchro.net", "WeatherAlert", {
    channels: ["#weather"],
    });

    client.addListener("message", function (from, to, message) {
    if (message === "!weather") {
    getWeatherAlerts(to);
    }
    });

    function getWeatherAlerts(channel) {
    https.get(weatherURL, (res) => {
    let data = "";
    res.on("data", (chunk) => {
    data += chunk;
    });
    res.on("end", () => {
    const alerts = JSON.parse(data).features;
    if (alerts.length === 0) {
    client.say(channel, "No severe weather alerts at this time.");
    return;
    }
    alerts.forEach((alert) => {
    client.say(channel, alert.properties.headline);
    });
    });
    });
    }

    ---
    Synchronet ANSUN - ansun.synchro.net
  • From Digital Man@VERT to ansunent on Monday, January 23, 2023 09:22:17
    Re: Weather alerts to IRC room
    By: ansunent to all on Mon Jan 23 2023 12:41 am

    Hey can anyone check out this script and tell me where it may have gone wrong? I keep getting a syntax error on line 17

    Line 17: https.get(weatherURL, (res) => {

    The JavaScript engine used by Synchronet (i.e. libmozjs, aka SpiderMonkey, v1.8.5) implements EMCAScript 5 (ES5) and thus does not support JS bullet operators.
    https://en.wikipedia.org/wiki/ECMAScript_version_history#5th_Edition_%E2%80%93_ECMAScript_2009
    --
    digital man (rob)

    Synchronet "Real Fact" #48:
    Synchronet directory naming (i.e. ctrl, exec, data) was suggested by S. Deppe Norco, CA WX: 50.9F, 29.0% humidity, 3 mph NE wind, 0.00 inches rain/24hrs

    ---
    Synchronet Vertrauen Home of Synchronet [vert/cvs/bbs].synchro.net
  • From ansunent@VERT/ANSUN to Digital Man on Monday, January 23, 2023 18:56:18
    Re: Weather alerts to IRC room
    By: ansunent to all on Mon Jan 23 2023 12:41 am

    The JavaScript engine used by Synchronet (i.e. libmozjs, aka SpiderMonkey, v1.8.5) implements EMCAScript 5 (ES5) and thus does not support JS bullet operators. https://en.wikipedia.org/wiki/ECMAScript_version_history#5th_Edition_%E2%80%9 3_ECMAScript_2009
    --
    digital man (rob)

    Synchronet "Real Fact" #48:
    Synchronet directory naming (i.e. ctrl, exec, data) was suggested by S. Deppe Norco, CA WX: 50.9F, 29.0% humidity, 3 mph NE wind, 0.00 inches rain/24hrs

    ---
    Synchronet Vertrauen Home of Synchronet
    [vert/cvs/bbs].synchro.net



    Still learning so please bear with me. I really appreciate the information.

    It sounds like we're specifically saying that the "=>" is the problem or at least one of the syntax problems Am I right?

    ---
    Synchronet ANSUN - ansun.synchro.net
  • From Digital Man@VERT to ansunent on Monday, January 23, 2023 20:32:00
    Re: Weather alerts to IRC room
    By: ansunent to Digital Man on Mon Jan 23 2023 06:56 pm

    Re: Weather alerts to IRC room
    By: ansunent to all on Mon Jan 23 2023 12:41 am

    The JavaScript engine used by Synchronet (i.e. libmozjs, aka SpiderMonkey, v1.8.5) implements EMCAScript 5 (ES5) and thus does not support JS bullet operators. https://en.wikipedia.org/wiki/ECMAScript_version_history#5th_Ed ition_%E2%80%9 3_ECMAScript_2009
    --
    digital man (rob)

    Synchronet "Real Fact" #48:
    Synchronet directory naming (i.e. ctrl, exec, data) was suggested by S. Deppe Norco, CA WX: 50.9F, 29.0% humidity, 3 mph NE wind, 0.00 inches rain/24hrs

    ---
    Synchronet Vertrauen Home of Synchronet [vert/cvs/bbs].synchro.net



    Still learning so please bear with me. I really appreciate the information.

    It sounds like we're specifically saying that the "=>" is the problem or at least one of the syntax problems Am I right?

    Right. => is often called a rocket operator (or "Arrow function expression") and is not supported in earlier JS implementations. Sorry, not "bullet operator" like I said.
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
    --
    digital man (rob)

    This Is Spinal Tap quote #42:
    What day the Lord created Spinal Tap and couldn't he have rested on that day? Norco, CA WX: 54.9F, 29.0% humidity, 4 mph SSE wind, 0.00 inches rain/24hrs

    ---
    Synchronet Vertrauen Home of Synchronet [vert/cvs/bbs].synchro.net
  • From ansunent@VERT/ANSUN to Digital Man on Tuesday, January 24, 2023 00:31:30
    Re: Weather alerts to IRC room
    By: ansunent to Digital Man on Mon Jan 23 2023 06:56 pm

    Right. => is often called a rocket operator (or "Arrow function expression") and is not supported in earlier JS implementations. Sorry, not "bullet operator" like I said. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/A rrow_functions
    --
    digital man (rob)

    This Is Spinal Tap quote #42:
    What day the Lord created Spinal Tap and couldn't he have rested on that day? Norco, CA WX: 54.9F, 29.0% humidity, 4 mph SSE wind, 0.00 inches
    rain/24hrs

    ---
    Synchronet Vertrauen Home of Synchronet
    [vert/cvs/bbs].synchro.net



    That makes sense. I'll look into what I need to use in substitution for this "=>".

    Much appreciated, DM.

    ---
    Synchronet ANSUN - ansun.synchro.net
  • From echicken@VERT/ECBBS to ansunent on Thursday, January 26, 2023 19:58:08
    Re: Weather alerts to IRC room
    By: ansunent to Digital Man on Tue Jan 24 2023 00:31:30

    That makes sense. I'll look into what I need to use in substitution for this "=>".

    You've got other problems beyond incompatible syntax.

    In the code that you posted, you were doing something like:

    http.get(url, res => {
    let data = '';
    res.on('data', d => data += d);
    res.on('end', () => {
    // do stuff with data
    });
    });

    I suspect you took inspiration from a rather outdated node.js example. None of this will work here. In fact a vast amount of example JS code that you find online simply won't work here without significant alteration.

    You want something like:

    function getWeatherAlerts(channel) {
    var data = http.Get(weatherURL);
    var alerts = JSON.parse(data).features;
    if (alerts.length < 1) {
    client.say(channel, 'No severe weather alerts at this time.');
    } else {
    alerts.forEach(function (alert) {
    client.say(channel, alert.properties.headline);
    });
    }
    }

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com
    ---
    Synchronet electronic chicken bbs - bbs.electronicchicken.com
  • From Nelgin@VERT/EOTLBBS to ansunent on Tuesday, January 31, 2023 01:40:33
    On Mon, 23 Jan 2023 00:41:10 -0600
    "ansunent" <ansunent@VERT/ANSUN> wrote:

    Hey can anyone check out this script and tell me where it may have
    gone wrong? I keep getting a syntax error on line 17

    Line 17: https.get(weatherURL, (res) => {

    The purpose of the script is to periodically check weather.gov for
    new or updated severe weather alerts and to post those in my IRC
    room. Below is the whole script. I appreciate any help you can give.


    Use ircbot, it has a built in weather function.
    --
    End Of The Line BBS - Plano, TX
    telnet endofthelinebbs.com 23
    ---
    Synchronet End Of The Line BBS - endofthelinebbs.com
  • From MRO@VERT/BBSESINF to Nelgin on Tuesday, January 31, 2023 12:10:24
    Re: Re: Weather alerts to IRC room
    By: Nelgin to ansunent on Tue Jan 31 2023 01:40 am



    Use ircbot, it has a built in weather function.

    yeah where's the docs for it? i tried setting it up before and couldn't get it to work and there were no error msgs.
    ---
    Synchronet ::: BBSES.info - free BBS services :::