Added blacklist feature (untested)

This commit is contained in:
Simon
2018-06-06 10:17:30 -04:00
parent cfa6a9f02f
commit 0b1d76f478
6 changed files with 77 additions and 20 deletions

View File

@@ -87,11 +87,14 @@ class Database:
conn.commit()
# Then insert files
cursor.execute("PRAGMA foreign_keys = OFF")
conn.commit()
cursor.executemany("INSERT INTO File (path_id, name, size, mime_id) VALUES (?,?,?,?)",
[(website_paths[x.path], x.name, x.size, mimetypes[x.mime]) for x in files])
# Update date
if len(files) > 0:
cursor.execute("UPDATE Website SET last_modified=CURRENT_TIMESTAMP WHERE id = ?",
(files[0].website_id, ))
conn.commit()
def import_json(self, json_file, website: Website):
@@ -302,6 +305,21 @@ class Database:
website_id = cursor.fetchone()
return website_id[0] if website_id else None
def website_has_been_scanned(self, url):
"""Check if a website has at least 1 file"""
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
website_id = self.website_exists(url)
if website_id:
cursor.execute("SELECT COUNT(Path.id) FROM Website "
"INNER JOIN WebsitePath Path on Website.id = Path.website_id "
"WHERE Website.id = ?", (website_id, ))
return cursor.fetchone()[0] > 0
return None
def clear_website(self, website_id):
"""Remove all files from a website and update its last_updated date"""
with sqlite3.connect(self.db_path) as conn: