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

Infinite loop

parent c2b9d57d
...@@ -26,7 +26,7 @@ class BotError(Exception): ...@@ -26,7 +26,7 @@ class BotError(Exception):
class WebBot: class WebBot:
def __init__(self): def __init__(self):
self.config = configparser.ConfigParser(empty_lines_in_values=False) self.config = configparser.ConfigParser(empty_lines_in_values=False)
self.config[CONFIG_SECTION] = {} self.config[CONFIG_SECTION] = {"INTERVAL": 60}
def initDB(self, sqlite_path): def initDB(self, sqlite_path):
self._db = LogDB(sqlite_path) self._db = LogDB(sqlite_path)
...@@ -116,6 +116,17 @@ class WebBot: ...@@ -116,6 +116,17 @@ class WebBot:
) )
self._db.storeQuery(ip, url, response.status_code) 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): def run(self):
print(time.strftime("%Y-%m-%d %H:%M:%S")) print(time.strftime("%Y-%m-%d %H:%M:%S"))
self.initDB(self.config[CONFIG_SECTION]["SQLITE"]) self.initDB(self.config[CONFIG_SECTION]["SQLITE"])
...@@ -144,14 +155,17 @@ class WebBot: ...@@ -144,14 +155,17 @@ class WebBot:
except Exception: except Exception:
pass pass
for url in self.config[CONFIG_SECTION]["URL"].split(): self._running = True
try: try:
self.check(url) while self._running:
except KeyboardInterrupt: self.iterateLoop()
self.stop() time.sleep(self.config.getint(CONFIG_SECTION, "INTERVAL"))
except: except KeyboardInterrupt:
print("Oups, error") self.stop()
raise except:
self.stop()
print("Oups, error")
raise
def create_bot(envvar="URLCHECKER_SETTINGS", cfgfile=None, mapping=None): 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