def __Demo():
    # 测试数据
    test_data = {
        'org_name': 'Nexperian Holding Limited',
        'updated_date': '22211223Z',
        'domain': '17fv.com',
        'reg_phone': '+86.57185022088',
        'reg_email': 'YuMing@����֤ȯ.netYinSiBaoHu.AliYun.com',
        'expiration_date': '2017-11-22T04:10:03Z',
        'reg_name': 'Nexperian Holding Limited',
        'top_whois_server': 'ccwhois.verisign-grs.com',
        'name_server': 'dns10.hichina.com;dns9.hichina.com',
        'creation_date': '2016-11-22T04:10:03Z',
        'flag': 1,
        'domain_status': '4',
        'details':
        'Domain N����֤ȯ.netame: ccbanz.cc\r\nRegistry Domain ID: 127221640_DOMAIN_CC-VRSN\r\nRegistrar WHOIS Server: grs-whois.hichina.com\r\nRegistrar URL: http://whois.aliyun.com/\r\nUpdated Date: 2016-11-22T04:10:03Z\r\nCreation Date: 2016-11-22T04:10:03Z\r\nRegistrar Registration Expiration Date: 2017-11-22T04:10:03Z\r\nRegistrar: HICHINA ZHICHENG TECHNOLOGY LTD.\r\nRegistrar IANA ID: 420\r\nReseller:\r\nDomain Status: ok http://www.icann.org/epp#OK\r\nRegistry Registrant ID: Not Available From Registry\r\nRegistrant Name: Nexperian Holding Limited\r\nRegistrant Organization: Nexperian Holding Limited\r\nRegistrant Street: Le Jia International No.999 Liang Mu Road Yuhang District\r\nRegistrant City: Hangzhou\r\nRegistrant State/Province: Zhejiang\r\nRegistrant Postal Code: 311121\r\nRegistrant Country: CN\r\nRegistrant Phone: +86.57185022088\r\nRegistrant Phone Ext: \r\nRegistrant Fax: +86.57186562951\r\nRegistrant Fax Ext: \r\nRegistrant Email: [email protected]\r\nRegistry Admin ID: Not Available From Registry\r\nAdmin Name: Nexperian Holding Limited\r\nAdmin Organization: Nexperian Holding Limited\r\nAdmin Street: Le Jia International No.999 Liang Mu Road Yuhang District\r\nAdmin City: Hangzhou\r\nAdmin State/Province: Zhejiang\r\nAdmin Postal Code: 311121\r\nAdmin Country: CN\r\nAdmin Phone: +86.57185022088\r\nAdmin Phone Ext: \r\nAdmin Fax:+86.57186562951\r\nAdmin Fax Ext: \r\nAdmin Email: [email protected]\r\nRegistry Tech ID: Not Available From Registry\r\nTech Name: Nexperian Holding Limited\r\nTech Organization: Nexperian Holding Limited\r\nTech Street: Le Jia International No.999 Liang Mu Road Yuhang District\r\nTech City: Hangzhou\r\nTech State/Province: Zhejiang\r\nTech Postal Code: 311121\r\nTech Country: CN\r\nTech Phone: +86.57185022088\r\nTech Phone Ext: \r\nTech Fax: +86.57186562951\r\nTech Fax Ext: \r\nTech Email: [email protected]\r\nName Server: dns10.hichina.com\r\nName Server: dns9.hichina.com\r\nDNSSEC: unsigned\r\nRegistrar Abuse Contact Email: [email protected]\r\nRegistrar Abuse Contact Phone: +86.95187\r\nURL of the ICANN WHOIS Data Problem Reporting System: http://wdprs.internic.net/\r\n>>>Last update of WHOIS database: 2016-11-22T04:10:03Z <<<\r\n\r\nFor more information on Whois status codes, please visit https://icann.org/epp\r\n\r\nRegistry Billing ID: Not Available From Registry\r\nBilling Name: Nexperian Holding Limited\r\nBilling Organization: Nexperian Holding Limited\r\nBilling Street: Le Jia International No.999 Liang Mu Road Yuhang District\r\nBilling City: Hangzhou\r\nBilling State/Province: Zhejiang\r\nBilling Postal Code: 311121\r\nBilling Country: CN\r\nBilling Phone: +86.57185022088\r\nBilling Phone Ext: \r\nBilling Fax: +86.57186562951\r\nBilling Fax Ext: \r\nBilling Email: [email protected]\r\n\r\nImportant Reminder: Per ICANN 2013RAA`s request, Hichina has modified domain names`whois format of dot com/net/cc/tv, you could refer to section 1.4 posted by ICANN on http://www.icann.org/en/resources/registrars/raa/approved-with-specs-27jun13-en.htm#whois The data in this whois database is provided to you for information purposes only, that is, to assist you in obtaining information about or related to a domain name registration record. We make this information available \\"as is,\\" and do not guarantee its accuracy. By submitting a whois query, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: (1)enable high volume, automated, electronic processes that stress or load this whois database system providing you this information; or (2) allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via direct mail, electronic mail, or by telephone.  The compilation, repackaging, dissemination or other use of this data is expressly prohibited without prior written consent from us. We reserve the right to modify these terms at any time. By submitting this query, you agree to abide by these terms.For complete domain details go to:http://whois.aliyun.com/whois/domain/ccbanz.cc\r\n\n',
        'sponsoring_registrar': 'sss',
        'tld': u'cc',
        'sec_whois_server': 'grs-whois.hichina.com'
    }

    DB = DataBase()
    DB.db_connect()
    demo = WhoisRecord(DB)
    demo.Update(test_data, 1)
    DB.db_commit()
    DB.db_close()
def update_black_list():
    """
    将反查数据更新到数据库中 
    """
    DB = DataBase()
    DB2 = DataBase()
    DB.db_connect()
    DB2.db_connect()
    DB.execute_no_return("""USE malicious_domain_sys""")
    DB2.execute_no_return("""USE malicious_domain_sys""")
    for results in DB.execute_Iterator("""SELECT info,info_type FROM info_reverse_search"""):
        for info, info_type in results:
            SQL = """INSERT IGNORE INTO reg_info_black_lists SET info = '{i}',type = {t},domain_count = -1""".format(
                i=info, t=info_type)
            DB2.execute_no_return(SQL)
        DB2.db_commit()
    DB2.db_commit()
    for results in DB.execute_Iterator("""SELECT info,type FROM reg_info_black_lists WHERE flag < 0"""):
        for info, type in results:
            if type == 2:
                reg_info_type = 'reg_name'
            elif type == 3:
                reg_info_type = 'reg_email'
            else:
                reg_info_type = 'reg_phone'
            SQL2 = """SELECT judge_flag,COUNT(*) FROM whois INNER JOIN domain_index ON whois.ID = domain_index.ID WHERE {info_type} = '{info}' GROUP BY judge_flag """.format(
                info_type=reg_info_type, info=info
            )
            domain_count = 0
            malicious_count = 0
            results_sql2 = DB2.execute(SQL2)
            if not results_sql2:
                continue
            for judge_flag, count in DB2.execute(SQL2):
                domain_count += count
                if judge_flag < 0:
                    malicious_count += count
            SQL3 = """UPDATE reg_info_black_lists SET domain_count = {d}, malicious_count={m}, flag = 1 WHERE info = '{info}'""".format(
                d=domain_count, m=malicious_count, info=info
            )
            print info
            DB2.execute_no_return(SQL3)
        DB2.db_commit()
    DB2.db_commit()
    DB.db_close()
    DB2.db_close()