Python Twython关键字和LED

Python Twython关键字和LED,python,raspberry-pi3,twython,Python,Raspberry Pi3,Twython,我正在创建一个项目,使用树莓圆周率和浆果剪辑。因此,我对它进行了编程(使用twython),代码使用用户输入的特定关键字搜索推特,当找到它时,它会显示推特和LED闪光灯。我想在我的浆果夹上扩展它,并使用所有6个LED和6个不同的关键字。我设法将其编程为搜索6个关键字,但到目前为止,我无法找到如何根据关键字制作每个led。例如,如果流找到第一个关键字,第一个LED将闪烁。如果找到第二个关键字,则第二个LED将闪烁,等等。我尝试在第一个If语句中使用If语句(If'text'在数据中:),通过添加I

我正在创建一个项目,使用树莓圆周率和浆果剪辑。因此,我对它进行了编程(使用twython),代码使用用户输入的特定关键字搜索推特,当找到它时,它会显示推特和LED闪光灯。我想在我的浆果夹上扩展它,并使用所有6个LED和6个不同的关键字。我设法将其编程为搜索6个关键字,但到目前为止,我无法找到如何根据关键字制作每个led。例如,如果流找到第一个关键字,第一个LED将闪烁。如果找到第二个关键字,则第二个LED将闪烁,等等。我尝试在第一个If语句中使用If语句(
If'text'在数据中:
),通过添加
If TERMS在'text':
中,但没有起作用。这是我目前的代码:

#!/usr/bin/python
import time
import RPi.GPIO as GPIO
from twython import TwythonStreamer

ledList=[4,17,22,10,9,11]

GPIO.setmode(GPIO.BCM)
GPIO.setup(ledList,GPIO.OUT)

TERMS=(raw_input("Please type the first keyword"));
TERMS2=(raw_input("Please type the second keyword"));
TERMS3=(raw_input("Please type the third keyword"));
TERMS4=(raw_input("Please type the fourth keyword"));
TERMS5=(raw_input("Please type the fifth keyword")); 
TERMS6=(raw_input("Please type the sixth keyword"));

termsList=[TERMS,TERMS1,TERMS2,TERMS3,TERMS4,TERMS5,TERMS6]   

APP_KEY='xxxxxxxxxxxx'
APP_SECRET='xxxxxxxxx'
OAUTH_TOKEN='xxxxxxxxx'
OAUTH_TOKEN_SECRET='xxxxxxxxx'

class streamer(TwythonStreamer):
     def success(self,data):
           if 'text' in data:
               tweet_data=data['text'].encode('utf-8')
               print (tweet_data)
               GPIO.output(4,True)
               time.sleep(1)
               GPIO.output(4,False)

try:
     stream = streamer(APP_KEY,APP_SECRET,OAUTH_TOKEN,OAUTH_TOKEN_SECRET)
     stream.statuses.filter(track=termsList)

except KeyboardInterrupt:
        print ('ending')
        GPIO.cleanup()

就像你说的,你需要检查tweet文本中的术语。 (我对覆盆子圆周率知之甚少,但我想当在推特中找到第i个术语时,下面将点亮第i个)

class streamer(TwythonStreamer):
     def success(self,data):
           if 'text' in data:
               tweet_data=data['text'].encode('utf-8')
               for i, term in enumerate(termList):
               if term in tweet_data:
                   GPIO.output(i,True)
                   time.sleep(1)
                   GPIO.output(i,False)