示例#1
0
def main():
    """docstring for main"""
    #set system default encoding to utf-8 to avoid encoding problems
    reload(sys)
    sys.setdefaultencoding( "utf-8" )
    
    #load channel configurations
    channels = json.load(open('conf/channel.json'))
    
    

    #find one account
    rr = SNSPocket()
    for c in channels:
        rr.add_channel(c)

    if rr is None:
        print "cannot find one renren platform in channel.json"
        return 
    else:
        rr.load_config()
        rr.auth()
        

    #load record to avoid repeated reply
    try:
        sIDs = json.load(open('statusID.json'))
    except IOError, e:
        if e.errno == 2: #no such file
            sIDs = {}
        else:
            raise e
示例#2
0
def _do_get_pocket(_sp_cache=[]):
    if _sp_cache:
        return _sp_cache[0]

    sp = SNSPocket()
    sp.load_config(CONF_ABS_PATH)
    sp.auth()
    _sp_cache.append(sp)
    return sp
示例#3
0
    def __init__(self):
        super(WeiboAutomator, self).__init__()
        self.sp = SNSPocket()
        self.sp.load_config()
        self.sp.auth()
        # assign 'channel_name' as automator
        self.weibo = self.sp['automator']

        self.rlq = RateLimitQueue()
        map(lambda t: self.rlq.add_bucket(t[0], t[1]), self.SINA_BUCKETS)
示例#4
0
# -*- coding: utf-8 -*-

from snsapi.snspocket import SNSPocket
from datetime import datetime
import time

TEXTS = ['凌晨好', '清晨好', '早上好', '下午好', '傍晚好', '晚上好']
#URL = 'https://github.com/hupili/snsapi/tree/master/app/clock'
URL = 'http://t.cn/zj1VSdV'
AD = '10行写个跨平台的钟:%s' % URL

sp = SNSPocket()  # SNSPocket 是一个承载各种SNS的容器
sp.load_config()  # 如名
sp.auth()  # 批量授权(如果已授权,读取授权信息)

while True:
    h, m = datetime.now().hour, datetime.now().minute  # 获取当前小时和分钟
    if m == 0:  # 每小时0分钟的时候发状态
        t = '%s -- 0x%X点钟, %s。( %s )' % ('烫' * h, h, TEXTS[h / 4], AD
                                         )  # 构造钟的报时文字
        print t
        sp.update(t)  # 发一条新状态
    time.sleep(60)  # 睡一分钟
示例#5
0
'''
Read timeline from all configured channels and reply one

docstring placeholder
'''

from snsapi.snspocket import SNSPocket
from snsapi.utils import console_input, console_output

if __name__ == "__main__":
    '''
    QQ weibo may fail sometimes, even with same input. May be the invoking frequency limit.
    Sina weibo is better, and more stable.
    '''

    sp = SNSPocket()
    sp.load_config()

    sp.auth()

    status_list = sp.home_timeline()

    print "==== read messages from all channels ===="

    no = 0
    for s in status_list:
        print "--No. %d --" % no
        s.show()
        no = no + 1

    print "==== try to reply one ===="