def POST(self): input_data = web.input() username = input_data.get('username') vid = input_data.get('video_id') comment = input_data.get('comment') model = mmodel() return model.add_comment(username, vid, comment)
def POST(self): input_data = web.input() username = input_data.get('username') vid = input_data.get('video_id') like = input_data.get('like') model = mmodel() if (like == '0'): return model.like_video(username, vid) else: return model.dislike_video(username, vid)
def POST(self): model = mmodel() try: data = json.loads(web.data()) if (not model.check_user_exist_by_name(data['username'])): model.new_user(data['username'],data['head_image']) else: return "user already existed" except Exception as e: print traceback.print_exc() return e return " user_add %s " % db.db.get_user_base_info(data['username'])
def POST(self): try: model = mmodel() data = json.loads(web.data()) if (model.check_user_exist_by_name(data['friend_name'])): #TODO: model.add_friend(data['username'],data['friend_name']) else: return errorno.server_error(errorno.VIDEO_NOT_EXISTED[0], errorno.VIDEO_NOT_EXISTED[1]).dumps() except Exception as e: print traceback.print_exc() return e return " user_add %s " % model.get_user_base_info(data['username'])
def POST(self): try: model = mmodel() sha1 = hashlib.sha1() upfile = web.input(uploaded_file={}, thumb_nail={}) owner = upfile.get('video_owner') place = upfile.get('video_place') title = upfile.get('video_title') authority = upfile.get('video_is_public') print owner,place,title,authority urldir = '/video/' filedir = '/var/www' + urldir # print owner, sha1.hexdigest(), authority, title if not os.path.exists(filedir): os.mkdir(filedir) sha1.update(upfile.uploaded_file.value) filepath = ''.join([filedir, sha1.hexdigest(), '.mp4']) with open(filepath, 'wb') as saved: saved.write(upfile.uploaded_file.file.read()) filepath_thumb = ''.join([filedir, sha1.hexdigest(), '.png']) with open(filepath_thumb, 'wb') as thumb_file: thumb_file.write(upfile.thumb_nail.file.read()) video_url = ''.join([urldir, sha1.hexdigest(), '.mp4']) thumb_url = ''.join([urldir, sha1.hexdigest(), '.png']) ret = model.new_video(owner, filepath, sha1.hexdigest(), title, place,url=video_url, thumb_url=thumb_url) if (ret == -1): return errorno.server_error(errorno.VIDEO_ALREADY_EXISTED[0], errorno.VIDEO_ALREADY_EXISTED[1]) elif (ret == -2): return 'user not existed' except Exception as e: print traceback.print_exc()
def POST(self): imagehash = hashlib.sha1() input_data = web.input(head_image={}) model = mmodel() username = input_data.get('username') if (username != None) and (model.check_user_exist_by_name(username)): urldir = '/video/headimage/' filedir = '/var/www' # print owner, sha1.hexdigest(), authority, title if not os.path.exists(filedir+urldir): os.mkdir(filedir+urldir) imagehash.update(input_data.head_image.value) headimage_url = "%s%s_%s.png" % (urldir, username, imagehash.hexdigest()) filepath = "%s%s" % (filedir, headimage_url) with open(filepath, 'wb') as image_file: image_file.write(input_data.head_image.file.read()) return model.set_user_headimage(username, headimage_url) else : return 'no such user'
#! /usr/bin/env python # -*- coding: utf-8 -*- from db.db import mmodel if __name__ == "__main__": namelist = ['simsun', 'tyler', 'juncheng', 'haoxu', 'xbfu', 'peter', \ 'jamie', 'somebody', 'helloworld', 'smith', 'this_is_longest_name_all_over_the_world'] model = mmodel() for user in namelist: model.new_user(user, 'www.baidu.com') for user in namelist: for otheruser in namelist: if user != otheruser: model.add_follow(user,otheruser)
def GET(self, VID): model = mmodel() return model.get_video_base_info(VID)
def GET(self, username): model = mmodel() return model.get_user_base_info(username)
def POST(self): input_data = web.input() username = input_data.get('username') following_user = input_data.get('following_user') model = mmodel() return model.del_follow(username, following_user)
def GET(self, username): model = mmodel() return model.get_all_video(username)
def GET(self, vid): model = mmodel() return model.get_comment(vid)
def GET(self, vid): model = mmodel() return model.get_videoliked_user_list(vid)
def GET(self, username): model = mmodel() return model.get_user_like_video_list(username)
def GET(self, username): model = mmodel() return model.get_user_follower_list(username)
def POST(self, username): model = mmodel() return model.get_video_list_byusername(username)