Commit c2b9d57d authored by Romain Courteaud's avatar Romain Courteaud

Prototype storing http status code

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