Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def set_n(n):
    path = lib.get_timed_path('toweiqun') + "-n"
    lib.writeto(path, str(n))
Ejemplo n.º 4
0
    newtime = int(time())
    if newtime - prevtime >= 3600 * 3:
        try:
            sina.login()
            print newtime, sina.cookies
            prevtime = newtime
        except: pass
    

    for uid, msg in sina.direct_messages():
        if lib.statuses_update(msg):
            print msg
            sina.del_direct_message(uid)
        sleep(1.0)
    
    path = lib.get_timed_path('toweiqun')
    if not os.path.exists(path): continue
    n = get_n()
    i = 1
    for line in file(path):
        if i > n:
            print 'toweiqun', i, line
            sina.update_q(conf.weiqun_id, line.strip())
            set_n(i)
            sleep(1.0)
        i += 1
        
    
    sleep(5)