Beispiel #1
0
def update_tlds():
    """
    Calls the Namecheap API to update the list of recognized and registerable top-level domains.  This is currently initiated manually via the administration panel.
    """
    params = AdminSetting.get_api_params()
    params.append((u'Command', u'namecheap.domains.gettldlist'))
    r = requests.get(AdminSetting.get_api_url(), params=params)
    rtext = r.text

    send_mail(
        u'Domain Checker - TLD Update',
        u'The following response was received from the TLD update (using %s):\n\n%s'
        % (AdminSetting.get_api_url(), rtext),
        AdminSetting.get_value(u'noreply_address'),
        [AdminSetting.get_value(u'admin_address')])

    parser = etree.XMLParser(encoding=u'utf-8')
    header_len = len('<?xml version="1.0" encoding="utf-8"?>')
    rtext = rtext[header_len:]
    rtree = etree.fromstring(rtext, parser=parser)
    rels = rtree.findall(
        u'./{http://api.namecheap.com/xml.response}CommandResponse/{http://api.namecheap.com/xml.response}Tlds/{http://api.namecheap.com/xml.response}Tld'
    )

    rels = dict([(r.attrib[u'Name'], r) for r in rels])
    tlds = TLD.objects.all()
    with transaction.atomic():
        for tld in tlds:
            if tld.domain in rels.keys():
                rel = rels[tld.domain]
                tld.is_recognized = True
                tld.is_api_registerable = (
                    rel.attrib[u'IsApiRegisterable'] == u'true')
                tld.description = rel.text
                tld.type = rel.attrib[u'Type']
            else:
                tld.is_recognized = False
                tld.is_api_registrable = False
                tld.type = u'unknown'
                tld.description = None
            tld.save()

        for ncd, rel in rels.items():
            if len(TLD.objects.filter(domain=ncd)) == 0:
                new_tld = TLD(domain=ncd,
                              is_recognized=True,
                              is_api_registerable=(
                                  rel.attrib['IsApiRegisterable'] == True),
                              description=rel.text,
                              type=rel.attrib['Type'])
                new_tld.save()
                print u'New TLD added: %s' % ncd
    print u'Finished processing tlds.'
Beispiel #2
0
def update_tlds():
    """
    Calls the Namecheap API to update the list of recognized and registerable top-level domains.  This is currently initiated manually via the administration panel.
    """
    params = AdminSetting.get_api_params()
    params.append((u'Command', u'namecheap.domains.gettldlist'))
    r = requests.get(AdminSetting.get_api_url(), params=params)
    rtext = r.text

    send_mail(u'Domain Checker - TLD Update', u'The following response was received from the TLD update (using %s):\n\n%s' % (AdminSetting.get_api_url(), rtext), AdminSetting.get_value(u'noreply_address'), [AdminSetting.get_value(u'admin_address')])

    parser = etree.XMLParser(encoding=u'utf-8')
    rtree = etree.fromstring(rtext, parser=parser)
    rels = rtree.findall(u'./{http://api.namecheap.com/xml.response}CommandResponse/{http://api.namecheap.com/xml.response}Tlds/{http://api.namecheap.com/xml.response}Tld')

    rels = dict([(r.attrib[u'Name'], r) for r in rels])
    tlds = TLD.objects.all()
    with transaction.atomic():
        for tld in tlds:
            if tld.domain in rels.keys():
                rel = rels[tld.domain]
                tld.is_recognized = True
                tld.is_api_registerable = (rel.attrib[u'IsApiRegisterable'] == u'true')
                tld.description = rel.text
                tld.type = rel.attrib[u'Type']
            else:
                tld.is_recognized = False
                tld.is_api_registrable = False
                tld.type = u'unknown'
                tld.description = None
            tld.save()

        for ncd, rel in rels.items():
            if len(TLD.objects.filter(domain=ncd)) == 0:
                new_tld = TLD(domain=ncd, is_recognized=True, is_api_registerable=(rel.attrib['IsApiRegisterable'] == True), description=rel.text, type=rel.attrib['Type'])
                new_tld.save()
                print u'New TLD added: %s' % ncd
    print u'Finished processing tlds.'
