示例#1
0
def soldier_restrain_import(db):
    data = request.files.data
    error = ''
    if data and data.file:
        tmp_root = './tmp/'
        if not isdir(tmp_root):
            os.mkdir(tmp_root)
        tmp_filename = os.path.join(
            tmp_root, current_time('tmpsoldierrestrain_%Y%m%d%H%M.xls'))
        tmp_file = open(tmp_filename, 'w')
        rows = data.file.readlines()
        if not rows:
            error = '数据个数错误[2]'
            return template('error', error=error)
        for row in rows:
            tmp_file.write(row)
        tmp_file.close()

        # 导入数据前先备份当前数据库中数据
        export_sqls = SOLDIER_RESTRAIN_EXPORT_SQLS
        try:
            if os.path.exists(
                    os.path.join(tmp_root, SOLDIER_RESTRAIN_BACK_FILE)):
                os.remove(os.path.join(tmp_root, SOLDIER_RESTRAIN_BACK_FILE))
            excel_export(export_sqls, tmp_root, SOLDIER_RESTRAIN_BACK_FILE, db)
        except Exception, e:
            print 'soldier restrain 数据备份错误:%s' % e

        all_sqls = SOLDIER_RESTRAIN_IMPORT_SQLS
        error = excel_import(all_sqls, tmp_filename, db)
        os.remove(tmp_filename)
示例#2
0
def monthly_card_import(db):
    data = request.files.data
    error = ''
    all_sqls = IMPORT_SQLS 

    if data and data.file:
        tmp_root = './tmp/'
        if not isdir(tmp_root):  # 若目录tmp_root不存在,则创建
            os.mkdir(tmp_root)
        tmp_filename = os.path.join(tmp_root, current_time('tmp_monthly_card%Y%m%d%H%M%S.xls'))
        tmp_file = open(tmp_filename, 'w')  # 新建一个xls后缀的文件,然后将读取的excel文件的内容写入该文件中
        rows = data.file.readlines()

        if not rows:  # 文件空
            error = '数据格式错误[2]'
            return template('error', error=error)
        for row in rows:
            tmp_file.write(row)
        tmp_file.close()

        # 在导入新的数据前,先将数据库原有数据导出到tmp目录,作为备份,数据导入失败时可以恢复数据
        export_sqls = EXPORT_SQLS
        try:
            # 若备份文件已存在,则删除重新写入
            if os.path.exists(os.path.join(tmp_root, BACK_FILE)):
                os.remove(os.path.join(tmp_root, BACK_FILE))
            excel_export(export_sqls, tmp_root, BACK_FILE, db)
        except Exception, e:
            print '数据备份错误: %s' %e

        error = excel_import(all_sqls, tmp_filename, db)
        os.remove(tmp_filename)  # 删除上传的临时文件
示例#3
0
def soldier_restrain_import(db):
    data = request.files.data
    error = ''
    if data and data.file:
        tmp_root = './tmp/'
        if not isdir(tmp_root):
            os.mkdir(tmp_root)
        tmp_filename = os.path.join(tmp_root, current_time('tmpsoldierrestrain_%Y%m%d%H%M.xls'))
        tmp_file = open(tmp_filename, 'w')
        rows = data.file.readlines()
        if not rows:
            error = '数据个数错误[2]'
            return template('error', error=error)
        for row in rows:
            tmp_file.write(row)
        tmp_file.close()
        
        # 导入数据前先备份当前数据库中数据
        export_sqls = SOLDIER_RESTRAIN_EXPORT_SQLS
        try:
            if os.path.exists(os.path.join(tmp_root, SOLDIER_RESTRAIN_BACK_FILE)):
                os.remove(os.path.join(tmp_root, SOLDIER_RESTRAIN_BACK_FILE))
            excel_export(export_sqls, tmp_root, SOLDIER_RESTRAIN_BACK_FILE, db)
        except Exception, e:
            print 'soldier restrain 数据备份错误:%s' %e

        all_sqls = SOLDIER_RESTRAIN_IMPORT_SQLS
        error = excel_import(all_sqls, tmp_filename, db)
        os.remove(tmp_filename)
