Skip to content

Commit

Permalink
#29 Using tldextract package to detect and remove subdomain part if n…
Browse files Browse the repository at this point in the history
…ecessary
  • Loading branch information
Danamir committed Jan 3, 2022
1 parent 5ead1b2 commit d23a2c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions dyn_gandi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import json
import os
import sys
import re
from configparser import ConfigParser
from datetime import datetime

import docopt as docpt
import tldextract
from docopt import docopt
from ip_resolver import IpResolver, IpResolverError

Expand Down Expand Up @@ -189,12 +189,12 @@ def main():
domain = config['dns']['domain'] # type: str

# Sub-domain check
domain = domain.replace(".co.uk", ".co_uk")
if re.match(r"^.+\.[^.]+\.[^.]+$", domain):
domain_ext = tldextract.extract(domain)
if domain_ext.subdomain:
if verbose:
print("Warning: removing sub-domain part of %s" % domain)
domain = re.sub(r"^.+\.([^.]+\.[^.]+)$", r"\g<1>", domain)
domain = domain.replace(".co_uk", ".co.uk")

domain = f'{domain_ext.domain}.{domain_ext.suffix}'

if verbose:
print("Domain: %s" % domain)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from setuptools import setup, find_packages

requires = [
'tldextract',
'docopt',
'requests',
]
Expand Down

0 comments on commit d23a2c6

Please sign in to comment.