How to use normalize_hostname method in autotest

Best Python code snippet using autotest_python

test-1.py

Source:test-1.py Github

copy

Full Screen

...76 # otr_filter_func = None77 source.make_fingerprints(with_filter=src_filter_func)78 other.make_fingerprints(with_filter=otr_filter_func)79 # def tr_hostname(val):80 # return normalize_hostname(val).replace('/', '-')81 source.make_keys("hostname", with_translate=normalize_hostname)82 other.make_keys("hostname", with_translate=normalize_hostname)83 source.make_keys("sn")84 other.make_keys("sn")85 def sn_cmp(val):86 return val if not val.endswith("_1") else val.partition("_1")[0]87 comparitors = {88 "sn": sn_cmp,89 # "model": str.upper,90 # "os_name": lambda f: f.replace("-", ""),91 }92 missing, changes = diff.diff(source, other, fields_cmp=comparitors)93 missing_sn = [94 (fp, change) for fp, change in changes if "sn" in change and fp["sn"] == ""...

Full Screen

Full Screen

domain-limit-list.py

Source:domain-limit-list.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import datetime3import time4from datetime import timezone5import pytz6import whois7import yaml8from jinja2 import Environment, FileSystemLoader9from publicsuffix import PublicSuffixList10# whois参照11def get_whois(host):12 time.sleep(2)13 return whois.whois(host)14# YamlをOpen15f = open("./chk_hosts.yml",encoding='utf-8')16chk_hosts = yaml.load(f)17chk_hosts = chk_hosts['chk_host_list']18#print (chk_hosts)19domain_list = []20# サブドメインや日本語ドメインを正規化する21for chk in chk_hosts:22 hostname = chk['uri']23 if hostname is None:24 next25 normalize_hostname = hostname.encode('idna').decode('utf-8')26 psl = PublicSuffixList()27 domain_list.append(psl.get_public_suffix(normalize_hostname))28#print (domain_list)29uniq_domain_list = list(set(domain_list))30list = []31# 重複を除去し、Whoisを引く32for domain in uniq_domain_list:33 registrar = " "34 update_date = " "35 expires_date = " "36 limit_day = " "37 try:38 whois_ans = get_whois(domain)39 registrar = whois_ans.registrar40 # print(domain)41 # print(whois_ans)42 # print(type(whois_ans.updated_date))43 if isinstance(whois_ans.updated_date, type(list)):44 whois_update_date = whois_ans.updated_date[0]45 else:46 whois_update_date = whois_ans.updated_date47 if isinstance(whois_ans.expiration_date, type(list)):48 whois_expiration_date = whois_ans.expiration_date[0]49 else:50 whois_expiration_date = whois_ans.expiration_date51 except whois.parser.PywhoisError as e:52 print("Whoisに見つからない")53 continue54 print(domain)55 # print(whois_ans)56 if whois_update_date is None:57 print("Whois情報取得に失敗")58 continue59 # そのまま処理するとJSTと認識されて時刻がずれるので、不細工だけど時間をずらす60 update_date = whois_update_date - datetime.timedelta(hours=9)61 expires_date = whois_expiration_date - datetime.timedelta(hours=9)62 jp = pytz.timezone('Asia/Tokyo')63 # print(update_date.astimezone(jp))64 diff = (expires_date.astimezone(jp) - datetime.datetime.now(jp)65 ) // datetime.timedelta(days=1)66 # print(update_date)67 # print(expires_date)68 # print(diff)69 whois_propaty = {"domain": domain, "registrar": registrar,70 "update_date": update_date, "expires_date": expires_date, "limit_day": diff}71 list.append(whois_propaty)72# 残り日数とホスト名でソート73list = sorted(list, key=lambda x: (x["limit_day"], x["domain"]))74# HTML作成75env = Environment(loader=FileSystemLoader('./', encoding='utf8'))76templete = env.get_template('./domain_limit.html.j2')77data = {"list": list}78output = templete.render(data)79# Windows環境だとエンコード指定しないと出力がSJISになる。80with open('domain_limit.html', 'w', encoding='utf-8') as f:81 f.write(output)...

Full Screen

Full Screen

normalize_hostname.py

Source:normalize_hostname.py Github

copy

Full Screen

...37 any_domain = "|".join(38 map(re.escape, map(partial(concat, "."), cfg_obj.domain_names))39 )40 return partial(re.compile(any_domain).sub, repl="")41def normalize_hostname(hostname):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful