Пример #1
0
def handleCurrentChange():
    objects = request.args.get('objects')
    offset = int(request.args.get('offset'))
    if (objects == 'jfmt'):
        cursor.execute("SELECT * FROM jfmt order by `index` desc limit %s,5",
                       offset)
        res = cursor.fetchall()
        for i in res:
            if isinstance(i['upload_date'], (datetime, date)):
                i['upload_date'] = i['upload_date'].strftime('%Y-%m-%d')
        return json.dumps(res)
    if (objects == 'today_history'):
        cursor.execute(
            "SELECT * FROM today_history order by `index` desc limit %s,5",
            offset)
        res = cursor.fetchall()
        for i in res:
            if isinstance(i['upload_date'], (datetime, date)):
                i['upload_date'] = i['upload_date'].strftime('%Y-%m-%d')
        return json.dumps(res)
    if (objects == 'trump_twitter'):
        cursor.execute(
            "SELECT * FROM trump_twitter order by `index` desc limit %s,5",
            offset)
        res = cursor.fetchall()
        for i in res:
            if isinstance(i['upload_date'], (datetime, date)):
                i['upload_date'] = i['upload_date'].strftime('%Y-%m-%d')
        return json.dumps(res)
Пример #2
0
def hotAudios():
    first_page_data = []
    lock.acquire()
    cursor.execute("SELECT * FROM jfmt order by `index` desc limit 4")
    lock.release()
    result1 = cursor.fetchall()
    first_page_data = first_page_data + result1
    lock.acquire()
    cursor.execute("SELECT * FROM today_history order by `index` desc limit 3")
    lock.release()
    result2 = cursor.fetchall()
    first_page_data = first_page_data + result2
    lock.acquire()
    cursor.execute("SELECT * FROM trump_twitter order by `index` desc limit 2")
    lock.release()
    result3 = cursor.fetchall()
    first_page_data = first_page_data + result3
    lock.acquire()
    cursor.execute("SELECT * FROM wenzhao order by `index` desc limit 4")
    lock.release()
    result4 = cursor.fetchall()
    first_page_data = first_page_data + result4
    for i in first_page_data:
        if isinstance(i['upload_date'], (datetime, date)):
            i['upload_date'] = i['upload_date'].strftime('%Y-%m-%d')
    return json.dumps(first_page_data)
Пример #3
0
def seeMessages():
    id = request.args.get('audio_id')
    lock.acquire()
    cursor.execute('Select * from comment where audio=%s',id)
    lock.release()
    result = cursor.fetchall()
    return json.dumps(result)
Пример #4
0
def get_all_art(username: str) -> List:
    images = []
    if username is None:
        username = ""

    cursor.execute("SELECT id, title, creator, image from arts")
    for art in cursor.fetchall():
        cursor.execute("SELECT COUNT(*) from comments where artID = ?",
                       (art[0], ))
        num_comments = cursor.fetchone()[0]
        cursor.execute("SELECT COUNT(*) FROM likes where artID = ?",
                       (art[0], ))
        likes = int(cursor.fetchone()[0])

        images.append({
            "image": art[3],
            "likes": likes,
            "creator": art[2],
            "title": art[1],
            "art_id": str(art[0]),
            "num_comments": num_comments,
            "hasLiked": did_user_like(username, art[0])
        })
    connection.commit()
    return images
Пример #5
0
def get_image(id: str, username: str) -> Dict:
    if username is None:
        username = ""

    cursor.execute("SELECT title, creator, image FROM arts WHERE id = ?",
                   (id, ))
    data = cursor.fetchone()
    if data is None:
        return None
    cursor.execute("SELECT COUNT(*) FROM likes where artID = ?", (int(id), ))
    likes = int(cursor.fetchone()[0])
    image = {
        "title": data[0],
        "creator": data[1],
        "image": data[2],
        "likes": likes,
        "comments": [],
        "hasLiked": did_user_like(username, id)
    }
    cursor.execute("SELECT username, content from comments WHERE artID = ?",
                   (id, ))
    for comment in cursor.fetchall():
        image["comments"].append({
            "username": comment[0],
            "content": comment[1]
        })
    connection.commit()
    return image
Пример #6
0
def handleCurrentChange():
    offset = int(request.args.get('offset'))
    cursor.execute("SELECT * FROM wenzhao order by `index` desc limit %s,10",
                   offset)
    result = cursor.fetchall()
    for i in result:
        if isinstance(i['upload_date'], (datetime, date)):
            i['upload_date'] = i['upload_date'].strftime('%Y-%m-%d')
    return json.dumps(result)
Пример #7
0
def dataAudio():
    lock.acquire()
    cursor.execute("SELECT * FROM wenzhao order by `index` desc limit 10;")
    result = cursor.fetchall()
    lock.release()
    for i in result:
        if isinstance(i['upload_date'], (datetime, date)):
            i['upload_date'] = i['upload_date'].strftime('%Y-%m-%d')
    return json.dumps(result)
Пример #8
0
def searchData():
    month = request.args.get("month")
    cols = request.args.get("column")
    lock.acquire()
    sql = "Select * from %s" %cols +" where date_format(upload_date,'%%Y-%%m')=%s"
    cursor.execute(sql,[month])
    res = cursor.fetchall()
    for item in res:
      if isinstance(item['upload_date'], (datetime, date)):
        item['upload_date'] = item['upload_date'].strftime('%Y-%m-%d')
    lock.release()
    return json.dumps(res)
Пример #9
0
def pullAudios():
    first_page_data = []
    lock.acquire()
    cursor.execute("Select * FROM jfmt order by `index` desc limit 5")
    lock.release()
    result1 = cursor.fetchall()
    first_page_data.append(result1)
    lock.acquire()
    cursor.execute("SELECT * FROM today_history order by `index` desc limit 5")
    lock.release()
    result2 = cursor.fetchall()
    first_page_data.append(result2)
    lock.acquire()
    cursor.execute(
        "SELECT * FROM trump_twitter order by `index` desc limit 5;")
    lock.release()
    result3 = cursor.fetchall()
    first_page_data.append(result3)
    for i in first_page_data:
        for item in i:
            if isinstance(item['upload_date'], (datetime, date)):
                item['upload_date'] = item['upload_date'].strftime('%Y-%m-%d')
    return json.dumps(first_page_data)
Пример #10
0
def sign_up():
    userName = request.args.get('userName')
    password = request.args.get('password')
    lock.acquire()
    cursor.execute("SELECT * FROM users where username = %s",userName)
    lock.release()
    result = cursor.fetchall()
    md5 = hashlib.md5()
    demo_md5 = password.encode(encoding='utf-8')
    md5.update(demo_md5)
    pass_md5 = md5.hexdigest()
    if(len(result) == 0 ):
        cursor.execute("Insert into users (username,password) values(%s,%s)",(userName,pass_md5))
        db.commit()
        sign_up = [{"sign_up": 200}]
    else:
        sign_up = [{"sign_up": 400}]
    return json.dumps(sign_up)
Пример #11
0
def sign_in():
    userName = request.form['userName']
    password = request.form['password']
    md5 = hashlib.md5()
    demo_md5 = password.encode(encoding='utf-8')
    md5.update(demo_md5)
    pass_md5 = md5.hexdigest()
    lock.acquire()
    cursor.execute("SELECT * FROM users where username = %s and password = %s",(userName,pass_md5))
    lock.release()
    result = cursor.fetchall()
    if(result):
        sign_in = {"sign_in":200}
        session['login'] = '******'
        session['userName'] = userName
        session['pass_md5'] = pass_md5
    else:
        sign_in = {"sign_in":400}
    return json.dumps(sign_in)