import functions import json import os import sys import codecs import datetime # Note this line. It's the important one sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) print("Content-Type: text/plain; charset=UTF-8\n\n") try: uid=functions.get_user_id() sid = functions.get_cookie_value('LoggedIn') if not functions.check_logged(): json_res = {"ok": False, "data": []} print(json.dumps(json_res, indent=4, default=str, ensure_ascii=False).encode('utf-8').decode()) sys.exit() list_friends_query = "SELECT friend1 FROM friends WHERE status = 2 AND friend2 = '"+str(uid)+"' UNION SELECT friend2 FROM friends WHERE status = 2 AND friend1 = '"+str(uid)+"' " sql = "SELECT id, nickname, picture_number FROM users WHERE id IN ("+list_friends_query+") " mydb = functions.connect() mycursor = mydb.cursor() mycursor.execute(sql) all_details = mycursor.fetchall() friend = [] list_of_columens = [i[0] for i in mycursor.description]
#!/home/mefath5/.local/bin/python3 # print("Content-Type: text/plain\n\n") import os import sys import datetime import functions try: sid = functions.get_cookie_value("LoggedIn") if not sid: print("location: login.html") print("") sys.exit() db = functions.connect() sql = "SELECT `update_time`, `logged_out` FROM sessions WHERE sid = '" + sid + "'" time_before = (datetime.datetime.now() - datetime.timedelta(minutes=10)) session_cursor = db.cursor() session_cursor.execute(sql) session = session_cursor.fetchall() if len(session) < 1: time = time_before logged = 0 else: time, logged = session[0]