1
0
mirror of https://github.com/tiyn/stud.ip-crawler.git synced 2026-02-22 06:34:48 +01:00

Documentation: added docstrings

This commit is contained in:
TiynGER
2020-10-25 16:22:02 +01:00
parent a5d7b0304b
commit 6f9ef9bbd6
3 changed files with 123 additions and 0 deletions

View File

@@ -17,6 +17,9 @@ class Database:
self.setup_db()
def connect(self):
"""
Connect to an existing database instance based on the object attributes.
"""
return pymysql.connect(
host=self.HOST,
port=self.PORT,
@@ -27,6 +30,9 @@ class Database:
)
def setup_db(self):
"""
Creates a database with tables.
"""
db = self.connect()
crs = db.cursor()
sql_query = "CREATE DATABASE IF NOT EXISTS " + self.NAME
@@ -40,6 +46,13 @@ class Database:
log.debug(db)
def set_last_file_dl(self, file_id, time):
"""
Insert a downloaded file to the database.
Parameters:
file_id (string): id of the file downloaded
time(int): time the file was downloaded
"""
db = self.connect()
db.select_db(self.NAME)
crs = db.cursor()
@@ -51,6 +64,15 @@ class Database:
db.commit()
def get_last_file_dl(self, file_id):
"""
Check when a file was downloaded.
Parameters:
file_id(string): id of the file to check
Returns:
int: time when the file was downloaded last. None if it wasnt downloaded.
"""
if self.RESET_DL:
return None
db = self.connect()