Пример #1
0
def collegeUpdate(filename, college_tablename):
    ret = jsonDownload(filename)
    if ret > 0:
        print('成功将大学地址数据写入到%s, %s字节' %
              (filename, format(ret, ','))
            )
        print('------------------------------------------- ')
    else:
        print('写入失败, 错误代码: %d' % ret)
        print('------------------------------------------- ')
        print('尝试导入本地json文件...\n---------------处理中, 请稍候---------------')
        college_json = load_json(filename)
        if college_json:
            print('导入成功!')
            print('------------------------------------------- ')
        else:
            print('导入失败,请手动下载文件至'+filename)
            exit()
    mysql = mysql_Database(config['mysql'].ip_database)
    convert_college(mysql, filename, college_tablename)
Пример #2
0
def collegeUpdate(filename, college_tablename, sqlite3file=None):
    ret = jsonDownload(filename)
    if ret > 0:
        print('成功将大学地址数据写入到%s, %s字节' % (filename, format(ret, ',')))
        print('------------------------------------------- ')
    else:
        print('写入失败, 错误代码: %d' % ret)
        print('------------------------------------------- ')
        print('尝试导入本地json文件...\n---------------处理中, 请稍候---------------')
        college_json = load_json(filename)
        if college_json:
            print('导入成功!')
            print('------------------------------------------- ')
        else:
            print('导入失败,请手动下载文件至' + filename)
            sys.exit()
    if sqlite3file:
        sql_object = sqlite3_Database(sqlite3file)
        sqlite3 = True
    else:
        sql_object = mysql_Database(config['mysql'].ip_database)
        sqlite3 = False
    convert_college(sql_object, filename, college_tablename, sqlite3=sqlite3)
Пример #3
0
def sqldump(mysql_object):
    print( "连接IP数据库, 并导出为sql文件: \n---------------处理中, 请稍候---------------")
    sql_file = os.path.abspath(data_dir+os.path.sep+"ipdatabase.sql")
    os.system('mysqldump -h %s -P %s -u %s -p%s %s > %s' % (config['mysql'].host, config['mysql'].port, config['mysql'].user, config['mysql'].password, config['mysql'].ip_database, sql_file))
    print( "IP数据库导出成功! ")
    table_college_info_sql_file = os.path.abspath(data_dir+os.path.sep+"college_info.sql")
    table_iprange_info_sql_file = os.path.abspath(data_dir+os.path.sep+"iprange_info.sql")
    os.system('mysqldump -h %s -P %s -u %s -p%s %s college_info > %s' % (config['mysql'].host, config['mysql'].port, config['mysql'].user, config['mysql'].password, config['mysql'].ip_database, table_college_info_sql_file))
    print( "高校信息表导出成功! ")
    os.system('mysqldump -h %s -P %s -u %s -p%s %s iprange_info > %s' % (config['mysql'].host, config['mysql'].port, config['mysql'].user, config['mysql'].password, config['mysql'].ip_database, table_iprange_info_sql_file))
    print( "IP数据表导出成功! ")
    
if __name__ == '__main__':
    """
    @description  :实现纯真IP数据库的下载和更新.
    ---------
    @params  :None
    -------
    @Returns  :None
    -------
    """
    filename =  os.path.abspath(data_dir+os.path.sep+"czipdata.dat")
    if os.path.exists(filename):
        txt_filename = os.path.abspath(data_dir+os.path.sep+"czipdata.txt")
        if os.path.exists(txt_filename):
            dat2Txt(txt_filename= txt_filename)
            #pass
    mysql = mysql_Database(config['mysql'].ip_database)
    dat2Mysql(mysql)
    convertipv4(mysql)
    sqldump(mysql)
Пример #4
0
            college_tablename = opt_value
            varlist.append('college_tablename')
        if opt_name in ('-f', '--college_filename'):
            college_filename = opt_value
            varlist.append('college_filename')
        if opt_name in ('-c', '--correct_filename'):
            correct_filename = opt_value
            varlist.append('correct_filename')
    if 'num_config' not in varlist:
        num_config = 20000
    if 'start_id' not in varlist:
        start_id = 1
    if 'college_tablename' not in varlist:
        college_tablename = 'college_info'
    if 'college_filename' not in varlist:
        tmp_dir = os.path.abspath(
            os.path.dirname(__file__) + os.path.sep + "tmp")
        file_set(tmp_dir, 'dir')
        college_filename = os.path.abspath(tmp_dir + os.path.sep +
                                           "college.json")
    if 'correct_filename' not in varlist:
        data_dir = os.path.abspath(
            os.path.dirname(os.path.dirname(__file__)) + os.path.sep + "data")
        file_set(data_dir, 'dir')
        correct_filename = os.path.abspath(data_dir + os.path.sep +
                                           "correct.json")
        file_set(correct_filename)

    mysql_object = mysql_Database(config['mysql'].ip_database)
    convert(mysql_object, college_tablename, num_config, start_id,
            college_filename, correct_filename)