Hardware Reference
In-Depth Information
def main():
api = twitter.Api(consumer_key='xxxxxxcxK9I3g',
consumer_secret='xxxxxfLBmh0gqHohRdkEH891B2XCv00',
access_token_key='xxxxx25-
Dw8foMCfNec2Gff72qxxxxxwMwomXYo',
access_token_secret='xxxxxxjIuFb88dI')
previous_status = twitter.Status()
chick = chicken.Chicken(pfio,0)
# has user passed command line argument?
if len(sys.argv) > 1:
search_term = sys.argv[1]
else:
search_term = DEFAULT_SEARCH_TERM
print “Listening to tweets containing the word '%s'.” % ↵
search_term
while True:
# grab the first tweet containing the
# search_term
current_status = api.GetSearch(term=search_term, ↵
count=1)[0]
# if the status is different
# then pass it to the chick.say function
if current_status.id != previous_status.id:
chick.start_wobble()
chick.say(current_status.text)
chick.stop_wobble()
previous_status = current_status
# wait for a short while before checking again
time.sleep(TIME_DELAY)
if __name__ == “__main__”:
main()
Try it! Run the code and you should have an animated, talking toy that responds to Twitter.
Don't forget you can make the file executable by running
chmod a+x twitter_tag_listen.py
Search WWH ::




Custom Search