示例#4
0
def error_import(db):
    data = request.files.data
    error = ''
    if data and data.file:
        tmp_root = './tmp/'
        if not isdir(tmp_root):
            os.mkdir(tmp_root)
        tmp_filename = os.path.join(tmp_root, current_time('tmperror_%Y%m%d%H%M.xls'))
        tmp_file = open(tmp_filename, 'w')  # 新建一个xls后缀的文件,然后将读取的excel文件的内容写入该文件
        rows = data.file.readlines()
        if not rows:  # 文件空
            error = '数据个数错误[2]'
            return template('error', error=error)
        for row in rows:
            tmp_file.write(row)
        tmp_file.close()

        # 导入数据前,先对数据库数据进行备份
        export_sqls = ERROR_EXPORT_SQLS
        try:
            # 若备份文件存在,删除重新写入
            if os.path.exists(os.path.join(tmp_root, ERROR_BACK_FILE)):
                os.remove(os.path.join(tmp_root, ERROR_BACK_FILE))
            excel_export(export_sqls, tmp_root, ERROR_BACK_FILE, db)
        except Exception, e:
            print 'error 数据备份错误: %s' %e

        all_sqls = ERROR_IMPORT_SQLS
        error = excel_import(all_sqls, tmp_filename, db)
        os.remove(tmp_filename)  # 删除临时文件
示例#5
0
def keyword_import(db):
    data = request.files.data
    error = ''
    lang_id = int(request.forms.lang)

    _table = 'tb_keyword_%s' % lang_id if lang_id and lang_id != '0' else table_name

    all_sqls = {'Message': [insert_sql.format(_table), _table]}
    export_sqls = {
        _table: [sql_base_tpl.format(_table), field_base, 'Message']
    }

    if data and data.file:
        tmp_root = './tmp/'
        if not isdir(tmp_root):  # 若目录tmp_root不存在,则创建
            os.mkdir(tmp_root)
        tmp_filename = os.path.join(
            tmp_root, current_time('tmpkeyword_%Y%m%d%H%M%S.xls'))
        tmp_file = open(tmp_filename,
                        'w')  # 新建一个xls后缀的文件,然后将读取的excel文件的内容写入该文件中
        rows = data.file.readlines()

        if not rows:  # 文件空
            error = '数据格式错误[2]'
            return template('error', error=error)
        for row in rows:
            tmp_file.write(row)
        tmp_file.close()

        # 在导入新的数据前,先将数据库原有数据导出到tmp目录,作为备份,数据导入失败时可以恢复数据
        try:
            # 若备份文件已存在,则删除重新写入
            if os.path.exists(os.path.join(tmp_root, BACK_FILE)):
                os.remove(os.path.join(tmp_root, BACK_FILE))
            excel_export(export_sqls, tmp_root, BACK_FILE, db)
        except Exception, e:
            print '数据备份错误: %s' % e

        error = excel_import(all_sqls, tmp_filename, db)
        os.remove(tmp_filename)  # 删除上传的临时文件
示例#6
0
def monthly_card_export(db):
    tmp_root = './tmp/'
    filename = current_time(excel_export_filename)  # 文件名
    error = ''

    if not isfile(tmp_root + filename): 
        all_sqls = EXPORT_SQLS
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:  
        return template('error', error=error)
    else:
        return static_file(filename, root = tmp_root, download = filename)
def randcard_consume_export(db):
    tmp_root = './tmp/'
    filename = current_time("randcard_consume_%Y%m%d%H%M.xls")  # 文件名
    error = ''

    if not isfile(tmp_root + filename):
        all_sqls = EXPORT_SQLS
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:
        return template('error', error=error)
    else:
        return static_file(filename, root=tmp_root, download=filename)
示例#8
0
def lover_kiss_export(db):
    tmp_root = './tmp/'
    filename = current_time("lover_kiss_%Y%m%d%H%M.xls")  # 文件名
    error = ''

    if not isfile(tmp_root + filename): 
        all_sqls = EXPORT_SQLS
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:  
        return template('error', error=error)
    else:
        return static_file(filename, root = tmp_root, download = filename)
示例#9
0
def soldier_restrain_export(db):
    tmp_root = './tmp/'
    filename = current_time('soldierrestrain_%Y%m%d%H%M.xls')
    error = ''

    if not isfile(tmp_root + filename):
        all_sqls = SOLDIER_RESTRAIN_EXPORT_SQLS
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:
        return template('error', error=error)
    else:
        return static_file(filename, root=tmp_root, download=filename)
