本文整理汇总了Python中pushbullet.PushBullet.upload_file方法的典型用法代码示例。如果您正苦于以下问题:Python PushBullet.upload_file方法的具体用法?Python PushBullet.upload_file怎么用?Python PushBullet.upload_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pushbullet.PushBullet
的用法示例。
在下文中一共展示了PushBullet.upload_file方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import upload_file [as 别名]
class PushBulletAlert:
def __init__(self, api_key, imagedir):
self.pb = PushBullet(api_key)
self.imagedir = imagedir
def sendAlert(self, image):
imagedata = open(os.path.join(self.imagedir, image), 'rb')
success, file_data = self.pb.upload_file(imagedata, 'Motion detected: ' + image)
success, push = self.pb.push_file(**file_data)
return success
示例2: pushSelfie
# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import upload_file [as 别名]
def pushSelfie(message):
try:
p = PushBullet(apiKey)
myPhone = p.devices[0]
print("uploading")
with open('/home/pi/sb/selfie.jpg', "rb") as pic:
file_data = p.upload_file(pic,"selfie.jpg")
file_data = str(file_data)
fileURL = file_data[file_data.find("https"):file_data.find("'})")]
print (fileURL)
myPhone.push_file(file_url=fileURL,file_name="selfie.jpg",file_type="image/jpeg")
except: #todo: gracefully handle exceptions, wouldya
e = sys.exc_info()[0]
print(e)
示例3: take_photo_and_push
# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import upload_file [as 别名]
def take_photo_and_push(pushbullet_auth_key, pushbullet_device_names):
""" Takes a photo and sends to the cloud via PushBullet.
Implements pushbullet.py, see https://pypi.python.org/pypi/pushbullet.py
Implements picamera.py, see http://raspberrypi.org/picamera-pure-python-interface-for-camera-module
"""
file_name = datetime.datetime.now().strftime("%I:%M%p %m-%d-%Y") + '.jpg'
file_path = os.path.join('/home/pi', file_name)
with picamera.PiCamera() as camera:
camera.vflip = True
camera.hflip = True
camera.resolution = (1024, 768)
camera.capture(file_path)
pb = PushBullet(pushbullet_auth_key)
with open(file_path, 'rb') as pic:
message = 'SmartDoor ' + re.sub('.png', "", file_name)
success, file_data = pb.upload_file(pic, message, 'image/jpeg',)
upload_message = "{0} uploading picture {1} to url {2}".format(
'Success' if str(success) else 'Failure',
file_data.get('file_name'),
file_data.get('file_url'))
print(upload_message)
devices = pb.devices
if any([item in pushbullet_device_names for item in pushbullet_device_names]):
for deviceName in pushbullet_device_names:
device_list = [d for d in devices if d.nickname == deviceName and d.active]
device = device_list[0] if device_list else None
if device is not None:
success, push = device.push_file(**file_data)
print('Successfully pushed ' + push.get('iden') + ' to ' + device.nickname)
else:
success, push = pb.push_file(**file_data)
print('Successfully pushed ' + push.get('iden') + ' to all devices')
os.remove(file_path)
示例4: PushBullet
# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import upload_file [as 别名]
#!/usr/python
from pushbullet import PushBullet
from subprocess import call
import time
pb = PushBullet('KEY_HERE')
while True:
call(["streamer","-f", "jpeg", "-o","image.jpeg"])
with open("image.jpeg", "rb") as pic:
success, file_data = pb.upload_file(pic, "picture.jpg")
success, push = pb.push_file(**file_data)
time.sleep(600)
示例5: PushBullet
# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import upload_file [as 别名]
from pushbullet import PushBullet
api_key = "q3U8S546S0D8tHJb8PrCzHaKABoHbnZy"
pb = PushBullet(api_key)
with open("gem1.png", "rb") as pic:
file_data = pb.upload_file(pic, "gem1.png")
push = pb.push_file(**file_data)
示例6: MainWindow
# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import upload_file [as 别名]
#.........这里部分代码省略.........
print "systray"
self.disconnect_systray()
print "listener quit"
self.listener.quit()
print "listener terminate"
self.listener.terminate()
print "disconnect_pushes"
self.disconnect_pushes_actions()
self.listener = None
@pyqtSlot()
def push_note(self):
if self.pusher and len(self.ui.devicesList.selectedItems()) == 1:
device = self.ui.devicesList.selectedItems()[0].data(Qt.UserRole).toPyObject()
device.push_note(str(self.ui.noteTitleEdt.text()), str(self.ui.noteTextEdt.toPlainText()))
else:
QMessageBox.warning(self, "Cannot push", "There is no target device selected")
@pyqtSlot()
def push_link(self):
if self.pusher and len(self.ui.devicesList.selectedItems()) == 1:
device = self.ui.devicesList.selectedItems()[0].data(Qt.UserRole).toPyObject()
device.push_link(str(self.ui.linkTitleEdt.text()), str(self.ui.linkUrlEdt.text()))
else:
QMessageBox.warning(self, "Cannot push", "There is no target device selected")
@pyqtSlot()
def push_list(self):
if self.pusher and len(self.ui.devicesList.selectedItems()) == 1:
device = self.ui.devicesList.selectedItems()[0].data(Qt.UserRole).toPyObject()
widget_items = [self.ui.itemsList.item(n) for n in range(0, self.ui.itemsList.count())]
items = map(lambda x: str(x.text()), widget_items)
device.push_list(str(self.ui.listTitleEdt.text()), items)
else:
QMessageBox.warning(self, "Cannot push", "There is no target device selected")
@pyqtSlot()
def push_file(self):
if self.pusher and len(self.ui.devicesList.selectedItems()) == 1:
device = self.ui.devicesList.selectedItems()[0].data(Qt.UserRole).toPyObject()
fname = str(self.ui.filePathEdt.text())
with open(fname, "rb") as f_to_send:
success, file_data = self.pusher.upload_file(f_to_send, os.path.basename(fname))
if success:
device.push_file(**file_data)
else:
QMessageBox.warning(self, "Cannot push", "There is no target device selected")
@pyqtSlot()
def push_address(self):
if self.pusher and len(self.ui.devicesList.selectedItems()) == 1:
device = self.ui.devicesList.selectedItems()[0].data(Qt.UserRole).toPyObject()
device.push_address(str(self.ui.addressTitleEdt.text()), str(self.ui.addressTxt.toPlainText()))
else:
QMessageBox.warning(self, "Cannot push", "There is no target device selected")
def connect_pushes_actions(self):
self.ui.sendNoteBtn.clicked.connect(self.push_note)
self.ui.sendLinkBtn.clicked.connect(self.push_link)
self.ui.sendFileBtn.clicked.connect(self.push_file)
self.ui.sendListBtn.clicked.connect(self.push_list)
self.ui.sendAddressBtn.clicked.connect(self.push_address)
def disconnect_pushes_actions(self):
self.ui.sendNoteBtn.clicked.disconnect(self.push_note)
self.ui.sendLinkBtn.clicked.disconnect(self.push_link)
self.ui.sendFileBtn.clicked.disconnect(self.push_file)
self.ui.sendListBtn.clicked.disconnect(self.push_list)
self.ui.sendAddressBtn.clicked.disconnect(self.push_address)
def connect_systray(self, ):
if self.tray is not None:
self.connected.connect(self.tray.connected)
self.listener.on_link.connect(self.tray.on_link)
self.listener.on_note.connect(self.tray.on_note)
self.connected.emit(self._connected)
def disconnect_systray(self):
if self.tray is not None:
self.listener.on_link.disconnect(self.tray.on_link)
self.listener.on_note.disconnect(self.tray.on_note)
@pyqtSlot()
def reconnect(self):
if self.listener is not None:
self.disconnect_pushbullet()
self.connect_pushbullet()
@pyqtSlot()
def exit(self):
self._exit = True
self.close()
def closeEvent(self, event):
if not self._exit:
self.hide()
event.ignore()
else:
QMainWindow.closeEvent(self, event)