Beispiel #3
0
    def handle(self, *args, **options):
        tld_filename = 'tld_list.txt'
        exclusion_filename = 'exclusion_domains.txt'
        settings_filename = 'clean_admin.txt'

        tldf = open(tld_filename)
        tlds = [line.strip() for line in tldf if line[0] not in '/\n']
        tldf.close()
        exf = open(exclusion_filename)
        exl = [line.strip() for line in exf]
        exf.close()
        sf = open(settings_filename)
        ss = [line.strip() for line in sf]
        sf.close()

        tic = 0
        for tld in tlds:
            try:
                t = TLD.objects.get(domain=tld)
            except TLD.DoesNotExist:
                t = TLD()
                t.domain = tld
                t.is_recognized = False
                t.is_api_registerable = False
                t.description = None
                t.type = ''
                t.save()
                tic += 1
        self.stdout.write('TLDs: Inserted %d row(s) (out of %d TLDs)' %
                          (tic, len(tlds)))

        eic = 0
        for exd in exl:
            try:
                ed = ExcludedDomain.objects.get(domain=exd)
            except ExcludedDomain.DoesNotExit:
                ed = ExcludedDomain()
                ed.domain = exd
                exd.save()
                eic += 1
        self.stdout.write(
            'Excluded domains: Inserted %d row(s) (out of %d listed domains)' %
            (eic, len(exl)))

        sic = 0
        for s in ss:
            if len(s) == 0:
                continue
            vals = s.split('\t')
            key = vals[0]
            value = vals[1]
            valtype = vals[2]
            choices = None
            if len(vals) > 3:
                choices = vals[4]
            try:
                aso = AdminSetting.objects.get(key=key)
            except AdminSetting.DoesNotExist:
                aso = AdminSetting()
                aso.key = key
                aso.value = value
                aso.type = valtype
                aso.choices = choices
                aso.save()
                sic += 1
        self.stdout.write(
            'Admin settings: Inserted %d row(s) (out of %d listed settings)' %
            (sic, len(ss)))
Beispiel #4
0
    def handle(self, *args, **options):
        tld_filename = 'tld_list.txt'
        exclusion_filename = 'exclusion_domains.txt'
        settings_filename = 'clean_admin.txt'

        tldf = open(tld_filename)
        tlds = [line.strip() for line in tldf if line[0] not in '/\n']
        tldf.close()
        exf = open(exclusion_filename)
        exl = [line.strip() for line in exf]
        exf.close()
        sf = open(settings_filename)
        ss = [line.strip() for line in sf]
        sf.close()

        tic = 0
        for tld in tlds:
            try:
                t = TLD.objects.get(domain=tld)
            except TLD.DoesNotExist:
                t = TLD()
                t.domain = tld
                t.is_recognized = False
                t.is_api_registerable = False
                t.description = None
                t.type = ''
                t.save()
                tic += 1
        self.stdout.write('TLDs: Inserted %d row(s) (out of %d TLDs)' % (tic, len(tlds)))

        eic = 0
        for exd in exl:
            try:
                ed = ExcludedDomain.objects.get(domain=exd)
            except ExcludedDomain.DoesNotExit:
                ed = ExcludedDomain()
                ed.domain = exd
                exd.save()
                eic += 1
        self.stdout.write('Excluded domains: Inserted %d row(s) (out of %d listed domains)' % (eic, len(exl)))

        sic = 0
        for s in ss:
            if len(s) == 0:
                continue
            vals = s.split('\t')
            key = vals[0]
            value = vals[1]
            valtype = vals[2]
            choices = None
            if len(vals) > 3:
                choices = vals[4]
            try:
                aso = AdminSetting.objects.get(key=key)
            except AdminSetting.DoesNotExist:
                aso = AdminSetting()
                aso.key = key
                aso.value = value
                aso.type = valtype
                aso.choices = choices
                aso.save()
                sic += 1
        self.stdout.write('Admin settings: Inserted %d row(s) (out of %d listed settings)' % (sic, len(ss)))