예제 #1
0
def update_user_info(uid, screen_name, access_key, expires):
    try:
        db = MySQL()
        sql = "SELECT uid FROM users WHERE uid=%d" % uid
        ret = db.query(sql)
        if not ret:
            # 新增用户
            sql = "INSERT INTO users(uid,screen_name,access_key,expires) VALUES(%d,'%s','%s',%d)" % (
                uid,
                quote_sql(screen_name),
                str(access_key),
                expires,
            )
        else:
            # 更新用户
            sql = "UPDATE users SET screen_name='%s',access_key='%s',expires=%s WHERE uid=%d" % (
                quote_sql(screen_name),
                access_key,
                expires,
                uid,
            )
        db.update(sql)
        return True
    except Exception as e:
        return str(e)
예제 #2
0
def get_status_comments(status_id):
    try:
        db = MySQL()
        sql = "SELECT * FROM comments WHERE post_id=%d ORDER BY pub_time" % status_id
        ret = db.query(sql)
        return ret
    except Exception as e:
        return str(e)
예제 #3
0
def add_status(uid, status):
    try:
        db = MySQL()
        time = get_time(datetime.now())
        sql = "INSERT INTO status(status,uid,pub_time) VALUES('%s', %d, '%s')" % (quote_sql(status), int(uid), time)
        db.update(sql)
        return True
    except Exception as e:
        return str(e)
예제 #4
0
def add_comment(status_id, uid, comment):
    try:
        db = MySQL()
        time = get_time(datetime.now())
        sql = "INSERT INTO comments(post_id, uid, comment, pub_time) VALUES(%d, %d, '%s', '%s')" % (
            status_id,
            uid,
            quote_sql(comment),
            time,
        )
        db.update(sql)
        return True
    except Exception as e:
        return str(e)
예제 #5
0
def show_status(page=0, count=20):
    ret = []
    try:
        db = MySQL()
        sql = "SELECT * FROM status ORDER BY pub_time DESC LIMIT %d,%d" % (page * count, count)
        status = db.query(sql)
        for s in status:
            tmp = []
            tmp.extend(s)
            status_id = s[0]
            comments = get_status_comments(status_id)
            tmp.append(comments)
            ret.append(tmp)
        return ret
    except Exception as e:
        return str(e)
예제 #6
0
from flask import current_app as app
from DB import MySQL, Mongo
from Helpers.Authentication import hash

db = MySQL.connect()
cursor = db.cursor()

mdb = Mongo.connect("users")


def list():
    cursor.execute("select id, name, email, phone from users")
    result = __format__(cursor)
    if (result == None or len(result) < 1):
        return False, 204
    return result, False


def details(id):
    cursor.execute("select id, name, email, phone from users where id=" +
                   str(id))
    record = cursor.fetchone()
    if (record == None or len(record) < 1):
        return False, 204
    return record, False


def alreadyExists(email):
    cursor.execute("select id from users where email='" + email + "'")
    record = cursor.fetchone()
    if record:
예제 #7
0
def test_db():
    db = MySQL()
    sql = "SELECT * FROM users"
    ret = db.query(sql)
    return ret