Commit c2b9d57d authored by Romain Courteaud's avatar Romain Courteaud

Prototype storing http status code

parent b572ffec
......@@ -31,7 +31,13 @@ class LogDB:
class Meta:
order_by = ["id"]
class Query(BaseModel):
ip = peewee.TextField()
url = peewee.TextField()
status = peewee.IntegerField()
self.Entry = Entry
self.Query = Query
def createTables(self):
# http://www.sqlite.org/pragma.html#pragma_user_version
......@@ -40,10 +46,10 @@ class LogDB:
print(db_version)
if db_version == 0:
with self._db.transaction():
self._db.create_tables([self.Entry])
self._db.create_tables([self.Entry, self.Query])
self._db.pragma("user_version", expected_version)
elif db_version != expected_version:
migrator = SqliteMigrator(self._db)
# migrator = SqliteMigrator(self._db)
migration_list = []
sql_query_list = []
......@@ -73,3 +79,10 @@ class LogDB:
id = entry.id
return id
def storeQuery(self, ip, url, status):
with self._db.atomic():
entry = self.Query.create(ip=ip, url=url, status=status)
id = entry.id
return id
......@@ -93,8 +93,8 @@ class WebBot:
def check(self, url):
parsed_url = urlparse(url)
response = self.request("GET", url)
print(url, response.status_code)
# response = self.request("GET", url)
# print(url, response.status_code)
# Get the list of available IPv4 frontend CDN
hostname = parsed_url.hostname
......@@ -114,8 +114,7 @@ class WebBot:
response = self.request(
"GET", url, headers={"Host": hostname}, session=session
)
print(ip, hostname, response.status_code)
self._db.storeQuery(ip, url, response.status_code)
def run(self):
print(time.strftime("%Y-%m-%d %H:%M:%S"))
......
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