예제 #1
0
파일: twitter.py 프로젝트: freizeit/ep11
def main():
    connection = kombu.BrokerConnection(**config.get_rabbitmq_config())
    channel = connection.channel()
    twitter_exchange = kombu.Exchange("twitter", type="topic")
    producer = kombu.Producer(channel, twitter_exchange)
    control_queue = connection.SimpleBuffer("twitter_pump")
    try:
        twitter = twython.Twython(**config.get_twitter_config())
        handle_tweets(twitter, producer, control_queue)
    finally:
        channel.close()
        connection.close()
예제 #2
0
파일: twistory.py 프로젝트: freizeit/brain2
import pymongo
import sys

from twisted.internet import task
from twisted.internet import reactor
from twisted.python import log

import twython

from utils import config, urls


log.startLogging(sys.stdout)


api = twython.Twython(**config.get_twitter_config())


def get_since_id(coll, user_name):
    since_id = coll.find_one({"user_name": user_name})
    return since_id if since_id else dict(user_name=user_name, id=0)


def pull_and_save_tweets(api):
    cfg = config.get("db")
    uri = "%s:%s@%s/%s" % (
        cfg.get("user"), cfg.get("password"), cfg.get("host"), cfg.get("db"))
    conn = pymongo.Connection(uri)
    db = conn[cfg.get("db")]
    messages = db[cfg.get("messages_coll")]
    messages.ensure_index("id")