def open_server_activity_shop_export(db):
    tmp_root = './tmp/'
    filename = current_time("open_server_activity_shop_%Y%m%d%H%M.xls")  # 文件名
    error = ''

    if not isfile(tmp_root + filename): 
        all_sqls = EXPORT_SQLS
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:  
        return template('error', error=error)
    else:
        return static_file(filename, root = tmp_root, download = filename)
示例#11
0
def monster_drop_export(db):
    tmp_root = './tmp/'
    filename = current_time("monster_drop_%Y%m%d%H%M.xls")  # 文件名
    error = ''

    if not isfile(tmp_root + filename):
        all_sqls = MONSTER_DROP_EXPORT_SQLS
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:
        return template('error', error=error)
    else:
        return static_file(filename, root=tmp_root, download=filename)
示例#12
0
def soldier_restrain_export(db):
    tmp_root = './tmp/'
    filename = current_time('soldierrestrain_%Y%m%d%H%M.xls')
    error = ''

    if not isfile(tmp_root + filename):
        all_sqls = SOLDIER_RESTRAIN_EXPORT_SQLS
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:
        return template('error', error=error)
    else:
        return static_file(filename, root=tmp_root, download=filename)
示例#13
0
def limit_fellow_pool_export(db):
    tmp_root = './tmp/'
    filename = current_time("LimitFellowPool_%Y%m%d%H%M.xls")  # 文件名
    error = ''

    if not isfile(tmp_root + filename):
        all_sqls = EXPORT_SQLS
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:
        return template('error', error=error)
    else:
        return static_file(filename, root=tmp_root, download=filename)
示例#14
0
def keyword_export(lang, db):
    tmp_root = './tmp/'
    filename = current_time("keyword_%Y%m%d%H%M.xls")  # 文件名
    error = ''

    _table = 'tb_keyword_%s' % lang if lang and lang != '0' else table_name
    all_sqls = {_table: [sql_base_tpl.format(_table), field_base, 'Message']}

    if not isfile(tmp_root + filename):
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:
        return template('error', error=error)
    else:
        return static_file(filename, root=tmp_root, download=filename)
示例#15
0
def keyword_export(lang, db):
    tmp_root = './tmp/'
    filename = current_time("keyword_%Y%m%d%H%M.xls")  # 文件名
    error = ''

    _table = 'tb_keyword_%s' % lang if lang and lang != '0' else table_name
    all_sqls = { _table : [sql_base_tpl.format( _table ), field_base, 'Message'] }

    if not isfile(tmp_root + filename): 
        error = excel_export(all_sqls, tmp_root, filename, db)

    if error:  
        return template('error', error=error)
    else:
        return static_file(filename, root = tmp_root, download = filename)
示例#16
0
def keyword_import(db):
    data = request.files.data
    error = ''
    lang_id = int(request.forms.lang)

    _table = 'tb_keyword_%s' % lang_id if lang_id and lang_id != '0' else table_name

    all_sqls    = { 'Message' : [insert_sql.format( _table ), _table] }
    export_sqls = { _table : [sql_base_tpl.format( _table ), field_base, 'Message'] }

    if data and data.file:
        tmp_root = './tmp/'
        if not isdir(tmp_root):  # 若目录tmp_root不存在,则创建
            os.mkdir(tmp_root)
        tmp_filename = os.path.join(tmp_root, current_time('tmpkeyword_%Y%m%d%H%M%S.xls'))
        tmp_file = open(tmp_filename, 'w')  # 新建一个xls后缀的文件,然后将读取的excel文件的内容写入该文件中
        rows = data.file.readlines()

        if not rows:  # 文件空
            error = '数据格式错误[2]'
            return template('error', error=error)
        for row in rows:
            tmp_file.write(row)
        tmp_file.close()

        # 在导入新的数据前,先将数据库原有数据导出到tmp目录,作为备份,数据导入失败时可以恢复数据
        try:
            # 若备份文件已存在,则删除重新写入
            if os.path.exists(os.path.join(tmp_root, BACK_FILE)):
                os.remove(os.path.join(tmp_root, BACK_FILE))
            excel_export(export_sqls, tmp_root, BACK_FILE, db)
        except Exception, e:
            print '数据备份错误: %s' %e

        error = excel_import(all_sqls, tmp_filename, db)
        os.remove(tmp_filename)  # 删除上传的临时文件