Exemple #1
0
def video_fun(fromUser):
    import os
    path = os.path.realpath(__file__)
    path = '/'.join(path.split('/')[:-2])

    all_path = os.walk('%s/tmp/user/%s/recent'%(path,fromUser))
    filename = []
    num = 0
    for (a,b,c) in all_path:
        for item in c:
            filename.append(item)
        break

    photonum = 79 * 25 / len(filename)
    os.system("mkdir %s/tmp/tempfile/%s"%(path,fromUser))
    for item in filename:
        for j in range(photonum):
            command = "cp %s/tmp/user/%s/recent/%s %s/tmp/tempfile/%s/a%04d.jpg"%(path, fromUser, item, path, fromUser, num)
            print command
            os.system(command)
            num += 1

    command = "ffmpeg -threads 2 -i %s/tmp/tempfile/%s/a%%04d.jpg -i %s/tmp/xiaopingguo.mp3 -strict -2 -vcodec libx264 -y -pix_fmt yuv420p %s/tmp/tempfile/%s/video.mp4"
    os.system(command%(path, fromUser, path, path, fromUser))
    from tool import wechat_upload, wechat_push
    thumb_id = wechat_upload('%s/static/img/getheadimg.jpg'%path, 'thumb')
    os.system("rm %s/tmp/tempfile/%s/a*"%(path, fromUser))
    media_id = wechat_upload('%s/tmp/tempfile/%s/video.mp4'%(path, fromUser), 'video')
    wechat_push(fromUser, 'video', media_id, thumb_id)
    os.system("mkdir %s/tmp/user/%s/image"%(path, fromUser))
    os.system("mv %s/tmp/user/%s/recent/* %s/tmp/user/%s/image/"%(path, fromUser, path, fromUser))
    os.system("mkdir %s/tmp/user/%s/video/"%(path,fromUser))
    import time
    now_time = time.time()
    now_time = time.localtime(now_time)
    now_time = time.strftime('%Y-%m-%d-%H:%M:%S',now_time)
    os.system("cp %s/tmp/tempfile/%s/video.mp4 %s/tmp/user/%s/video/%s.mp4"%(path, fromUser, path, fromUser, now_time))
    os.system("chmod 666 %s/tmp/user/%s/video/%s.mp4"%(path, fromUser, now_time))

    from redis import Redis
    con = Redis('localhost')
    routerid = con.get('WECHAT_BIND:'+fromUser)
    if routerid != None:
        f = open('%s/tmp/router/%s/ins.json'%(path,routerid),'r')
        text = f.read()
        if text == '':
            text = '{"ins":[]}'
        import json
        data = json.loads(text)
        f.close()
        f = open('%s/tmp/router/%s/ins.json'%(path,routerid),'w')
        data['ins'].append({'type':'video','url':'http://wull.me/download/%s/video/%s.mp4'%(fromUser,now_time)})
        f.write(json.dumps(data))
        f.close()
Exemple #2
0
def sanguosha_fun(fromUser, access_token):

    import os
    path = os.path.realpath(__file__)
    path = '/'.join(path.split('/')[:-2])

    f = open('%s/tmp/user/%s/sanguosha/config.txt'%(path,fromUser))
    filepath = '%s/tmp/user/%s/sanguosha/pic.jpg'%(path,fromUser)
    name = f.readline()[:-1]
    nickname = f.readline()[:-1]
    blood = int(f.readline())
    priority = f.readline()[:-1]
    temp = f.readline().split()
    temp2 = f.readline().split()
    if len(temp2) == 1:
        skillname = [temp[0]]
        skilldata = [temp[1]]
    else:
        skillname = [temp[0], temp2[0]]
        skilldata = [temp[1], temp2[1]]
    
    pic_path = sanguosha(fromUser,filepath,name,nickname,priority,skillname,skilldata,blood,path) 
    
    from tool import wechat_upload, wechat_push
    media_id = wechat_upload(pic_path, 'image')
    wechat_push(fromUser, 'image', media_id, '')
    from redis import Redis
    con = Redis('localhost')
    routerid = con.get('WECHAT_BIND:'+fromUser)
    if routerid != None:
        f = open('%s/tmp/router/%s/ins.json'%(path,routerid),'r')
        text = f.read()
        if text == '':
            text = '{"ins":[]}'
        import json
        data = json.loads(text)
        f.close()
        f = open('%s/tmp/router/%s/ins.json'%(path,routerid),'w')
        data['ins'].append({'type':'sanguosha','url':'https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s'%(access_token,media_id)})
        f.write(json.dumps(data))
        f.close()