Commit 7479fca7 authored by Romain Courteaud's avatar Romain Courteaud

Infinite loop

parent c2b9d57d
......@@ -26,7 +26,7 @@ class BotError(Exception):
class WebBot:
def __init__(self):
self.config = configparser.ConfigParser(empty_lines_in_values=False)
self.config[CONFIG_SECTION] = {}
self.config[CONFIG_SECTION] = {"INTERVAL": 60}
def initDB(self, sqlite_path):
self._db = LogDB(sqlite_path)
......@@ -116,6 +116,17 @@ class WebBot:
)
self._db.storeQuery(ip, url, response.status_code)
def iterateLoop(self):
for url in self.config[CONFIG_SECTION]["URL"].split():
self.check(url)
def stop(self):
print("Bye bye")
print(time.strftime("%Y-%m-%d %H:%M:%S"))
self._running = False
if hasattr(self, "_db"):
self._db.close()
def run(self):
print(time.strftime("%Y-%m-%d %H:%M:%S"))
self.initDB(self.config[CONFIG_SECTION]["SQLITE"])
......@@ -144,14 +155,17 @@ class WebBot:
except Exception:
pass
for url in self.config[CONFIG_SECTION]["URL"].split():
try:
self.check(url)
except KeyboardInterrupt:
self.stop()
except:
print("Oups, error")
raise
self._running = True
try:
while self._running:
self.iterateLoop()
time.sleep(self.config.getint(CONFIG_SECTION, "INTERVAL"))
except KeyboardInterrupt:
self.stop()
except:
self.stop()
print("Oups, error")
raise
def create_bot(envvar="URLCHECKER_SETTINGS", cfgfile=None, mapping=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment