def addPhotoFavoriteToDB(userid, photoid): cursor=conn.cursor() from datetime import datetime try: if cursor is not None: sql = ("select * from favorite where Userid=%(uid)s and Photoid=%(pic)s") data={'uid':userid, 'pic':photoid} cursor.execute(sql,data) result=cursor.fetchall() if (len(result)>0): return true else: sql=("Insert into favorite " "Values(%(uid)s, %(pic)s, %(time)s)") data={'uid':userid, 'pic':photoid,'time':datetime.now().strftime('%Y-%m-%d %H:%M:%S')} cursor.execute(sql,data) result=cursor.rowcount conn.commit() cursor.close() if (result>0): return true else: return false; except: print (exc_info()) conn.rollback() cursor.close() return false
def addNewTag(tagText): newCursor=conn.cursor(); try: args = [tagText, 0] result_args = newCursor.callproc('uspAddTag', args) conn.commit() if result_args[1]>0: return result_args[1] except Error as e: conn.rollback() print (e) newCursor.close() return 0;
def addphoto(UID, PName, PDesc, PPath, FiName): newCursor = conn.cursor(); try: args = [UID, PName, PDesc, PPath, FiName, 0] result_args = newCursor.callproc('uspAddPhoto', args) conn.commit() newCursor.close() return (result_args[5]) except Error as e: conn.rollback() print(e) newCursor.close() return 0;
def UnlikePic(UID,PID): if UID==0 or PID==0: return False try: cursor = conn.cursor() args = [UID, PID, 0] result_args = cursor.callproc('uspCancelLike', args) conn.commit() cursor.close() return True # print(result_args[3]) except Error as e: conn.rollback() print(e) cursor.close() return False
def AddLike(UID, PID): if UID==0 or PID==0: return try: cursor = conn.cursor() args = [UID, PID, 0] result_args = cursor.callproc('uspAddLike', args) conn.commit() return True # print(result_args[3]) except Error as e: conn.rollback() print(e) return False finally: cursor.close()
def AddNewUser(Username, Pword, salt, email): from datetime import datetime try: cursor=conn.cursor() timeFormat='%Y-%m-%d %H:%M:%S' args = [Username,Pword, 0, salt, email, datetime.utcnow().strftime(timeFormat),0] result_args = cursor.callproc('uspAddUser', args) conn.commit() cursor.close() #print(result_args[6]) return result_args[6] except Error as e: conn.rollback() cursor.close() print(e) return 0
def AddUserRelation(u1id, u2id, Rtype): if u1id ==0 or u2id==0: return success=False try: cursor = conn.cursor() args = [u1id, u2id, Rtype, 0] result_args = cursor.callproc('uspAddUserRelation', args) conn.commit() # print(result_args[3]) success=True except Error as e: conn.rollback() print(e) finally: cursor.close() return success
def addcomment(CText, UID, PID): if UID==0 or PID==0 or CText is None: return if len(CText) <1: return cursor = conn.cursor() try: args = [CText, UID, PID, 0] result_args = cursor.callproc('uspAddComment', args) conn.commit() #print(result_args[4]) return result_args[3] except Error as e: conn.rollback() print(e) finally: cursor.close()
def addphotoTags(Pid,Tags): newCursor=conn.cursor(); try: for tag in Tags: tagid=tag['tagid'] if (tagid == 0): tagid=addNewTag(tag['text']) sql=("Insert into PhotoTags (PhotoID,TagID,LeftX,TopY)" "Values(%(pic)s, %(tag)s, %(x)s,%(y)s)") data={'pic':Pid, 'tag':tagid,'x':tag['left'],'y':tag['top']} newCursor.execute(sql,data) result=newCursor.rowcount conn.commit() newCursor.close() return true except Error as e: conn.rollback() print (e) newCursor.close() return false;
def addUserProfile(uid,Uname,Location,brithday,Gender,Occupation,Height,Weight): if uid==0: return None cursor=conn.cursor() try: sql=("insert into userdb.userDetails (UserId,username,location,brithday,Gender,Occupation,Height,Weight)" " Values(%(uid)s, %(uname)s, %(loca)s, %(brith)s, %(Gender)s, %(Occup)s, %(Height)s, %(Weight)s)") data={"uid":uid, "uname":Uname,"loca":Location,"brith":datetime.strptime(brithday,'%Y-%m-%d'),"Gender":Gender,"Occup":Occupation,"Height":Height,"Weight":Weight} cursor.execute(sql,data) row=cursor.rowcount conn.commit(); cursor.close() if row >0: return true; else: return false; except: print (exc_info()) conn.rollback() cursor.close() return false;
def saveUserKeys(userid,priv_pem,pub_pem): if userid<1: return False cursor=conn.cursor() try: sql=("Update userdb.userinfo " " SET Private_key=%(prv)s, Public_key=%(pub)s " " WHERE ID=%(uid)s") data={'uid':userid, 'prv':priv_pem,'pub':pub_pem} cursor.execute(sql,data) result=cursor.rowcount conn.commit() cursor.close() if (result>0): return true else: return false except: print (exc_info()) conn.rollback() cursor.close() return False;
def updateUserProfile(uid,Uname,Location,brithday,Gender,Occupation,Height,Weight): if uid==0: return None cursor=conn.cursor() try: sql=("Update userdetails " "set Username=%(uname)s,Location=%(loca)s,Brithday=%(brith)s,Gender=%(Gender)s,Occupation=%(Occup)s," "Height=%(Height)s,Weight=%(Weight)s " "Where UserID=%(uid)s") data={"uid":uid, "uname":Uname,"loca":Location,"brith":datetime.strptime(brithday,'%Y-%m-%d'),"Gender":Gender,"Occup":Occupation,"Height":Height,"Weight":Weight} cursor.execute(sql,data) row=cursor.rowcount conn.commit(); cursor.close() if row >0: return true; else: return false; except: print (exc_info()) conn.rollback() cursor.close() return false;
def updateUserToken(userid, token): if userid<0: return False else: cursor=conn.cursor() try: sql=("Update userdb.userinfo " " SET accessToken=%(token)s " " WHERE ID=%(uid)s") data={'uid':userid, 'token':token} cursor.execute(sql,data) result=cursor.rowcount conn.commit() cursor.close() if (result>0): return True else: return False except: print (exc_info()) conn.rollback() cursor.close() return False;