Пример #1
0
def main():
    if len(cfg.http_proxy_host) == 0 or len(cfg.http_proxy_port) == 0:
        client = oauthapi.tpOAuth()
    else:
        client = oauthapi.tpOAuth(http_proxy={
            'host': cfg.http_proxy_host,
            'port': cfg.http_proxy_port
        })

    maxid = getmaxid()

    try:
        response = client.fetch_user_timeline(cfg.screen_name, 0, maxid + 1, 1,
                                              cfg.sync_rt_message)
        tweets = simplejson.loads(response)
    except:
        writelog('Twitter API limited')
        print 'API limited'
        return

    if maxid == 0:
        writelog('now tweets max id is %s' % tweets[0]['id'])
        savemaxid(tweets[0]['id'])
        return

    sina = Sina()
    sina.setToken(cfg.sina_access_token_key, cfg.sina_access_token_secret)
    #sina.update('hello sina microblog, abcd, F**K the developers of the API')
    for tweet in tweets:
        if maxid <= long(tweet['id']):
            maxid = long(tweet['id'])
        if not cfg.sync_reply_message and tweet['in_reply_to_user_id']:
            continue
        try:
            retweet = tweet['retweeted_status']
            text = retweet['text']
            mentions = retweet['entities']['user_mentions']
            for mention in mentions:
                p = re.compile('@' + mention['screen_name'])
                text = p.sub(mention['screen_name'], text)
            text = u"转:" + text
        except Exception, e:
            text = tweet['text']
            mentions = tweet['entities']['user_mentions']
            for mention in mentions:
                p = re.compile('@' + mention['screen_name'])
                text = p.sub(mention['screen_name'], text)
        try:
            msg = "update---: " + text
            writelog(msg.encode('utf8'))
            sina.update(text)
        except WeibopError as e:
            writelog('sina error, maybe api limited')

        writelog('now tweets max id is %ld' % maxid)
        savemaxid(maxid)

        time.sleep(120)
Пример #2
0
#! /usr/bin/env python
#coding=utf8
from oauthUpdate import Sina

sina = Sina()
sina.auth()