Skip to content
Snippets Groups Projects
Commit e7c208ae authored by echicken's avatar echicken :chicken:
Browse files

Treat command line argument as an alternate URL.

This allows for greater flexibility with the options, and the
possibility of querying your own (or some other) wttr server.
parent e844d66d
Branches
Tags
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -33,14 +33,10 @@ Contents ...@@ -33,14 +33,10 @@ Contents
3) Customization 3) Customization
Please see https://wttr.in/:help for a list of options. You may pass any Any arguments that you pass on the command line will be treated as an
of the 'Units' and 'View options' values to this script on the command alternate URL to query. For example:
line to customize the output, for example:
Command Line ?wttr.js m0AFn Command Line ?wttr.js https://wttr.in/?m0AFn
The default is 'AFn' for ANSI, no 'Follow' line, and narrow output. The default is URL is 'https://wttr.in/?AFn' for ANSI, no 'Follow' line,
and narrow output.
Note that your command line argument will completely replace the default
parameters. You will probably want to specify 'A' and 'n' in addition to
your chosen values.
...@@ -8,10 +8,10 @@ function uReplace(str) { ...@@ -8,10 +8,10 @@ function uReplace(str) {
} }
function fetchWeather(addr) { function fetchWeather(addr) {
const qs = argc > 0 ? argv.join('') : 'AFn'; const qs = argc > 0 ? argv.join('') : 'https://wttr.in/?AFn';
const http = new HTTPRequest(); const http = new HTTPRequest();
if (addr !== undefined) http.extra_headers = { 'X-Forwarded-For': addr }; if (addr !== undefined) http.extra_headers = { 'X-Forwarded-For': addr };
const body = http.Get('https://wttr.in/?' + qs); const body = http.Get(qs);
if (http.response_code !== 200) throw new Error('wttr.in response had status ' + http.response_code); if (http.response_code !== 200) throw new Error('wttr.in response had status ' + http.response_code);
return body; return body;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment