From 19928dde097a131fbcc2b73f7ba1142c6e6ee7cc Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 14 Nov 2022 23:03:38 +0200 Subject: Unify scripts/ directory (#52) * Unify scripts/ directory * Keep build.py in root for simplicity --- scripts/ghpr.py | 25 +++++++++++++++++++++++++ scripts/scan.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 scripts/ghpr.py create mode 100644 scripts/scan.py (limited to 'scripts') diff --git a/scripts/ghpr.py b/scripts/ghpr.py new file mode 100644 index 0000000..4e9a124 --- /dev/null +++ b/scripts/ghpr.py @@ -0,0 +1,25 @@ +import sys + +from pathlib import Path +from subprocess import run + +ROOT_PATH = Path(__file__).parent + +path = sys.argv[1] + +with open(path, "r") as f: + for line in f: + l = line.strip().split(",") + domain, handle, name = [x.strip() for x in l] + + fn = domain.replace(".", "") + with open(ROOT_PATH / "names" / f"{fn}.yml", "w") as out: + s = f"domain: {domain}\nname: {name}\ngithub: {handle}\n" + out.write(s) + + run(["git", "checkout", "-b", domain]) + run(["git", "add", f"names/{fn}.yml"]) + run(["git", "commit", "-m", f"Add {domain}"]) + run(["git", "push", "-u", "origin", domain]) + run(["gh", "pr", "create", "-t", f"Add {domain}", "-b", f"Hey @{handle}, would you like to merge this PR adding you to https://namehack.club?"]) + run(["git", "checkout", "main"]) diff --git a/scripts/scan.py b/scripts/scan.py new file mode 100644 index 0000000..cf367f4 --- /dev/null +++ b/scripts/scan.py @@ -0,0 +1,57 @@ +import requests + +from pathlib import Path + +ROOT_PATH = Path(__file__).parent + +DATA_DIR = ROOT_PATH / "data" + +TLDS_URL = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt" +MALE_NAMES_URL = "https://raw.githubusercontent.com/DictionaryHouse/EnglishName/master/top_1000_EN_%E7%94%B7%E6%80%A7names_english.txt" +FEMALE_NAMES_URL = "https://raw.githubusercontent.com/DictionaryHouse/EnglishName/master/top_1000_EN_%E5%A5%B3%E6%80%A7names_english.txt" + +with open(DATA_DIR / "tlds.txt", "w") as f: + print("Fetching TLDs...") + res = requests.get(TLDS_URL) + tlds = [tld.lower() for tld in res.text.strip().split("\n")[1:] if len(tld) < 4] + f.write("\n".join(tlds).strip()) + TLDS = set(tlds) + +NAMES = [] + +with open(DATA_DIR / "names.txt", "w") as f: + print("Fetching female names...") + res = requests.get(FEMALE_NAMES_URL) + f.write(res.text) + NAMES += res.text.split("\n") + print("Fetching male names...") + res = requests.get(MALE_NAMES_URL) + f.write(res.text) + NAMES += res.text.split("\n") + +# print(NAMES) +# print(TLDS) + +CANDIDATES = [] + +for name in NAMES: + if name[-2:] in TLDS: + CANDIDATES.append(f"{name[:-2]}.{name[-2:]}") + if name[-3:] in TLDS: + CANDIDATES.append(f"{name[:-3]}.{name[-3:]}") + +with open(DATA_DIR / "domains.txt", "w") as f: + f.write("\n".join(CANDIDATES).strip()) + +for c in CANDIDATES: + try: + print(f"Fetching {c}...", end="") + res = requests.get(f"http://{c}", timeout=5) + if res.ok: + print(f"Found {c}!") + with open(DATA_DIR / "homepages" / f"{c}.html", "w") as f: + f.write(res.text) + else: + print("x") + except: + print("x") \ No newline at end of file -- cgit v1.3.1