Skip to content

Instantly share code, notes, and snippets.

@jblb
Forked from matael/tweet_reader.py
Created February 13, 2013 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jblb/4948741 to your computer and use it in GitHub Desktop.
Save jblb/4948741 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from twitter import Twitter
import time
# CONFIG
# hashtag a chercher
HASHTAG = "#jellylemans"
# attente entre deux récup (en MINUTES)
INTERVALE = 5
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']:
# TODO
# envoi à l'afficheur a mettre ici
print("@{0}: {1}".format(
r['from_user'],
r['text'].encode('utf8')
))
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