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
d9b026da
Commit
d9b026da
authored
Jun 10, 2022
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bot: add recent status to see latest updates
parent
55e40205
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
3 deletions
+50
-3
src/surykatka/bot.py
src/surykatka/bot.py
+47
-2
src/surykatka/cli.py
src/surykatka/cli.py
+3
-1
No files found.
src/surykatka/bot.py
View file @
d9b026da
...
...
@@ -67,6 +67,29 @@ def rfc822(date):
return
email
.
utils
.
format_datetime
(
date
)
def
filterRecentStatus
(
status_dict
,
warning_period_duration
):
now
=
datetime
.
datetime
.
utcnow
()
del
status_dict
[
"bot_status"
]
del
status_dict
[
"warning"
]
del
status_dict
[
"missing_data"
]
for
status_key
in
list
(
status_dict
.
keys
()):
for
i
in
range
(
len
(
status_dict
[
status_key
])
-
1
,
-
1
,
-
1
):
status_date
=
parsedate_to_datetime
(
status_dict
[
status_key
][
i
][
"date"
]
)
if
(
warning_period_duration
)
<
(
now
-
status_date
).
total_seconds
():
del
status_dict
[
status_key
][
i
]
status_dict
[
status_key
].
sort
(
key
=
lambda
x
:
parsedate_to_datetime
(
x
[
"date"
])
)
if
not
status_dict
[
status_key
]:
del
status_dict
[
status_key
]
def
filterWarningStatus
(
status_dict
,
interval
,
...
...
@@ -836,7 +859,14 @@ class WebBot:
def
run
(
self
,
mode
):
status_dict
=
None
if
mode
not
in
[
"crawl"
,
"pack"
,
"status"
,
"warning"
,
"error"
]:
if
mode
not
in
[
"crawl"
,
"pack"
,
"status"
,
"recent"
,
"warning"
,
"error"
,
]:
raise
NotImplementedError
(
"Unexpected mode: %s"
%
mode
)
if
self
.
config
[
"SQLITE"
]
==
":memory:"
:
...
...
@@ -845,13 +875,21 @@ class WebBot:
mode
=
"wallwarning"
elif
mode
==
"error"
:
mode
=
"wallerror"
elif
mode
==
"recent"
:
mode
=
"wallrecent"
else
:
mode
=
"all"
self
.
initDB
()
try
:
if
mode
in
[
"crawl"
,
"wallwarning"
,
"wallerror"
,
"all"
]:
if
mode
in
[
"crawl"
,
"wallwarning"
,
"wallerror"
,
"wallrecent"
,
"all"
,
]:
self
.
crawl
()
if
mode
in
[
"status"
,
...
...
@@ -860,6 +898,8 @@ class WebBot:
"warning"
,
"wallerror"
,
"error"
,
"wallrecent"
,
"recent"
,
]:
status_dict
=
self
.
status
()
if
mode
==
"pack"
:
...
...
@@ -879,6 +919,11 @@ class WebBot:
float
(
self
.
config
[
"WARNING_PERIOD"
]),
keep_warning
=
(
"warning"
in
mode
),
)
elif
mode
in
(
"wallrecent"
,
"recent"
):
filterRecentStatus
(
status_dict
,
float
(
self
.
config
[
"WARNING_PERIOD"
]),
)
if
self
.
config
[
"FORMAT"
]
==
"json"
:
status_output
=
json
.
dumps
(
status_dict
)
else
:
...
...
src/surykatka/cli.py
View file @
d9b026da
...
...
@@ -29,7 +29,9 @@ from .bot import create_bot
help
=
"The bot operation mode to run."
,
show_default
=
True
,
default
=
"status"
,
type
=
click
.
Choice
([
"crawl"
,
"pack"
,
"status"
,
"warning"
,
"error"
]),
type
=
click
.
Choice
(
[
"crawl"
,
"pack"
,
"status"
,
"recent"
,
"warning"
,
"error"
]
),
)
@
click
.
option
(
"--sqlite"
,
"-s"
,
help
=
"The path of the sqlite DB. (default: :memory:)"
...
...
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