本文整理汇总了Python中sickbeard.db.DBConnection.action方法的典型用法代码示例。如果您正苦于以下问题:Python DBConnection.action方法的具体用法?Python DBConnection.action怎么用?Python DBConnection.action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sickbeard.db.DBConnection
的用法示例。
在下文中一共展示了DBConnection.action方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sickbeard.db import DBConnection [as 别名]
# 或者: from sickbeard.db.DBConnection import action [as 别名]
class History:
date_format = '%Y%m%d%H%M%S'
def __init__(self):
self.db = DBConnection()
def clear(self):
self.db.action(
'DELETE '
'FROM history '
'WHERE 1 = 1'
)
def get(self, limit=100, action=None):
action = action.lower() if isinstance(action, str) else ''
limit = int(limit)
if action == 'downloaded':
actions = Quality.DOWNLOADED
elif action == 'snatched':
actions = Quality.SNATCHED
else:
actions = Quality.SNATCHED + Quality.DOWNLOADED
if limit == 0:
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',
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]
)
data = []
for result in results:
data.append({
'action': result['action'],
'date': result['date'],
'episode': result['episode'],
'provider': result['provider'],
'quality': result['quality'],
'resource': result['resource'],
'season': result['season'],
'show_id': result['showid'],
'show_name': result['show_name']
})
return data
def trim(self):
self.db.action(
'DELETE '
'FROM history '
'WHERE date < ?',
[(datetime.today() - timedelta(days=30)).strftime(History.date_format)]
)
示例2: __init__
# 需要导入模块: from sickbeard.db import DBConnection [as 别名]
# 或者: from sickbeard.db.DBConnection import action [as 别名]
class History:
date_format = '%Y%m%d%H%M%S'
def __init__(self):
self.db = DBConnection()
def clear(self):
"""
Clear all the history
"""
self.db.action(
'DELETE '
'FROM history '
'WHERE 1 = 1'
)
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
"""
actions = History._get_actions(action)
limit = History._get_limit(limit)
common_sql = 'SELECT action, date, episode, provider, h.quality, resource, season, show_name, showid ' \
'FROM history h, tv_shows s ' \
'WHERE h.showid = s.indexer_id '
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(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:
data.append({
'action': result['action'],
'date': result['date'],
'episode': result['episode'],
'provider': result['provider'],
'quality': result['quality'],
'resource': result['resource'],
'season': result['season'],
'show_id': result['showid'],
'show_name': result['show_name']
})
return data
def trim(self):
"""
Remove all elements older than 30 days from the history
"""
self.db.action(
'DELETE '
'FROM history '
'WHERE date < ?',
[(datetime.today() - timedelta(days=30)).strftime(History.date_format)]
)
@staticmethod
def _get_actions(action):
action = action.lower() if isinstance(action, (str, unicode)) else ''
if action == 'downloaded':
return Quality.DOWNLOADED
if action == 'snatched':
return Quality.SNATCHED
return []
@staticmethod
def _get_limit(limit):
limit = try_int(limit, 0)
return max(limit, 0)
示例3: History
# 需要导入模块: from sickbeard.db import DBConnection [as 别名]
# 或者: from sickbeard.db.DBConnection import action [as 别名]
class History(object):
date_format = '%Y%m%d%H%M%S'
def __init__(self):
self.db = DBConnection()
def clear(self):
"""
Clear all the history
"""
self.db.action(
'DELETE '
'FROM history '
'WHERE 1 = 1'
)
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
"""
# TODO: Make this a generator instead
# TODO: Split compact and detailed into separate methods
# TODO: Add a date limit as well
# TODO: Clean up history.mako
actions = History._get_actions(action)
limit = max(try_int(limit), 0)
common_sql = 'SELECT show_name, showid, season, episode, h.quality, ' \
'action, provider, resource, date ' \
'FROM history h, tv_shows s ' \
'WHERE h.showid = s.indexer_id '
filter_sql = 'AND action in (' + ','.join(['?'] * len(actions)) + ') '
order_sql = 'ORDER BY date DESC '
if actions:
sql_results = self.db.select(common_sql + filter_sql + order_sql,
actions)
else:
sql_results = self.db.select(common_sql + order_sql)
detailed = []
compact = dict()
# TODO: Convert to a defaultdict and compact items as needed
# TODO: Convert to using operators to combine items
for row in sql_results:
row = History.Item(*row)
if row.index in compact:
compact[row.index].actions.append(row.cur_action)
elif not limit or len(compact) < limit:
detailed.append(row)
compact[row.index] = row.compacted()
results = namedtuple('results', ['detailed', 'compact'])
return results(detailed, compact.values())
def trim(self, days=30):
"""
Remove expired elements from history
:param days: number of days to keep
"""
date = datetime.today() - timedelta(days)
self.db.action(
'DELETE '
'FROM history '
'WHERE date < ?',
[date.strftime(History.date_format)]
)
@staticmethod
def _get_actions(action):
action = action.lower() if isinstance(action, (str, unicode)) else ''
result = None
if action == 'downloaded':
result = Quality.DOWNLOADED
elif action == 'snatched':
result = Quality.SNATCHED
return result or []
action_fields = ('action', 'provider', 'resource', 'date', )
# A specific action from history
Action = namedtuple('Action', action_fields)
Action.width = len(action_fields)
index_fields = ('show_id', 'season', 'episode', 'quality', )
# An index for an item or compact item from history
Index = namedtuple('Index', index_fields)
Index.width = len(index_fields)
compact_fields = ('show_name', 'index', 'actions', )
# Related items compacted with a list of actions from history
CompactItem = namedtuple('CompactItem', compact_fields)
#.........这里部分代码省略.........