0

我编写了一个脚本,它使用 while True 定期抓取 Twitter 数据。

对于 except 元素,我启动了对大量数据的一次性抓取。

我可以触发它的唯一方法是使用 Ctrl+C。我想要做的是将“Ctrl+C”功能映射到我的 RaspberryPi Pibrella 上的按钮。

我环顾了这里,那里,到处,但没有快乐。我能找到的唯一模块不适用于 Raspberry Pi (Linux)。

def status_update():  
    while True:  
        try:  
            scrape_some_stuff()  
            time.sleep(1x60)  
        except:  
            scrape_lots_of_stuff()  
            time.sleep(1x60)  
4

1 回答 1

0

pibrella 有一个包 ( pip install pibrella),因此您可以轻松监控按钮状态,您可以使用它来引发异常

import pibrella

# add this line into your codes
pibrella.button.pressed(raise Exception)

他们的github repo有一些例子。

于 2019-05-26T11:55:32.427 回答