Ejemplo n.º 1
0
def mdf_words(conn):
    cursor = conn.cursor()
    data = request.form
    nm, expl = escape_string(data['nm']), escape_string(data['expl'])
    if data['id'] == '新增':
        cursor.execute(
            'insert into words(nm, c_tm, m_tm, expl, sound) VALUES("%s", current_time(), current_time(), "%s", "%s")'
            % (nm, expl, ''))
        conn.commit()
        cursor.execute('select last_insert_id()')
        words_id = cursor.fetchone()[0]
        re = gen_response('suc', {'id': words_id})
    else:
        words_id = int(data['id'])
        cursor.execute(
            'update words set nm="%s",m_tm=current_time(),expl="%s" where id=%d'
            % (nm, expl, words_id))
        re = gen_response('suc', {})
    if 'sound' not in data:
        # 存储mp3
        file = request.files.get('sound')
        cursor.execute('select sound from words where id=%d' % words_id)
        # 删除旧的
        old_path = cursor.fetchone()[0]
        folder = static_path + 'mp3' + sep
        if old_path and exists(folder + old_path):
            remove(folder + old_path)
        # 加上时间戳
        sound_filename = str(words_id) + '_' + str(int(time())) + '.mp3'
        sound_path = folder + sound_filename
        # 存储并更新表
        file.save(sound_path)
        cursor.execute('update words set sound="%s" where id=%d' %
                       (sound_filename, words_id))
    return re
Ejemplo n.º 2
0
def get_config():
    return gen_response(
        'suc', {
            'pwd': config['pwd'],
            'home_btn': config['home_btn'],
            'about': config['about']
        })
Ejemplo n.º 3
0
def mdf_book(conn):
    cursor = conn.cursor()
    data = request.form
    nm, author, summary, expl, info = escape_string(data['nm']), escape_string(
        data['author']), escape_string(data['summary']), escape_string(
            data['expl']), escape_string(data['info'])
    weight = 0.3
    for i in eval(data['info']):
        if i['key'] == '字数':
            weight = int(i['val'].replace('千', '')) / 800
            if weight < 0.25: weight = 0.25
            if weight > 1.25: weight = 1.25
            break
    if data['id'] == '新增':
        cursor.execute(
            'insert into book(nm, author, summary, c_tm, m_tm, expl, cover, info, weight) VALUES("%s", "%s", "%s", current_time(), current_time(), "%s", "%s", "%s", %s)'
            % (nm, author, summary, expl, '', info, str(weight)))
        conn.commit()
        cursor.execute('select last_insert_id()')
        book_id = cursor.fetchone()[0]
        re = gen_response('suc', {'id': book_id})
    else:
        book_id = int(data['id'])
        cursor.execute(
            'update book set nm="%s",author="%s",summary="%s",m_tm=current_time(),expl="%s",info="%s",weight=%s where id=%d'
            % (nm, author, summary, expl, info, str(weight), book_id))
        re = gen_response('suc', {})
    if 'cover' not in data:
        # 存储封面
        file = request.files.get('cover')
        cursor.execute('select cover from book where id=%d' % book_id)
        # 删除旧的
        old_path = cursor.fetchone()[0]
        folder = static_path + 'img' + sep + 'book' + sep
        if old_path and exists(folder + old_path):
            remove(folder + old_path)
        ''' 加上时间戳 '''
        cover_filename = str(book_id) + '_' + str(int(
            time())) + '.' + file.content_type.replace('image/', '')
        cover_path = folder + cover_filename
        # 存储并更新表
        file.save(cover_path)
        cursor.execute('update book set cover="%s" where id=%d' %
                       (cover_filename, book_id))
    return re
Ejemplo n.º 4
0
def util_get_list(conn):
    cursor = conn.cursor(DictCursor)
    data = dict_post_data()
    what = data['what']
    if what == 'words':
        args = ''
    elif what == 'book':
        args = ',cover,weight'
    else:
        args = ',cover'
    page, count = int(data['page']), int(data['count'])
    re = {}
    cursor.execute('select count(*) as c from ' + what)
    re['count'] = cursor.fetchone()['c']
    cursor.execute('select id,nm%s from %s order by id desc limit %d,%d' %
                   (args, what, page * count, count))
    re['list'] = cursor.fetchall()
    return gen_response('suc', re)
Ejemplo n.º 5
0
def util_get_detail(conn):
    cursor = conn.cursor(DictCursor)
    data = dict_post_data()
    what = data['what']
    if what == 'words':
        args = 'sound'
    elif what == 'book':
        args = 'cover,author,summary,info,weight'
    else:
        args = 'cover,summary,info,posters'
    if data['id'] != '':
        cursor.execute(
            'select nm,date_format(c_tm, "%s") as c_tm,date_format(m_tm, "%s") as m_tm,expl,%s from %s where id=%d'
            % (data_format, data_format, args, what, int(data['id'])))
    else:
        cursor.execute(
            'select nm,date_format(c_tm, "%s") as c_tm,date_format(m_tm, "%s") as m_tm,expl,%s from %s order by id desc limit 0,1'
            % (data_format, data_format, args, what))
    return gen_response('suc', cursor.fetchone())
