Ejemplo n.º 1
0
def getLrcByWord(word):
    GET_LIST_SQL = "SELECT song_id FROM res_word WHERE word=%s ORDER BY RAND() LIMIT 5"
    GET_NAME_SQL = "SELECT song_name FROM song WHERE song_id=%s"
    GET_SINGER_SQL = "SELECT singer_name FROM singer,singers_sing WHERE song_id=%s AND " \
                     "singer.singer_id=singers_sing.singer_id "
    GET_LRC_SQL = "SELECT lrc FROM res_lrc WHERE song_id=%s"
    db, cursor = DBUtil.connect()
    cursor.execute(GET_LIST_SQL, word)
    res_list = cursor.fetchall()

    data = list()

    for item in res_list:
        song_id = item[0]
        song_data = {'id': song_id}

        cursor.execute(GET_NAME_SQL, song_id)
        song_name = cursor.fetchone()[0]
        song_data['name'] = song_name

        cursor.execute(GET_SINGER_SQL, song_id)
        singer_name = cursor.fetchone()[0]
        song_data['singer'] = singer_name

        cursor.execute(GET_LRC_SQL, song_id)
        song_lrc = cursor.fetchone()[0]
        song_lrc = song_lrc.split()
        for lrc in song_lrc:
            if word in lrc:
                song_data['lrc'] = lrc
                break

        data.append(song_data)

    return data
Ejemplo n.º 2
0
def getWordsStat():
    SQL = "SELECT word, cnt_sum FROM words_rank ORDER BY cnt_sum DESC LIMIT 100"
    db, cursor = DBUtil.connect()
    cursor.execute(SQL)
    res = cursor.fetchall()
    data = list()
    for item in res:
        data.append({'word': str(item[0]), 'cnt': int(item[1])})
    return data
Ejemplo n.º 3
0
def getAllUserBirthday():
    SQL = "SELECT birthday div 1000 FROM user WHERE birthday>0"
    db, cursor = DBUtil.connect()
    cursor.execute(SQL)
    res = cursor.fetchall()
    data = list()
    for item in res:
        data.append(time.localtime(item[0]))
    return data
Ejemplo n.º 4
0
def getProvinceStat():
    SQL = "SELECT province_name, cnt FROM province_rank"
    db, cursor = DBUtil.connect()
    cursor.execute(SQL)
    res = cursor.fetchall()
    data = list()
    for item in res:
        data.append({'province': str(item[0]), 'cnt': int(item[1])})
    return data
Ejemplo n.º 5
0
def getAboutInfo():
    SQL = "SELECT * FROM %s.system" % config.DB_NAME
    db, cursor = DBUtil.connect()
    cursor.execute(SQL)
    res = cursor.fetchall()
    data = {}
    for item in res:
        data[item[0]] = item[1]
    return data
Ejemplo n.º 6
0
def getGenderStat():
    SQL = "SELECT gender, cnt FROM gender_rank"
    db, cursor = DBUtil.connect()
    cursor.execute(SQL)
    res = cursor.fetchall()
    data = list()
    gender = {1: '男', 2: '女', 0: '保密'}
    for item in res:
        data.append({'gender': gender[item[0]], 'cnt': int(item[1])})
    return data
Ejemplo n.º 7
0
def getPublishStat():
    SQL = "SELECT year,cnt FROM res_publish_stat ORDER BY year"
    db, cursor = DBUtil.connect()
    cursor.execute(SQL)
    res = cursor.fetchall()
    data = []
    for item in res:
        if int(item[0]) <= 1970:
            continue
        data.append({'year': item[0], 'cnt': item[1]})
    return data
Ejemplo n.º 8
0
def getSingerRank():
    SQL = "SELECT singer_id,singer_name,song_cnt,comment_cnt  FROM res_singer_rank ORDER BY comment_cnt DESC LIMIT 20"
    db, cursor = DBUtil.connect()
    cursor.execute(SQL)
    res = cursor.fetchall()
    data = list()
    for item in res:
        data.append({
            'singer_id': int(item[0]),
            'singer_name': item[1],
            'song_cnt': int(item[2]),
            'comment_cnt': int(item[3])
        })
    return data
Ejemplo n.º 9
0
import random

from util import DBUtil
from functools import cmp_to_key

db, cursor = DBUtil.connect()
GET_WORD_VALUE_SQL = "SELECT word,value from res_word_value"

cursor.execute(GET_WORD_VALUE_SQL)
res = cursor.fetchall()

values = {}
for item in res:
    values[item[0]] = int(item[1])


def cmpSortByValue(x, y):
    vx = values.get(x, 0)
    vy = values.get(y, 0)
    if vx == vy:
        return 0
    if vx > vy:
        return -1
    return 1


def calc(words):
    words.sort(key=cmp_to_key(cmpSortByValue))
    cnt = 0
    value_sum = 0
    used_words = []