Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
url-checker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
url-checker
Commits
b572ffec
Commit
b572ffec
authored
Oct 16, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add configuration file
parent
1c4c8adf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
15 deletions
+47
-15
urlchecker_cli.py
urlchecker_cli.py
+12
-6
urlchecker_http.py
urlchecker_http.py
+35
-9
No files found.
urlchecker_cli.py
View file @
b572ffec
...
...
@@ -8,14 +8,20 @@ def runUrlChecker():
@
runUrlChecker
.
command
(
"bot"
,
short_help
=
"Runs url checker bot."
)
@
click
.
argument
(
"url"
)
@
click
.
argument
(
"sqlite_path"
)
def
runWebBot
(
url
,
sqlite_path
):
from
urlchecker_http
import
WebBot
@
click
.
option
(
"--url"
,
"-u"
,
help
=
"The url to check."
)
@
click
.
option
(
"--sqlite"
,
"-s"
,
help
=
"The path of the sqlite DB."
)
@
click
.
argument
(
"configuration"
)
def
runWebBot
(
url
,
sqlite
,
configuration
):
from
urlchecker_http
import
create_bot
click
.
echo
(
"Running url checker bot"
)
bot
=
WebBot
()
return
bot
.
run
(
url
,
sqlite_path
)
mapping
=
{}
if
url
:
mapping
[
"URL"
]
=
url
if
sqlite
:
mapping
[
"SQLITE"
]
=
sqlite
bot
=
create_bot
(
cfgfile
=
configuration
,
mapping
=
mapping
)
return
bot
.
run
()
if
__name__
==
"__main__"
:
...
...
urlchecker_http.py
View file @
b572ffec
...
...
@@ -9,11 +9,14 @@ import dns.resolver
import
miniupnpc
import
platform
from
urlchecker_db
import
LogDB
import
configparser
import
os
__version__
=
"0.0.3"
PREFERRED_TYPE
=
"text/html"
TIMEOUT
=
2
CONFIG_SECTION
=
"URLCHECKER"
class
BotError
(
Exception
):
...
...
@@ -21,6 +24,10 @@ class BotError(Exception):
class
WebBot
:
def
__init__
(
self
):
self
.
config
=
configparser
.
ConfigParser
(
empty_lines_in_values
=
False
)
self
.
config
[
CONFIG_SECTION
]
=
{}
def
initDB
(
self
,
sqlite_path
):
self
.
_db
=
LogDB
(
sqlite_path
)
self
.
_db
.
createTables
()
...
...
@@ -110,9 +117,9 @@ class WebBot:
print
(
ip
,
hostname
,
response
.
status_code
)
def
run
(
self
,
url
,
sqlite_path
):
def
run
(
self
):
print
(
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
))
self
.
initDB
(
s
qlite_path
)
self
.
initDB
(
s
elf
.
config
[
CONFIG_SECTION
][
"SQLITE"
]
)
self
.
_db
.
storeEntry
(
platform
=
platform
.
platform
())
print
(
"Platform"
,
platform
.
platform
())
...
...
@@ -138,10 +145,29 @@ class WebBot:
except
Exception
:
pass
try
:
self
.
check
(
url
)
except
KeyboardInterrupt
:
self
.
stop
()
except
:
print
(
"Oups, error"
)
raise
for
url
in
self
.
config
[
CONFIG_SECTION
][
"URL"
].
split
():
try
:
self
.
check
(
url
)
except
KeyboardInterrupt
:
self
.
stop
()
except
:
print
(
"Oups, error"
)
raise
def
create_bot
(
envvar
=
"URLCHECKER_SETTINGS"
,
cfgfile
=
None
,
mapping
=
None
):
bot
=
WebBot
()
if
(
envvar
is
not
None
)
and
(
envvar
in
os
.
environ
):
bot
.
config
.
read
([
os
.
environ
.
get
(
envvar
)])
if
cfgfile
is
not
None
:
print
(
cfgfile
)
bot
.
config
.
read
([
cfgfile
])
if
mapping
is
not
None
:
bot
.
config
.
read_dict
({
CONFIG_SECTION
:
mapping
})
for
parameter
in
[
"URL"
,
"SQLITE"
]:
if
parameter
not
in
bot
.
config
[
CONFIG_SECTION
]:
raise
AttributeError
(
"Config %s not defined"
%
parameter
)
return
bot
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