Skip to content

Instantly share code, notes, and snippets.

@matael
Last active December 13, 2015 17:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matael/4948168 to your computer and use it in GitHub Desktop.
Save matael/4948168 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from twitter import Twitter
import re
import time
import os
# CONFIG
# hashtag a chercher
HASHTAG = "#jellylemans"
# attente entre deux récup (en MINUTES)
INTERVALE = 5
reg_e = re.compile('é|è|ê|ë')
reg_i = re.compile('î|ï')
reg_a = re.compile('â|à')
reg_u = re.compile('ù|û')
def get_tweets(hashtag, last_id=None):
""" Get last tweets """
# init twitter connection
twlk = Twitter(domain="search.twitter.com")
# get tweets since last id
if last_id:
res = twlk.search(q=hashtag, since_id=last_id)
else:
res = twlk.search(q=hashtag)
return res
def send_tweets(tweets):
""" send tweets to display """
# loop over tweets
for r in tweets['results']:
tweet = reg_e.sub('e', r['text'])
tweet = reg_i.sub('i', tweet)
tweet = reg_u.sub('u', tweet)
tweet = reg_a.sub('a', tweet)
tweet = tweet.encode('utf8')
print("@{0}: {1}".format(
r['from_user'],
tweet
))
os.system('python ./Py_affiche.py -p /dev/ttyUSB0 "@{0} {1}"'.format(r['from_user'], tweet))
time.sleep(len(tweet)/4+4)
def main():
hashtag = HASHTAG
last_id = None
while 1:
# récup des tweets
tweets = get_tweets(hashtag,last_id)
# envoi
send_tweets(tweets)
# récup de l'ID max
last_id = tweets['max_id_str']
# attente
time.sleep(INTERVALE*60)
if __name__=="__main__": main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment