每隔几秒检查一次电子邮件

时间:2017-05-24 20:41:56

标签: email

每次收到特定的电子邮件时,我的代码都会亮起来。我正在使用扭曲并且希望它每20秒运行一次这个代码,但是现在代码只是在运行时打开灯并保持打开(灯通常只运行10秒然后关闭)任何人都知道为什么扭曲是这样做?或者如何实现这一点。

import gmail
import unicornhat as unicorn
from light import light
import time
from twisted.internet import task
from twisted.internet import reactor

timeout = 20.0 # Sixty seconds

def doWork():

      g = gmail.login('email', 'password')
      unread = g.inbox().mail(subject="[Ardent Ink] Order")
      print unread[0].body
      total_messages = 0
      # none

      for message in unread:
            total_messages += 1

      if total_messages > 0:
            light()

            pass

l = task.LoopingCall(doWork)
l.start(timeout) # call every sixty seconds

reactor.run()

这是模块light()

的代码
import time
import unicornhat as unicorn

def light():
    unicorn.set_layout(unicorn.AUTO)
    unicorn.rotation(0)
    unicorn.brightness(1.0)
    width,height= unicorn.get_shape()

    for y in range(height):
        for x in range(width):
            unicorn.set_pixel(x,y,255,255,255)
            unicorn.show()
            time.sleep(0.01)
    time.sleep(10)

0 个答案:

没有答案