Private GIT

Skip to content
Snippets Groups Projects
Commit 9fd8f65c authored by Gaëtan Muller's avatar Gaëtan Muller
Browse files
parent 97fa35dc
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,9 @@ class History:
self.db = DBConnection()
def clear(self):
"""
Clear all the history
"""
self.db.action(
'DELETE '
'FROM history '
......@@ -18,6 +21,13 @@ class History:
)
def get(self, limit=100, action=None):
"""
:param limit: The maximum number of elements to return
:param action: The type of action to filter in the history. Either 'downloaded' or 'snatched'. Anything else or
no value will return everything (up to ``limit``)
:return: The last ``limit`` elements of type ``action`` in the history
"""
action = action.lower() if isinstance(action, str) else ''
limit = int(limit)
......@@ -26,27 +36,24 @@ class History:
elif action == 'snatched':
actions = Quality.SNATCHED
else:
actions = Quality.SNATCHED + Quality.DOWNLOADED
actions = []
if limit == 0:
results = self.db.select(
'SELECT h.*, show_name '
'FROM history h, tv_shows s '
common_sql = 'SELECT h.*, show_name ' \
'FROM history h, tv_shows s ' \
'WHERE h.showid = s.indexer_id '
'AND action in (' + ','.join(['?'] * len(actions)) + ') '
'ORDER BY date DESC',
actions
)
filter_sql = 'AND action in (' + ','.join(['?'] * len(actions)) + ') '
order_sql = 'ORDER BY date DESC '
if limit == 0:
if len(actions) > 0:
results = self.db.select(common_sql + filter_sql + order_sql, actions)
else:
results = self.db.select(
'SELECT h.*, show_name '
'FROM history h, tv_shows s '
'WHERE h.showid = s.indexer_id '
'AND action in (' + ','.join(['?'] * len(actions)) + ') '
'ORDER BY date DESC '
'LIMIT ?',
actions + [limit]
)
results = self.db.select(common_sql + order_sql)
else:
if len(actions) > 0:
results = self.db.select(common_sql + filter_sql + order_sql + 'LIMIT ?', actions + [limit])
else:
results = self.db.select(common_sql + order_sql + 'LIMIT ?', [limit])
data = []
for result in results:
......@@ -65,6 +72,10 @@ class History:
return data
def trim(self):
"""
Remove all elements older than 30 days from the history
"""
self.db.action(
'DELETE '
'FROM history '
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment