Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
surykatka
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
surykatka
Commits
9274f2be
Commit
9274f2be
authored
Jun 07, 2024
by
Romain Courteaud
🐙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bot: add HTML output
parent
a37def25
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
1 deletion
+80
-1
src/surykatka/bot.py
src/surykatka/bot.py
+79
-0
src/surykatka/cli.py
src/surykatka/cli.py
+1
-1
No files found.
src/surykatka/bot.py
View file @
9274f2be
...
@@ -54,6 +54,7 @@ import datetime
...
@@ -54,6 +54,7 @@ import datetime
from
email.utils
import
parsedate_to_datetime
from
email.utils
import
parsedate_to_datetime
import
tempfile
import
tempfile
import
os
import
os
import
html
__version__
=
"0.8.0"
__version__
=
"0.8.0"
...
@@ -67,6 +68,82 @@ def rfc822(date):
...
@@ -67,6 +68,82 @@ def rfc822(date):
return
email
.
utils
.
format_datetime
(
date
)
return
email
.
utils
.
format_datetime
(
date
)
def
_
(
string_to_escape
):
return
html
.
escape
(
"%s"
%
string_to_escape
,
quote
=
False
)
def
__
(
string_to_escape
):
return
html
.
escape
(
"%s"
%
string_to_escape
,
quote
=
True
)
def
dumpStatusDictToHTML
(
status_dict
):
body_result
=
"<main>"
status_list
=
[]
append_status
=
status_list
.
append
for
table_key
in
status_dict
:
table
=
status_dict
[
table_key
]
if
table
:
append_status
(
"<table><caption>%s</caption><thead><tr>"
%
_
(
table_key
)
)
# Headers
table_key_list
=
[
x
for
x
in
table
[
0
].
keys
()]
table_key_list
.
sort
()
for
table_key
in
table_key_list
:
append_status
(
'<th scope="col">%s</th>'
%
_
(
table_key
))
append_status
(
"</tr></thead><tbody>"
)
# Status
for
line
in
table
:
append_status
(
"<tr>"
)
for
table_key
in
table_key_list
:
if
table_key
==
"url"
:
append_status
(
'<td><a href="%s">%s</a></td>'
%
(
__
(
line
[
table_key
]),
_
(
line
[
table_key
]))
)
elif
table_key
in
(
"domain"
,
"hostname"
):
append_status
(
'<td><a href="https://%s">%s</a></td>'
%
(
__
(
line
[
table_key
]),
_
(
line
[
table_key
]))
)
else
:
append_status
(
"<td>%s</td>"
%
_
(
line
[
table_key
]))
append_status
(
"</tr>"
)
append_status
(
"</tbody></table>"
)
body_result
+=
"
\
n
"
.
join
(
status_list
)
body_result
+=
"</main>"
result
=
(
"<!DOCTYPE html><html><head>"
'<meta name="viewport"
\
n
'
'content="width=device-width,height=device-height,'
'initial-scale=1" />'
"<title>Surykatka</title>"
"<style>"
"html {display: flex; justify-content: center;}
\
n
"
"body {width: 100%%; padding: 0 1em;"
" word-break: break-all; display: flex;"
" min-height: 100vh; flex-direction: column;}
\
n
"
"main {flex: 1;}
\
n
"
"html, body {height: 100%%; margin: 0;}
\
n
"
"table {border: 2px solid black; border-collapse: collapse;}
\
n
"
"caption {font-weight: bold;}
\
n
"
"th, td {border: 1px solid black; padding: 0 .5em}
\
n
"
"</style>
\
n
"
"</head><body>%(body)s</body></html>"
%
{
"body"
:
body_result
,
}
)
return
result
def
filterRecentStatus
(
status_dict
,
warning_period_duration
):
def
filterRecentStatus
(
status_dict
,
warning_period_duration
):
now
=
datetime
.
datetime
.
utcnow
()
now
=
datetime
.
datetime
.
utcnow
()
...
@@ -934,6 +1011,8 @@ class WebBot:
...
@@ -934,6 +1011,8 @@ class WebBot:
)
)
if
self
.
config
[
"FORMAT"
]
==
"json"
:
if
self
.
config
[
"FORMAT"
]
==
"json"
:
status_output
=
json
.
dumps
(
status_dict
)
status_output
=
json
.
dumps
(
status_dict
)
if
self
.
config
[
"FORMAT"
]
==
"html"
:
status_output
=
dumpStatusDictToHTML
(
status_dict
)
else
:
else
:
status_list
=
[]
status_list
=
[]
append_status
=
status_list
.
append
append_status
=
status_list
.
append
...
...
src/surykatka/cli.py
View file @
9274f2be
...
@@ -57,7 +57,7 @@ from .bot import create_bot
...
@@ -57,7 +57,7 @@ from .bot import create_bot
"--output"
,
"--output"
,
"-o"
,
"-o"
,
help
=
"The status output format."
,
help
=
"The status output format."
,
type
=
click
.
Choice
([
"plain"
,
"json"
]),
type
=
click
.
Choice
([
"plain"
,
"json"
,
"html"
]),
default
=
"plain"
,
default
=
"plain"
,
show_default
=
True
,
show_default
=
True
,
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment