def say():
    s = request.environ.get('beaker.session')
    access_token = s.get('access_token', '')
    if not access_token:
        toggle_notice('还未登录, <a href="/auth"><img src="/static/login240.png" /></a> ')
        redirect('/')
    if not check_formhash():
        abort(403, 'how you get here?')

    o = lib.get_user_api(access_token)
    
    word = request.POST.get('word', '')
    word = " ".join(word.split())
    wordlen = len(lib.mb_code(word, 'utf-8').decode('utf-8'))
    toweiqun = request.POST.get('toweiqun', '')
    if wordlen == 0 or wordlen > 140:
	abort(403, 'invalid status')
		
    try:
        api = lib.get_api()
        api.update_status(word)
        toggle_notice('小纸条已经丢进树洞')
        if toweiqun == 'on':
            lib.appendto(
                lib.get_timed_path('toweiqun'),
                word + "\n",
            )
        return {
            'uid': s.get('uid', ''),
            'name': s.get('name',''),
            'notice': toggle_notice(),
            'formhash': set_formhash(),
        }
    except Exception, e:
        return "error: " + str(e)
Example #2
0
from time import sleep, time
import os

def get_n():
    path = lib.get_timed_path('toweiqun') + "-n"
    if os.path.exists(path):
        return int(lib.readfrom(path))
    else:
        lib.writeto(path, "0")
        return 0

def set_n(n):
    path = lib.get_timed_path('toweiqun') + "-n"
    lib.writeto(path, str(n))

o = lib.get_api()


sina = Sina(conf.username, conf.password)
prevtime = 0

while True:
    newtime = int(time())
    if newtime - prevtime >= 3600 * 3:
        try:
            sina.login()
            print newtime, sina.cookies
            prevtime = newtime
        except: pass
    
Example #3
0
def pub2qq(status):
    from lib import get_api
    o = get_api()
    o.tweet.add(status)
Example #4
0
def pub2sina(status):
    from lib import get_api
    o = get_api()
    o.update_status(status)
def get_sina_status():
    from lib import get_api
    o = get_api()
    print dir(o)
    return o.user_timeline(count=10, page=1)