def crawl_one(tag): sp = SNSPocket() sp.load_config(fn_channel=tag+'/channel.json') status_list = mongo_client[tag].status_list sl = sp.home_timeline() for s in sl: try: r = s.raw #print r clear_urls(r) if 'retweeted_status' in r: clear_urls(r['retweeted_status']) r['_id'] = r['id'] r['time'] = s.parsed['time'] ret = status_list.insert(r) print ret except Exception as e: print str(e)
# -*- coding: utf-8 -*- ''' Read timeline from all configured channels docstring placeholder ''' from snsapi.snspocket import SNSPocket from snsapi.utils import console_input,console_output if __name__ == "__main__": sp = SNSPocket() sp.load_config() sp.auth() sl = sp.home_timeline() print sl
if isinstance(t, str): return sp.update(console_input(t), *al, **ad) elif isinstance(t, snstype.Message): return sp.update(t, *al, **ad) else: logger.warning("unknown type: %s", type(t)) lc = load_config = lambda *al, **ad : sp.load_config(*al, **ad) sc = save_config = lambda *al, **ad : sp.save_config(*al, **ad) lsc = list_channel = lambda *al, **ad : sp.list_channel(*al, **ad) lsp = list_platform = lambda *al, **ad : sp.list_platform(*al, **ad) newc = new_channel = lambda *al, **ad : sp.new_channel(*al, **ad) addc = add_channel = lambda *al, **ad : sp.add_channel(*al, **ad) clc = clear_channel = lambda *al, **ad : sp.clear_channel(*al, **ad) auth = lambda *al, **ad : sp.auth(*al, **ad) ht = home_timeline = lambda *al, **ad : sp.home_timeline(*al, **ad) up = update = lambda t, *al, **ad : update_from_console(t, *al, **ad) re = reply = lambda m, t, *al, **ad : sp.reply(m, console_input(t), *al, **ad) fwd = forward = lambda m, t, *al, **ad : sp.forward(m, console_input(t), *al, **ad) #==== documentation ==== helpdoc = \ """ snscli -- the interactive CLI to operate all SNS! Type "print helpdoc" again to see this document. To start your new journey, type "print tut" Here's the command list:
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 ====" print "Input the no:" no = int(console_input()) print "Input the text:" text = console_input()
from snsapi import snstype from snsapi.utils import console_output, console_input from snsapi.snspocket import SNSPocket from snsapi.snslog import SNSLog as logger sp = SNSPocket() #This is a much simpler and more clear test file. Hupili's tut file is too complex, and did not provide a `app_secret` and `app_key` #Don't think too much just run, it will be all clear. ^_^ #xuanqinanhai 2013-1-25 14:43 sp.list_channel() sp.clear_channel() nc = sp.new_channel() nc["platform"] = "SinaWeiboStatus" nc["app_secret"] = "96bcc1e00268d7e415c32212b3e197fb" #this is my own app secret nc["app_key"] = "3644324674" #and key nc["channel_name"] = "test_weibo" nc["auth_info"]["callback_url"] = "https://snsapi.ie.cuhk.edu.hk/aux/auth.php" #I changed the callback url in my app manage page. sp.add_channel(nc) sp.auth() sp.save_config() sp.list_channel() status = sp.home_timeline() for each in status: print each,
# -*- coding: utf-8 -*- 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.read_config() sp.auth() for cname in sp: print "listen first___________________________%s" % cname sl = sp.home_timeline(channel = cname) print sl print "update status__________________________%s" % cname print "Input text:" text = raw_input() ret = sp.update(text, channel = cname) print ret
return sp.update(console_input(t), *al, **ad) elif isinstance(t, snstype.Message): return sp.update(t, *al, **ad) else: logger.warning("unknown type: %s", type(t)) lc = load_config = lambda *al, **ad: sp.load_config(*al, **ad) sc = save_config = lambda *al, **ad: sp.save_config(*al, **ad) lsc = list_channel = lambda *al, **ad: sp.list_channel(*al, **ad) lsp = list_platform = lambda *al, **ad: sp.list_platform(*al, **ad) newc = new_channel = lambda *al, **ad: sp.new_channel(*al, **ad) addc = add_channel = lambda *al, **ad: sp.add_channel(*al, **ad) clc = clear_channel = lambda *al, **ad: sp.clear_channel(*al, **ad) auth = lambda *al, **ad: sp.auth(*al, **ad) ht = home_timeline = lambda *al, **ad: sp.home_timeline(*al, **ad) up = update = lambda t, *al, **ad: update_from_console(t, *al, **ad) re = reply = lambda m, t, *al, **ad: sp.reply(m, console_input(t), *al, **ad) fwd = forward = lambda m, t, *al, **ad: sp.forward(m, console_input(t), *al, ** ad) #==== documentation ==== helpdoc = \ """ snscli -- the interactive CLI to operate all SNS! Type "print helpdoc" again to see this document. To start your new journey, type "print tut"
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 ====" print "Input the no:" no = int(console_input()) print "Input the text:" text = console_input()
# -*- coding: utf-8 -*- from snsapi.snspocket import SNSPocket from snsapi.utils import console_input,console_output if __name__ == "__main__": sp = SNSPocket() sp.read_config() sp.auth() sl = sp.home_timeline() print sl
nc["app_key"] = "03af00adef1440899c62f8a76d05400f" nc["channel_name"] = "test_renren" nc["auth_info"]["callback_url"] = "http://snsapi.sinaapp.com/auth.php" sp.add_channel(nc) sp.auth() sp.save_config() sp.list_channel() status = sp.home_timeline() #print status nc2 = sp.new_channel(); nc2["platform"] = "RSS2RW" nc2["channel_name"] = "output" nc2["url"] = "output.atom" sp.add_channel(nc2) sp.auth() sp.save_config() sp.list_channel() sl = sp.home_timeline(5) print sl[0] print sp.home_timeline(channel = "output") sp.update(text = unicode(sl[0]), channel = "output") print sp.home_timeline(channel = "output")
''' Update status on all channels 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() for cname in sp: print "listen first___________________________%s" % cname sl = sp.home_timeline(channel = cname) print sl print "update status__________________________%s" % cname print "Input text:" text = raw_input() ret = sp.update(text, channel = cname) print ret