本文整理汇总了Python中sender.Sender.create_from_db方法的典型用法代码示例。如果您正苦于以下问题:Python Sender.create_from_db方法的具体用法?Python Sender.create_from_db怎么用?Python Sender.create_from_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sender.Sender
的用法示例。
在下文中一共展示了Sender.create_from_db方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sender_query
# 需要导入模块: from sender import Sender [as 别名]
# 或者: from sender.Sender import create_from_db [as 别名]
def sender_query(self, mac=None, sort='last_seen', time_window=None, advanced=None, count=None):
"""Query the database for a sender by it's MAC address.
If mac is None - return a list of all senders.
sort can start with `-' to change sort direction
time_window - recently seen (X seconds) senders only
"""
# Parse sorting order
direction = 1
if sort.startswith('-'):
direction = -1
sort = sort[1:]
# Build query
where = {}
if mac is not None:
where['mac'] = mac.lower()
if time_window:
now = time()
where['aggregate.last_seen'] = {
'$gt': now - time_window
}
if advanced is not None:
where.update(advanced)
senders = self.knowledge.find(where).sort(sort, direction)
if count is not None:
senders = senders[:count]
return Sender.create_from_db(senders)