from sachintweets.models import connect, MongoException ####################################### Log book setup ######################### log_handler = FileHandler('fetch_user_details.log') log_handler.push_application() ###################################### Constants ############################### LOCK_FILE = 'recv.lock' ###################################### Mongodb connection ###################### try: db = connect() if db: tweet = db.tweet except Exception as e: log_handler.write(e.message) def fetch_user_details(): tweets = tweet.find({}) for t in tweets: if not 'screen_name' in t: r = requests.get("http://api.twitter.com/1/statuses/show/%d.json"\ %(t['tid'])) d = json.loads(r.content) if 'user' in d: tweet.update({'tid': t['tid']},{'$set': { 'screen_name': d['user']['screen_name'],\ 'profile_image_url': d['user']['profile_image_url']}}) print "%s ===updated to db=== %d", time.ctime(), t['tid']
from os import remove, getpid ####################################### Log book setup ######################### log_handler = FileHandler('recv.log') log_handler.push_application() ###################################### Constants ############################### LOCK_FILE = 'recv.lock' ###################################### Mongodb connection ###################### try: db = connect() if db: tweet = db.tweet except Exception as e: log_handler.write(e.message) #################################### ZERO MQ PULLER ############################ context = zmq.Context() socket = context.socket(zmq.SUB) socket.connect("tcp://*:6789") socket.setsockopt(zmq.SUBSCRIBE, "") def store_live_tweets(): while True: try: d = json.loads(socket.recv()) if tweet: tweet.insert({'text': d['text'],\ 'location': d['user']['location'], \