Data package
Description
Data storage and fetch
db_manager
DBManager class
- class module.data.db_manager.DbManager
Bases:
object
Class that handles the management of databases
- classmethod count_from(table_name, select='*', where='', where_args=None, group_by='')
Returns the number of rows found with the query. Executes “SELECT COUNT(select) FROM table_name [WHERE where (with where_args)]”
- Parameters:
table_name (
str
) – name of the table used in the FROMselect (
str
) – columns considered for the query. Defaults to “*”.where (
str
) – where clause, with ? placeholders for the where_args. Defaults to “”.where_args (
Optional
[tuple
]) – args used in the where clause. Defaults to None.group_by (
str
) – group by clause. Defaults to “”.
- Return type:
int
- Returns:
number of rows
- classmethod delete_from(table_name, where='', where_args=None)
Deletes the rows from the specified table, where the condition, when set, is satisfied. Executes “DELETE FROM table_name [WHERE where (with where_args)]”
- Parameters:
table_name (
str
) – name of the table used in the DELETE FROMwhere (
str
) – where clause, with ? placeholders for the where args. Defaults to “”.where_args (
Optional
[tuple
]) – args used in the where clause. Defaults to None.
- static get_db(db_path='data/DMI_DB.db')
Creates the connection to the database
- Parameters:
db_path (
str
) – path/name.- Return type:
Tuple
[Connection
,Cursor
]- Returns:
sqlite database connection and cursor
- classmethod insert_into(table_name, values, columns='', multiple_rows=False)
Inserts the specified values in the database. Executes “INSERT INTO table_name ([columns]) VALUES (placeholders)”
- Parameters:
table_name (
str
) – name of the table used in the INSERT INTOvalues (
tuple
) – values to be inserted. If multiple_rows is true, tuple of tuples of values to be insertedcolumns (
tuple
) – columns that will be inserted, as a tuple of strings. Defaults to None.multiple_rows (
bool
) – whether or not multiple rows will be inserted at the same time
- classmethod query_from_file(filename='data/DMI_DB.sql')
Commits all the queries in the specified file. Each query must end with a “);” and a carriage return
- Parameters:
filename (
str
) – path/name of the text file containing the queries
- classmethod query_from_string(*queries)
Commits all the queries in the string. Should not be used to select something
- Parameters:
queries (
str
) – tuple of queries
- classmethod select_from(table_name, select='*', where='', where_args=None, group_by='', order_by='')
Returns the results of a query. Executes “SELECT select FROM table_name [WHERE where (with where_args)] [GROUP BY group_by] [ORDER BY order_by]”
- Parameters:
table_name (
str
) – name of the table used in the FROMselect (
str
) – columns considered for the query. Defaults to “*”.where (
str
) – where clause, with ? placeholders for the where_args. Defaults to “”.where_args (
Optional
[tuple
]) – args used in the where clause. Defaults to None.group_by (
str
) – group by clause. Defaults to “”.order_by (
str
) – order by clause. Defaults to “”.
- Return type:
list
- Returns:
rows from the select
- module.data.db_manager.dict_factory(cursor, row)
Makes so that the cursor is a list of dictionaries with column names as keys
- Parameters:
cursor (
Cursor
) – cursor generated by the databaserow (
Row
) – rows of the database
- Return type:
dict
- Returns:
structure of the database used used by the cursor
easter_egg
EasterEgg class
exam
Exam class
- class module.data.exam.Exam(anno='', cdl='', insegnamento='', docenti='')
Bases:
Scrapable
- anno
[1° anno | 2° anno | 3° anno]
- Type:
str
- cdl
“Corso Di Laurea”
- Type:
str
- insegnamento
subject of the exam
- Type:
str
- docenti
name of the teacher
- Type:
str
- prima
list of appeals in the first session
- Type:
list | str
- seconda
list of appeals in the second session
- Type:
list | str
- terza
list of appeals in the second session
- Type:
list | str
- straordinaria
list of appeals in the “straordinaria” session
- Type:
list | str
- COURSES = ['l-31', 'lm-18', 'l-35', 'lm-40']
- SESSIONS = ['prima', 'seconda', 'terza', 'straordinaria']
- classmethod append_multiple_sessions(cells, exam, session)
- append_session(session_name, to_append)
Appends an element to a session based on its name.
- Parameters:
session_name (
str
) – [ prima | seconda | terza | straordinaria ]to_append (
str
) – element to append
- property columns: tuple
tuple of column names of the database table that will store this Exam
- delete()
Deletes this exam from the database
- classmethod find(select_sessione='', where_sessione='', where_anno='', where_insegnamento='')
Produces a list of exams from the database, based on the provided parametes
- Parameters:
select_sessione (
str
) – which sessions to select. Defaults to “”.where_sessione (
str
) – specifies what sessions can’t be []. Defaults to “”.where_anno (
str
) – specifies the year. Defaults to “”.where_insegnamento (
str
) – specifies the subject. Defaults to “”.
- Return type:
List
[Exam
]- Returns:
result of the query on the database
- classmethod find_all()
Finds all the exams present in the database
- Return type:
List
[Exam
]- Returns:
list of all the exams
- get_session(session_name)
Gets the session with the same name.
- Parameters:
session_name (
str
) – [ prima | seconda | terza | straordinaria ]- Return type:
Optional
[list
]- Returns:
session
- classmethod scrape(year_exams, delete=False)
Scrapes the exams of the provided year and stores them in the database
- Parameters:
year_exams (
str
) – current yeardelete (
bool
) – whether the table contents should be deleted first. Defaults to False.
- property table: str
name of the database table that will store this Exam
- property values: tuple
tuple of values that will be saved in the database
lesson
Lesson class
- class module.data.lesson.Lesson(nome='', giorno_settimana='', ora_inizio='', ora_fine='', aula='', anno='', semestre='')
Bases:
Scrapable
- nome
name of the subject
- Type:
str
- giorno_settimana
day of the week
- Type:
str
- ora_inizio
starting time of the lesson
- Type:
str
- ora_fine
ending time of the lesson
- Type:
str
- aula
hall
- Type:
str
- anno
year
- Type:
str
- semestre
semester
- Type:
str
- DAY_TO_INT = {'GIO': 4, 'LUN': 1, 'MAR': 2, 'MER': 3, 'VEN': 5}
- IDS = ['l-31', 'l-35', 'lm-18', 'lm-40']
- INT_TO_DAY = {'1': 'LUN', '2': 'MAR', '3': 'MER', '4': 'GIO', '5': 'VEN'}
- property columns: tuple
tuple of column names of the database table that will store this Lesson
- classmethod find(where_anno='', where_giorno='', where_nome='')
Produces a list of lessons from the database, based on the provided parametes
- Parameters:
where_anno (
str
) – specifies the year. Defaults to “”.where_giorno (
str
) – specifies the day. Defaults to “”.where_nome (
str
) – specifies the name of the subject. Defaults to “”.
- Return type:
List
[Lesson
]- Returns:
result of the query on the database
- classmethod find_all()
Finds all the lessons present in the database
- Return type:
List
[Lesson
]- Returns:
list of all the lessons
- classmethod scrape(year_exams, delete=False)
Scrapes the lessons of the provided year and stores them in the database
- Parameters:
year_exams (
str
) – current yeardelete (
bool
) – whether the table contents should be deleted first. Defaults to False.
- property table: str
name of the database table that will store this Lesson
professor
Professor class
- class module.data.professor.Professor(ID=-1, ruolo='', nome='', scheda_dmi='', fax='', telefono='', email='', ufficio='', sito='', photo_id='')
Bases:
Scrapable
- ID
primary key of the table
- Type:
int
- ruolo
role of the professor
- Type:
str
- nome
name of the professor
- Type:
str
- scheda_dmi
web-page about the professor
- Type:
str
- fax
fax of the professor
- Type:
str
- telefono
phone number of the professor
- Type:
str
- email
e-mail of the professor
- Type:
str
- ufficio
which office belogs to the professor
- Type:
str
- sito
orcid page of the professor
- Type:
str
- photo_id
photo id of the professor’s page
- Type:
str
- URL_PROF = 'http://web.dmi.unict.it/docenti'
- property columns: tuple
tuple of column names of the database table that will store this Professor
- classmethod find(where_name)
Produces a list of professors from the database, based on the provided parametes
- Parameters:
where_name (
str
) – specifies the name of the professor- Return type:
List
[Professor
]- Returns:
result of the query on the database
- classmethod find_all()
Finds all the professors present in the database
- Return type:
List
[Professor
]- Returns:
list of all the professors
- classmethod scrape(delete=False)
Scrapes all the professors and stores them in the database
- Parameters:
delete (
bool
) – whether the table contents should be deleted first. Defaults to False.
- property table: str
name of the database table that will store this Lesson
- module.data.professor.em(text)
Alias for escape_markdown function
scrapable
Scrapable abstract class
- class module.data.scrapable.Scrapable
Bases:
object
Abstract class base of everything that is to be scraped and saved in the database
- classmethod bulk_save(scrapables)
Saves multiple Scrapable objects at once in the database
- Parameters:
scrapables (
list
) – list of Scrapable objects to save
- property columns
tuple of column names of the database table that will store this Scrapable
- classmethod count(where='', where_args=None, group_by='')
Count the number of scrapable objects present in the database, based on the parameters
- Parameters:
where (
str
) – where clause, with ? placeholders for the where_args. Defaults to “”.where_args (
Optional
[tuple
]) – args used in the where clause. Defaults to None.group_by (
str
) – group by clause. Defaults to “”.
- Return type:
int
- Returns:
number of scrapable objects
- delete()
Deletes this scrapable object from the database
- classmethod delete_all()
Deletes all the scrapable objects of this kind from the database
- classmethod find_all()
Finds all the scrapable objects present in the database
- Return type:
list
- Returns:
list of all the scrapable objects
- save()
Saves this scrapable object in the database
- property table
name of the database table that will store this Scrapable
- property values
tuple of values that will be saved in the database
timetable_slot
TimetableSlot class
- class module.data.timetable_slot.TimetableSlot(ID=0, nome='', giorno=0, ora_inizio='', ora_fine='', aula='')
Bases:
Scrapable
- ID
id of the TimetableSlot
- Type:
int
- nome
name of the subject
- Type:
str
- giorno
days from today
- Type:
str
- ora_inizio
starting time of the lesson
- Type:
str
- ora_fine
ending time of the lesson
- Type:
str
- aula
hall
- Type:
str
- property columns: tuple
tuple of column names of the database table that will store this TimetableSlot
- property end_hour: str
adds half an hour to the ora_fine value
- classmethod find(**kwargs)
Produces a list of scrapables from the database, based on the provided parametes
- Return type:
List
[TimetableSlot
]- Returns:
result of the query on the database
- classmethod find_all()
Finds all the timetable slots present in the database
- Return type:
List
[TimetableSlot
]- Returns:
list of all the timetable slots
- classmethod get_max_giorno()
Finds the maximum value of giorno
- Return type:
int
- Returns:
result of the query on the database
- property is_still_to_come: bool
whether or not the current time slot is still to come or has already passed
- classmethod scrape(delete=False)
Scrapes the timetable slots of the provided year and stores them in the database
- Parameters:
delete (
bool
) – whether the table contents should be deleted first. Defaults to False.
- property table: str
name of the database table that will store this TimetableSlot