Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
ee95c38b
Commit
ee95c38b
authored
2 years ago
by
echicken
Browse files
Options
Downloads
Patches
Plain Diff
Cache stuff. Rearranged some things. Stuff like that.
parent
e7c208ae
No related branches found
No related tags found
1 merge request
!463
MRC mods by Codefenix (2024-10-20)
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
xtrn/wttr.in/readme.txt
+13
-4
13 additions, 4 deletions
xtrn/wttr.in/readme.txt
xtrn/wttr.in/wttr-lib.js
+52
-0
52 additions, 0 deletions
xtrn/wttr.in/wttr-lib.js
xtrn/wttr.in/wttr.js
+17
-18
17 additions, 18 deletions
xtrn/wttr.in/wttr.js
with
82 additions
and
22 deletions
xtrn/wttr.in/readme.txt
+
13
−
4
View file @
ee95c38b
...
...
@@ -33,10 +33,19 @@ Contents
3) Customization
Any arguments that you pass on the command line will be treated as an
alternate URL to query. For example:
The default query URL is https://wttr.in/?AFn for ANSI, no 'Follow' line,
and narrow output. You can override this by supplying an alternate URL on
the command line, such as:
Command Line ?wttr.js https://wttr.in/?m0AFn
The default is URL is 'https://wttr.in/?AFn' for ANSI, no 'Follow' line,
and narrow output.
Responses are cached in your OS temp directory and remain valid for 3600
seconds (one hour). You can override this default cache TTL by supplying
a numeric value (in seconds) on the command line, such as:
Command Line ?wttr.js 1800
You can combine the parameters in whichever order you prefer:
Command Line ?wttr.js https://wttr.in/?m0AFn 1800
Command Line ?wttr.js 1800 https://wttr.in/?m0AFn
This diff is collapsed.
Click to expand it.
xtrn/wttr.in/wttr-lib.js
0 → 100644
+
52
−
0
View file @
ee95c38b
require
(
'
http.js
'
,
'
HTTPRequest
'
);
const
locator
=
load
({},
js
.
exec_dir
+
'
locator.js
'
);
const
xterm
=
load
({},
js
.
exec_dir
+
'
xterm-colors.js
'
);
function
uReplace
(
str
)
{
return
str
.
replace
(
/
\x
E2
\x
9A
\x
A1/g
,
'
\
x01+
\
x01h
\
x01yZ
\
x01-
'
);
// U+26A1 Lightning bolt
}
function
getCacheName
(
qs
,
addr
)
{
const
cfn
=
format
(
'
wttr.in_%s_%s.ans
'
,
qs
,
addr
||
''
).
replace
(
/
[^
0-9a-z
\.]
+/ig
,
'
_
'
);
return
system
.
temp_path
+
cfn
;
}
function
readCache
(
qs
,
addr
,
ttl
)
{
const
cfn
=
getCacheName
(
qs
,
addr
);
const
f
=
new
File
(
cfn
);
if
(
!
f
.
exists
)
return
;
if
(
time
()
-
file_date
(
cfn
)
>
ttl
)
return
;
if
(
!
f
.
open
(
'
r
'
))
return
;
const
cache
=
f
.
read
();
f
.
close
();
return
cache
;
}
function
writeCache
(
qs
,
addr
,
ans
)
{
const
cfn
=
getCacheName
(
qs
,
addr
);
const
f
=
new
File
(
cfn
);
if
(
!
f
.
open
(
'
w
'
))
return
;
f
.
write
(
ans
);
f
.
close
();
}
function
fetchWeather
(
qs
,
addr
)
{
const
http
=
new
HTTPRequest
();
if
(
addr
!==
undefined
)
http
.
extra_headers
=
{
'
X-Forwarded-For
'
:
addr
};
const
body
=
http
.
Get
(
qs
);
if
(
http
.
response_code
!==
200
)
throw
new
Error
(
'
wttr.in response had status
'
+
http
.
response_code
);
return
body
;
}
function
getWeather
(
qs
,
ttl
)
{
const
addr
=
locator
.
getAddress
();
const
cachedWeather
=
readCache
(
qs
,
addr
,
ttl
);
if
(
cachedWeather
!==
undefined
)
return
cachedWeather
;
const
weather
=
fetchWeather
(
qs
,
addr
);
const
text
=
uReplace
(
weather
);
const
ansi
=
xterm
.
convertColors
(
text
);
writeCache
(
qs
,
addr
,
ansi
);
return
ansi
;
}
this
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
xtrn/wttr.in/wttr.js
+
17
−
18
View file @
ee95c38b
require
(
'
sbbsdefs.js
'
,
'
P_UTF8
'
);
require
(
'
http.js
'
,
'
HTTPRequest
'
);
const
xterm
=
load
({},
js
.
exec_dir
+
'
xterm-colors.js
'
);
const
locator
=
load
({},
js
.
exec_dir
+
'
locator.js
'
);
const
wttr
=
load
({},
js
.
exec_dir
+
'
wttr-lib.js
'
);
function
uReplace
(
str
)
{
return
str
.
replace
(
/
\x
E2
\x
9A
\x
A1/g
,
'
/
'
);
// U+26A1 Lightning bolt
}
function
fetchWeather
(
addr
)
{
const
qs
=
argc
>
0
?
argv
.
join
(
''
)
:
'
https://wttr.in/?AFn
'
;
const
http
=
new
HTTPRequest
();
if
(
addr
!==
undefined
)
http
.
extra_headers
=
{
'
X-Forwarded-For
'
:
addr
};
const
body
=
http
.
Get
(
qs
);
if
(
http
.
response_code
!==
200
)
throw
new
Error
(
'
wttr.in response had status
'
+
http
.
response_code
);
return
body
;
function
parseArgs
()
{
const
ret
=
{
qs
:
'
https://wttr.in/?AFn
'
,
ttl
:
3600
,
// Seconds
};
for
(
var
n
=
0
;
n
<
argc
;
n
++
)
{
const
arg
=
parseInt
(
argv
[
n
],
10
);
if
(
isNaN
(
arg
))
{
ret
.
qs
=
arg
;
}
else
{
ret
.
ttl
=
arg
;
}
}
return
ret
;
}
function
main
()
{
const
addr
=
locator
.
getAddress
();
const
weather
=
fetchWeather
(
addr
);
const
text
=
uReplace
(
weather
);
const
ansi
=
xterm
.
convertColors
(
text
);
const
args
=
parseArgs
();
const
ansi
=
wttr
.
getWeather
(
args
.
qs
,
args
.
ttl
);
const
attr
=
console
.
attributes
;
console
.
clear
(
BG_BLACK
|
LIGHTGRAY
);
console
.
putmsg
(
ansi
,
P_UTF8
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment