def follow_user(): cur = mysql.connection.cursor() try: json_obj = json.loads(json.dumps(request.json)) follower = json_obj["follower"] followee = json_obj["followee"] except Exception: return json.dumps(responses_codes[2]) if not follower or not followee: return json.dumps(responses_codes[1]) cur.execute('''SELECT id FROM User WHERE email='%s' ''' % follower) if not cur.fetchone(): return json.dumps(responses_codes[1]) cur.execute('''SELECT id FROM User WHERE email='%s' ''' % followee) if not cur.fetchone(): return json.dumps(responses_codes[1]) cur.execute('''SELECT id FROM Follow WHERE follower = '%s' AND followee = '%s' ''' % (follower, followee,)) if cur.fetchone(): return json.dumps(responses_codes[5]) try: cur.execute('''INSERT INTO Follow (follower, followee) VALUES ('%s','%s')''' % (follower, followee,)) except Exception: return json.dumps(responses_codes[5]) return json.dumps({ "code": 0, "response": get_user_entity(follower) }, sort_keys=True)
def user_updateProfile(): cur = mysql.connection.cursor() try: json_obj = json.loads(json.dumps(request.json)) about = json_obj["about"] email = json_obj["user"] name = json_obj["name"] except Exception: return json.dumps(responses_codes[2]) if not about or not email or not name: return json.dumps(responses_codes[2]) try: cur.execute( '''UPDATE User SET about='%s',name='%s' WHERE email = '%s' ''' % ( about, name, email, )) except Exception: return json.dumps(responses_codes[1]) return json.dumps({ "code": 0, "response": get_user_entity(email) }, sort_keys=True)
def unfollow_user(): cur = mysql.connection.cursor() try: json_obj = json.loads(json.dumps(request.json)) follower = json_obj["follower"] followee = json_obj["followee"] except Exception: return json.dumps(responses_codes[2]) if not follower or not followee: return json.dumps(responses_codes[2]) try: cur.execute( '''DELETE FROM Follow WHERE follower = '%s' AND followee = '%s' ''' % ( follower, followee, )) except Exception: return json.dumps(responses_codes[1]) return json.dumps({ "code": 0, "response": get_user_entity(follower) }, sort_keys=True)
def follow_user(): cur = mysql.connection.cursor() try: json_obj = json.loads(json.dumps(request.json)) follower = json_obj["follower"] followee = json_obj["followee"] except Exception: return json.dumps(responses_codes[2]) if not follower or not followee: return json.dumps(responses_codes[1]) # exist both users? cur.execute('''SELECT id FROM User WHERE email='%s' ''' % follower) if not cur.fetchone(): return json.dumps(responses_codes[1]) cur.execute('''SELECT id FROM User WHERE email='%s' ''' % followee) if not cur.fetchone(): return json.dumps(responses_codes[1]) # exist follow? cur.execute('''SELECT id FROM Follow WHERE follower = '%s' AND followee = '%s' ''' % (follower, followee,)) if cur.fetchone(): return json.dumps(responses_codes[5]) try: cur.execute('''INSERT INTO Follow (follower, followee) VALUES ('%s','%s')''' % (follower, followee,)) except Exception: return json.dumps(responses_codes[5]) return json.dumps({ "code": 0, "response": get_user_entity(follower) }, sort_keys=True)
def detail_forum(): user_email = request.args.get("user") if not user_email: return json.dumps(responses_codes[2]) response = get_user_entity(user_email) if response in responses_codes: return json.dumps(response) result = {"code": 0, "response": response} return json.dumps(result)
def detail_forum(): user_email = request.args.get("user") if not user_email: return json.dumps(responses_codes[2]) response = get_user_entity(user_email) if response in responses_codes: return json.dumps(response) result = { "code": 0, "response": response } return json.dumps(result)
def user_updateProfile(): cur = mysql.connection.cursor() try: json_obj = json.loads(json.dumps(request.json)) about = json_obj["about"] email = json_obj["user"] name = json_obj["name"] except Exception: return json.dumps(responses_codes[2]) if not about or not email or not name: return json.dumps(responses_codes[2]) try: cur.execute('''UPDATE User SET about='%s',name='%s' WHERE email = '%s' ''' % (about, name, email,)) except Exception: return json.dumps(responses_codes[1]) return json.dumps({ "code": 0, "response": get_user_entity(email) }, sort_keys=True)
def unfollow_user(): cur = mysql.connection.cursor() try: json_obj = json.loads(json.dumps(request.json)) follower = json_obj["follower"] followee = json_obj["followee"] except Exception: return json.dumps(responses_codes[2]) if not follower or not followee: return json.dumps(responses_codes[2]) try: cur.execute('''DELETE FROM Follow WHERE follower = '%s' AND followee = '%s' ''' % (follower, followee,)) except Exception: return json.dumps(responses_codes[1]) return json.dumps({ "code": 0, "response": get_user_entity(follower) }, sort_keys=True)