本文整理汇总了Python中pushbullet.PushBullet.getPushHistory方法的典型用法代码示例。如果您正苦于以下问题:Python PushBullet.getPushHistory方法的具体用法?Python PushBullet.getPushHistory怎么用?Python PushBullet.getPushHistory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pushbullet.PushBullet
的用法示例。
在下文中一共展示了PushBullet.getPushHistory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import getPushHistory [as 别名]
class PBEventHandler:
def __init__(self):
self.KEY = KEY
self.HIST_FILE = HIST_FILE
self.pb = PushBullet(KEY)
self.maxmod = float(0)
self.iden = None
self._sync_maxmod()
self._sync_maxmod(self._get_modified())
devices = self.pb.getDevices()
for device in devices:
if device['nickname'] == DEVICE:
self.iden = device['iden']
break
def _get_modified(self):
return self.pb.getPushHistory(self.maxmod)
def _sync_maxmod(self, pushes = []):
for push in pushes:
if float(push['modified']) > self.maxmod:
self.maxmod = float(push['modified'])
n = float(self.maxmod)
try:
fn = float(open(self.HIST_FILE).read()) + 0.01
except:
fn = 0
fn = max(float(n), float(fn))
open(self.HIST_FILE, "w").write(str(fn))
self.maxmod = float(fn)
def _event(self, data, callback):
if data['type'] == 'tickle' and data['subtype'] == 'push':
pushes = self.pb.getPushHistory(self.maxmod)
for push in pushes:
if push['modified'] > self.maxmod:
self.maxmod = push['modified']
self._sync_maxmod()
if self.iden != None and\
push['target_device_iden'] != self.iden: continue
try:
callback(push)
except:
pass
def run(self, callback):
def __event(data):
print "event: " + str(data)
self._event(data, callback)
self.pb.realtime(__event)