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
0
Merge Requests
0
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
Romain Courteaud
surykatka
Commits
557155b4
Commit
557155b4
authored
Sep 10, 2021
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide file output for status
This allows to have better atomicity than shell redirection
parent
b498c212
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
src/surykatka/bot.py
src/surykatka/bot.py
+23
-6
src/surykatka/cli.py
src/surykatka/cli.py
+5
-0
No files found.
src/surykatka/bot.py
View file @
557155b4
...
...
@@ -51,6 +51,8 @@ from .ssl import (
)
import
datetime
from
email.utils
import
parsedate_to_datetime
import
tempfile
import
os
__version__
=
"0.6.0"
...
...
@@ -645,24 +647,39 @@ class WebBot:
float
(
self
.
config
[
"WARNING_PERIOD"
]),
)
if
self
.
config
[
"FORMAT"
]
==
"json"
:
print
(
json
.
dumps
(
status_dict
)
)
status_output
=
json
.
dumps
(
status_dict
)
else
:
status_list
=
[]
append_status
=
status_list
.
append
for
table_key
in
status_dict
:
print
(
"# %s"
%
table_key
)
print
(
""
)
append_status
(
"# %s"
%
table_key
)
append_status
(
""
)
table
=
status_dict
[
table_key
]
if
table
:
# Print the header
table_key_list
=
[
x
for
x
in
table
[
0
].
keys
()]
table_key_list
.
sort
()
print
(
" | "
.
join
(
table_key_list
))
append_status
(
" | "
.
join
(
table_key_list
))
for
line
in
table
:
print
(
append_status
(
" | "
.
join
(
[
"%s"
%
(
line
[
x
])
for
x
in
table_key_list
]
)
)
print
(
""
)
append_status
(
""
)
status_output
=
"
\
n
"
.
join
(
status_list
)
if
self
.
config
[
"STDOUT"
]
==
""
:
print
(
status_output
)
else
:
# https://blog.gocept.com/2013/07/15/reliable-file-updates-with-python/#write-replace
with
tempfile
.
NamedTemporaryFile
(
"w"
,
dir
=
os
.
path
.
dirname
(
self
.
config
[
"STDOUT"
]),
delete
=
False
,
)
as
temp_file
:
temp_file
.
write
(
status_output
)
temp_file_name
=
temp_file
.
name
os
.
rename
(
temp_file_name
,
self
.
config
[
"STDOUT"
])
def
create_bot
(
**
kw
):
...
...
src/surykatka/cli.py
View file @
557155b4
...
...
@@ -48,6 +48,9 @@ from .bot import create_bot
help
=
"Reload the configuration file between each crawl."
,
show_default
=
True
,
)
@
click
.
option
(
"--stdout"
,
help
=
"File to store status. (default: stdout)"
,
default
=
""
)
@
click
.
option
(
"--output"
,
"-o"
,
...
...
@@ -69,6 +72,7 @@ def runSurykatka(
warning
,
configuration
,
reload
,
stdout
,
output
,
profile
,
):
...
...
@@ -91,6 +95,7 @@ def runSurykatka(
mapping
[
"NAMESERVER"
]
=
nameserver
if
reload
:
mapping
[
"RELOAD"
]
=
str
(
reload
)
mapping
[
"STDOUT"
]
=
stdout
mapping
[
"FORMAT"
]
=
output
bot
=
create_bot
(
cfgfile
=
configuration
,
mapping
=
mapping
)
if
profile
is
None
:
...
...
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