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():
...
@@ -8,14 +8,20 @@ def runUrlChecker():
@
runUrlChecker
.
command
(
"bot"
,
short_help
=
"Runs url checker bot."
)
@
runUrlChecker
.
command
(
"bot"
,
short_help
=
"Runs url checker bot."
)
@
click
.
argument
(
"url"
)
@
click
.
option
(
"--url"
,
"-u"
,
help
=
"The url to check."
)
@
click
.
argument
(
"sqlite_path"
)
@
click
.
option
(
"--sqlite"
,
"-s"
,
help
=
"The path of the sqlite DB."
)
def
runWebBot
(
url
,
sqlite_path
):
@
click
.
argument
(
"configuration"
)
from
urlchecker_http
import
WebBot
def
runWebBot
(
url
,
sqlite
,
configuration
):
from
urlchecker_http
import
create_bot
click
.
echo
(
"Running url checker bot"
)
click
.
echo
(
"Running url checker bot"
)
bot
=
WebBot
()
mapping
=
{}
return
bot
.
run
(
url
,
sqlite_path
)
if
url
:
mapping
[
"URL"
]
=
url
if
sqlite
:
mapping
[
"SQLITE"
]
=
sqlite
bot
=
create_bot
(
cfgfile
=
configuration
,
mapping
=
mapping
)
return
bot
.
run
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
urlchecker_http.py
View file @
b572ffec
...
@@ -9,11 +9,14 @@ import dns.resolver
...
@@ -9,11 +9,14 @@ import dns.resolver
import
miniupnpc
import
miniupnpc
import
platform
import
platform
from
urlchecker_db
import
LogDB
from
urlchecker_db
import
LogDB
import
configparser
import
os
__version__
=
"0.0.3"
__version__
=
"0.0.3"
PREFERRED_TYPE
=
"text/html"
PREFERRED_TYPE
=
"text/html"
TIMEOUT
=
2
TIMEOUT
=
2
CONFIG_SECTION
=
"URLCHECKER"
class
BotError
(
Exception
):
class
BotError
(
Exception
):
...
@@ -21,6 +24,10 @@ class BotError(Exception):
...
@@ -21,6 +24,10 @@ class BotError(Exception):
class
WebBot
:
class
WebBot
:
def
__init__
(
self
):
self
.
config
=
configparser
.
ConfigParser
(
empty_lines_in_values
=
False
)
self
.
config
[
CONFIG_SECTION
]
=
{}
def
initDB
(
self
,
sqlite_path
):
def
initDB
(
self
,
sqlite_path
):
self
.
_db
=
LogDB
(
sqlite_path
)
self
.
_db
=
LogDB
(
sqlite_path
)
self
.
_db
.
createTables
()
self
.
_db
.
createTables
()
...
@@ -110,9 +117,9 @@ class WebBot:
...
@@ -110,9 +117,9 @@ class WebBot:
print
(
ip
,
hostname
,
response
.
status_code
)
print
(
ip
,
hostname
,
response
.
status_code
)
def
run
(
self
,
url
,
sqlite_path
):
def
run
(
self
):
print
(
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
))
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
())
self
.
_db
.
storeEntry
(
platform
=
platform
.
platform
())
print
(
"Platform"
,
platform
.
platform
())
print
(
"Platform"
,
platform
.
platform
())
...
@@ -138,10 +145,29 @@ class WebBot:
...
@@ -138,10 +145,29 @@ class WebBot:
except
Exception
:
except
Exception
:
pass
pass
try
:
for
url
in
self
.
config
[
CONFIG_SECTION
][
"URL"
].
split
():
self
.
check
(
url
)
try
:
except
KeyboardInterrupt
:
self
.
check
(
url
)
self
.
stop
()
except
KeyboardInterrupt
:
except
:
self
.
stop
()
print
(
"Oups, error"
)
except
:
raise
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