Ejemplo n.º 6
0
def util_get_list_manager(conn):
    cursor = conn.cursor(DictCursor)
    data = dict_post_data()
    what = data['what']
    s, page, count, orient = escape_string(data['s']), int(data['page']), int(
        data['count']), ('' if data['desc'] == 'unset' else
                         (' order by ' + data['order'] +
                          (' desc ' if data['desc'] == 'desc' else ' ')))
    where = (' ' if s == '' else ' where nm like "%s" ' % ("%%" + s + "%%"))
    re = {}
    cursor.execute('select count(*) as c from ' + what + where + orient)
    re['count'] = cursor.fetchone()['c']
    cursor.execute((
        'select id,nm%s,date_format(c_tm, "%s") as c_tm,date_format(m_tm, "%s") as m_tm from %s '
        + where + orient + ' limit %d,%d') %
                   (('' if what == 'words' else ',cover'), data_format,
                    data_format, what, page * count, count))
    re['list'] = cursor.fetchall()
    return gen_response('suc', re)
Ejemplo n.º 7
0
def del_item(conn):
    data = dict_post_data()
    cursor = conn.cursor(DictCursor)
    what, id_ = data['what'], int(data['id'])
    if what == 'words':
        # 删除MP3
        cursor.execute('select sound from words where id=%d' % id_)
        remove(static_path + 'mp3' + sep + cursor.fetchone()['sound'])
    else:
        # 删除封面
        cursor.execute('select cover from %s where id=%d' % (what, id_))
        remove(static_path + 'img' + sep + what + sep +
               cursor.fetchone()['cover'])
        if what == 'film':
            # 删除海报
            cursor.execute('select posters from film where id=%d' % id_)
            for i in eval(cursor.fetchone()['posters']):
                remove(static_path + 'img' + sep + 'film' + sep + i)
    cursor.execute('delete from %s where id=%d' % (what, id_))
    return gen_response('suc', {})
Ejemplo n.º 8
0
def get_info():
    return gen_response('suc', config['home_btn'])
Ejemplo n.º 9
0
def submit_config():
    data = dict_post_data()
    config.update(data)
    while not save_config():
        sleep(1)
    return gen_response('suc', {})
Ejemplo n.º 10
0
def mdf_film(conn):
    cursor = conn.cursor()
    data = request.form
    nm, summary, expl, info, poster_list = escape_string(
        data['nm']), escape_string(data['summary']), escape_string(
            data['expl']), escape_string(data['info']), eval(
                data['poster_list'])
    if data['id'] == '新增':
        cursor.execute(
            'insert into film(nm, summary, c_tm, m_tm, expl, cover, info, posters) VALUES("%s", "%s", current_time(), current_time(), "%s", "%s", "%s", "[]")'
            % (nm, summary, expl, '', info))
        conn.commit()
        cursor.execute('select last_insert_id()')
        film_id = cursor.fetchone()[0]
        re = gen_response('suc', {'id': film_id})
    else:
        film_id = int(data['id'])
        cursor.execute(
            'update film set nm="%s",summary="%s",m_tm=current_time(),expl="%s",info="%s" where id=%d'
            % (nm, summary, expl, info, film_id))
        re = gen_response('suc', {})
    folder = static_path + 'img' + sep + 'film' + sep
    if 'cover' not in data:
        # 存储封面
        file = request.files.get('cover')
        cursor.execute('select cover from film where id=%d' % film_id)
        # 删除旧的
        old_path = cursor.fetchone()[0]
        if old_path and exists(folder + old_path):
            remove(folder + old_path)
        ''' 加上时间戳 '''
        cover_filename = str(film_id) + '_' + str(int(
            time())) + '.' + file.content_type.replace('image/', '')
        # 存储并更新表
        file.save(folder + cover_filename)
        cursor.execute('update film set cover="%s" where id=%d' %
                       (cover_filename, film_id))
        conn.commit()
    # 海报
    cursor.execute('select posters from film where id=%d' % film_id)
    poster_old = eval(cursor.fetchone()[0])
    poster_new = []
    idx = 0
    for i in poster_list:
        if i[0:7] == 'poster_':
            file = request.files.get(i)
            poster_name = str(film_id) + '_poster' + str(idx) + '_' + str(
                int(time())) + sub(r'^.*_', '_',
                                   i) + '.' + file.content_type.replace(
                                       'image/', '')
            file.save(folder + poster_name)
            poster_new.append(poster_name)
        else:
            poster_new.append(i)
        idx += 1
    # 删除
    for i in poster_old:
        if i not in poster_new:
            if exists(folder + i):
                remove(folder + i)
    cursor.execute('update film set posters="%s" where id=%d' %
                   (escape_string(str(poster_new).replace("'", '"')), film_id))
    return re
Ejemplo n.º 11
0
def get_something(what):
    if what == 'tip':
        return gen_response('suc', config['tip'])
    elif what == 'views':
        return gen_response('suc', config['views'])
Ejemplo n.º 12
0
def login():
    data = dict_post_data()
    is_equal = data['pwd'] == config['pwd']
    if is_equal:
        session['login'] = True
    return gen_response('suc' if is_equal else 'err', [])
Ejemplo n.º 13
0
def get_about():
    return gen_response('suc', config['about'])