Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update weather to include information about locality #305

Closed
chelming opened this issue Jan 22, 2024 · 1 comment · Fixed by #401
Closed

Update weather to include information about locality #305

chelming opened this issue Jan 22, 2024 · 1 comment · Fixed by #401

Comments

@chelming
Copy link
Collaborator

if you !weather rochester (https://wttr.in/rochester), it doesn't tell you which Rochester the weather is for. It might be worth regexing the location

Location: Rochester, Monroe County, New York, United States of America [43.157285,-77.6152139]

/Location: ([^[]+)\s/ would probably grab the location minus the coordinates.

@chelming
Copy link
Collaborator Author

I think this would work:

/*
activation_example:!weather london
regex:!weather
flags:gmi
*/
var wordCount = current.text.replace('!weather', '').trim().split(' ');

if (wordCount[0] != '') {

    var rm = new sn_ws.RESTMessageV2();
    rm.setHttpMethod('GET');
    rm.setLogLevel('all');
    rm.setEndpoint('https://wttr.in/' + wordCount[0] + '?format=4');
    var response = rm.execute();
    var weatherBody = response.getBody();

    var locrm = new sn_ws.RESTMessageV2();
    locrm.setHttpMethod('GET');
    locrm.setLogLevel('all');
    locrm.setEndpoint('https://wttr.in/' + wordCount[0]);
    var locResponse = locrm.execute();
    var locBody = locResponse.getBody();
    var matches = locBody.match(/Location: ([^[]+)\s/);

    if (matches[1]) weatherBody = weatherBody.replace(/[^:]+/, matches[1]);

    new x_snc_slackerbot.Slacker().send_chat(current, weatherBody);
} else {
    new x_snc_slackerbot.Slacker().send_chat(current, 'Please Provide Location Ex: "!weather london"');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant