当前位置: 首页>>代码示例>>Python>>正文


Python PushBullet.new_contact方法代码示例

本文整理汇总了Python中pushbullet.PushBullet.new_contact方法的典型用法代码示例。如果您正苦于以下问题:Python PushBullet.new_contact方法的具体用法?Python PushBullet.new_contact怎么用?Python PushBullet.new_contact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pushbullet.PushBullet的用法示例。


在下文中一共展示了PushBullet.new_contact方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: lattefy

# 需要导入模块: from pushbullet import PushBullet [as 别名]
# 或者: from pushbullet.PushBullet import new_contact [as 别名]
class lattefy():
    def __init__(self):
        #Pushbullet API data
        self.token = "BXRMMQMOGoLoQY4LWLsOOzf8ep3vlD5F"
        self.pb = PushBullet(self.token)
        self.pb.contacts
    
        #Coffee orders array
        self.orders = deque([])
        
        #Setting up SPI connection
        self.SPI_bus = smbus.SMBus(1)
        self.SPI_address = 0x04
        
        #Threading Pushbullet checks
        self.hilo=threading.Thread(target=self.pbCycle)
        self.hilo.start()
        
        #Threading buttons checks
        self.hilo2=threading.Thread(target=self.btnCycle)
        self.hilo2.start()
        
        while True:
            if True:
                if len(self.orders) > 0:
                    try:
                        self.SPI_bus.write_byte(self.SPI_address, self.orders[0]) #Send order number to Arduino
                    except:
                        pass
                    #self.makeOrder(self.orders[0])
                    self.orders.popleft()
                    #time.sleep(5)
                    #self.SPI_bus.write_byte(self.SPI_address, 3) #Ask Arduino to buzz
                    time.sleep(1)
                #else:
                    #self.SPI_bus.write_byte(self.SPI_address, 0) #Send blank
                    #time.sleep(1.5)
            else:
                print("No hay tazas libres")

    def get_sender(self,sender_iden,sender_name,sender_email):
        for contact in self.pb.contacts:
            if contact.email == sender_email:
                return contact
                break
        else:
            success, contact = self.pb.new_contact(sender_name,sender_email)
            return contact
    
    def get_body(self,push):
        try:
            body = push["body"]
            return body
        except:
            return ""
    
    def get_order(self,order):
        if order == "caféconleche":
            return 1
        elif order == "cafésolo":
            return 2
        else:
            return 0
    
    def buzz(self):        
        p = GPIO.PWM(buzzer, 3000)
        p.start(0)
        p.ChangeFrequency(900) #900Hz
        p.ChangeDutyCycle(70)
        time.sleep(0.1)
        p.stop()
        time.sleep(0.1)
        p.start(0)
        p.ChangeFrequency(900)
        p.ChangeDutyCycle(70)
        time.sleep(0.1)
        p.stop()
 
    def pbCycle(self):
        while True:
            success, self.pushes = self.pb.get_pushes()
            #print(self.pushes)
            for push in self.pushes:
                if push["dismissed"] == False:
                    re_body = self.get_body(push)
                    body = re_body.lower()
                    body = body.split(" ")
                    body = "".join(body)
                    sender_iden = push["sender_iden"]
                    sender_name = push["sender_name"]
                    sender_email = push["sender_email"]
                    order_result = self.get_order(body)
                    if order_result > 0:
                        if order_result == 1:
                            print("Preparando café con leche")
                        elif order_result == 2:
                            print("Preparando café solo")
                        self.get_sender(sender_iden,sender_name,sender_email).push_note("¡Orden terminada!","Ya puedes recoger tu {0}".format(re_body))
                        time.sleep(2)
                        self.orders.append(order_result)
#.........这里部分代码省略.........
开发者ID:Polectron,项目名称:lattefy-coffee-maker,代码行数:103,代码来源:pushes_checker.py


注:本文中的pushbullet.PushBullet.new_contact方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。