summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2025-06-15 13:44:16 +0200
committerYuval Adam <_@yuv.al>2025-06-15 13:44:16 +0200
commit2e0755cc68e14bda95abe9472754ae5f4e760a04 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /cli
parentcd812332b9000e58665585e9c3fadc30470a9a6d (diff)
Remove all old files before migration
Diffstat (limited to 'cli')
-rw-r--r--cli/__init__.py16
-rw-r--r--cli/base.py15
-rw-r--r--cli/build.py75
-rw-r--r--cli/clean.py12
-rw-r--r--cli/ghpr.py37
-rw-r--r--cli/model.py15
-rw-r--r--cli/scan.py140
-rw-r--r--cli/serve.py15
8 files changed, 0 insertions, 325 deletions
diff --git a/cli/__init__.py b/cli/__init__.py
deleted file mode 100644
index e7d137f..0000000
--- a/cli/__init__.py
+++ /dev/null
@@ -1,16 +0,0 @@
-import os
-
-from .base import cli
-
-from .build import build
-from .serve import serve
-
-__all__ = [cli, build, serve]
-
-# ugly workaround to avoid build failures in Python 3.8
-if "NETLIFY" not in os.environ:
- from .clean import clean
- from .ghpr import ghpr
- from .scan import scan
-
- __all__ += [clean, ghpr, scan]
diff --git a/cli/base.py b/cli/base.py
deleted file mode 100644
index e76da9d..0000000
--- a/cli/base.py
+++ /dev/null
@@ -1,15 +0,0 @@
-import click
-import ymlstash
-
-from pathlib import Path
-from .model import Name
-
-ROOT_PATH = Path(__file__).parents[1]
-NAMES_DIR = ROOT_PATH / "names"
-
-STASH = ymlstash.YmlStash(Name, NAMES_DIR, filter_none=True)
-
-
-@click.group
-def cli():
- pass
diff --git a/cli/build.py b/cli/build.py
deleted file mode 100644
index 01bc020..0000000
--- a/cli/build.py
+++ /dev/null
@@ -1,75 +0,0 @@
-import click
-
-from jinja2 import Environment, FileSystemLoader, select_autoescape
-from os import listdir, mkdir
-from pathlib import Path
-from shutil import copyfile
-from unidecode import unidecode
-
-from .base import cli, STASH
-
-ROOT_PATH = Path(__file__).parents[1]
-
-NAMES_DIR = ROOT_PATH / "names"
-BUILD_DIR = ROOT_PATH / "build"
-STATIC_DIR = ROOT_PATH / "static"
-
-TEMPLATES = ["index.html"]
-
-
-@cli.command()
-@click.option("--verbose", "-v", is_flag=True)
-def build(verbose):
- # copy static files
- if not BUILD_DIR.exists():
- mkdir(BUILD_DIR)
- for f in listdir(STATIC_DIR):
- copyfile(STATIC_DIR / f, BUILD_DIR / f)
-
- # process all name yamls
- names = []
- candidates = []
-
- for key in STASH.list_keys():
- name = STASH.load(key)
- if name.invalid is True:
- continue
- if name.candidate is True:
- candidates.append(name)
- else:
- names.append(name)
-
- names = list(sorted(names, key=lambda x: x.domain))
- candidates = list(sorted(candidates, key=lambda x: x.domain))
-
- if verbose:
- names_str = [x.domain for x in names]
- candidates_str = [x.domain for x in candidates]
- print(f"Got {names_str=}")
- print(f"Got {candidates_str=}")
-
- def render_link(value, classes):
- name = unidecode(value.name).lower().split(" ")
- domain = unidecode(value.domain).replace(".", "")
- candidate = value.candidate
- rel = ' rel="nofollow"' if candidate else ""
- res = []
- for part in name:
- if part == domain:
- url = value.url or "https://" + value.domain
- res.append(f'<a href="{url}" class="{classes}"{rel}>{value.domain}</a>')
- else:
- res.append(part)
- return " ".join(res)
-
- # render templates
- env = Environment(
- loader=FileSystemLoader("templates"),
- autoescape=select_autoescape(),
- )
- env.filters["render_link"] = render_link
- for template in TEMPLATES:
- t = env.get_template(template)
- index = t.render(names=names, candidates=candidates)
- with open(BUILD_DIR / "index.html", "w") as f:
- f.write(index)
diff --git a/cli/clean.py b/cli/clean.py
deleted file mode 100644
index 0ce061c..0000000
--- a/cli/clean.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from .base import cli, STASH
-
-
-@cli.command()
-def clean():
- names = STASH.list_keys()
- for name in names:
- try:
- obj = STASH.load(name)
- STASH.save(obj)
- except Exception as e:
- print(f"Error {e} when attempting to clean {name=}")
diff --git a/cli/ghpr.py b/cli/ghpr.py
deleted file mode 100644
index 926a338..0000000
--- a/cli/ghpr.py
+++ /dev/null
@@ -1,37 +0,0 @@
-import click
-
-from pathlib import Path
-
-from .base import cli
-
-ROOT_PATH = Path(__file__).parents[1]
-
-
-@cli.command()
-@click.argument("path", type=click.Path())
-def ghpr(path):
- with open(path, "r") as f:
- for line in f:
- domain, handle, name = [x.strip() for x in line.strip().split(",")]
- handle = None if "@" in handle else handle
-
- fn = domain.replace(".", "")
-
- path = ROOT_PATH / "names" / f"{fn}.yml"
- if path.exists():
- print(f"{domain} already exists")
- continue
-
- with open(path, "w") as out:
- s = f"domain: {domain}\nname: {name}\n"
- if handle:
- s += f"github: {handle}\n"
- s += "candidate: true\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/cli/model.py b/cli/model.py
deleted file mode 100644
index 728a9d3..0000000
--- a/cli/model.py
+++ /dev/null
@@ -1,15 +0,0 @@
-from dataclasses import dataclass
-from typing import ClassVar, Optional
-
-
-@dataclass
-class Name:
- domain: str
- name: str
- title: Optional[str] = None
- url: Optional[str] = None
- email: Optional[str] = None
- github: Optional[str] = None
- candidate: Optional[bool] = None
- invalid: Optional[bool] = None
- key: ClassVar[str] = "domain"
diff --git a/cli/scan.py b/cli/scan.py
deleted file mode 100644
index 318e68b..0000000
--- a/cli/scan.py
+++ /dev/null
@@ -1,140 +0,0 @@
-import aiohttp
-import asyncio
-import json
-import requests
-
-from pathlib import Path
-from os import makedirs, listdir
-
-from .base import cli
-
-ROOT_PATH = Path(__file__).parents[1]
-
-DATA_DIR = ROOT_PATH / "data"
-
-TLDS_URL = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
-
-NAMES_ENDPOINT = "https://nameberry.com/nameberry/api/v1/search"
-
-
-class NameScanner:
- def fetch_tlds(self):
- 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)
-
- def fetch_homepage(self, domain):
- print(f"Fetching {domain}...", end="")
- res = requests.get(f"http://{domain}", timeout=5)
- if res.ok:
- print(f"Found {domain}!")
- with open(DATA_DIR / "homepages" / f"{domain}.html", "w") as f:
- f.write(res.text)
- else:
- print("x")
-
- def fetch_names(self, suffix, count=5000):
- res = requests.post(
- NAMES_ENDPOINT,
- json={
- "starts_with": "",
- "ends_with": suffix,
- "contains": "",
- "syllables": "",
- "origin_id": "",
- "derivation": "",
- "page": 1,
- "per_page": count,
- },
- )
- if res.ok:
- j = res.json()
- print(f"found {j['advanced_name_count']}")
- makedirs(DATA_DIR / "names", exist_ok=True)
- with open(DATA_DIR / "names" / f"{suffix}.json", "w") as f:
- f.write(res.text)
-
- def fetch_all(self):
- with open(DATA_DIR / "tlds.txt", "r") as f:
- for line in f:
- d = line.strip()
- print(f"Fetching {d}...", end="")
- self.fetch_names(d)
-
- def consolidate_names(self):
- res = set()
- for fn in listdir(DATA_DIR / "names"):
- with open(DATA_DIR / "names" / fn, "r") as f:
- j = json.load(f)
- names = j["advanced"]
- if names:
- suffix = fn.split(".")[0]
- for name in names:
- n = name["name"].lower().split(suffix)[0]
- if n:
- res.add(n)
- with open(DATA_DIR / "allnames.txt", "w") as out:
- for n in res:
- out.write(n + f".{suffix}\n")
-
- async def get_homepage(self, session, domain):
- try:
- url = f"http://{domain}"
- async with session.get(url) as res:
- res = await res.text()
- if res:
- print(f"Got {len(res)} bytes from {domain}")
- with open(DATA_DIR / "homepages" / f"{domain}.html", "w") as out:
- out.write(res)
- return len(res)
- except Exception:
- return 0
-
- async def fetch_homepages(self, N):
- with open(DATA_DIR / "allnames.txt", "r") as f:
- names = [x.strip() for x in f.readlines()][N * 1000 : 1000 * (N + 1)]
-
- timeout = aiohttp.ClientTimeout(total=30)
- async with aiohttp.ClientSession(timeout=timeout) as session:
- tasks = []
- for name in names:
- tasks.append(asyncio.ensure_future(self.get_homepage(session, name)))
-
- _resps = await asyncio.gather(*tasks)
-
- def find_homepages(self):
- res = {}
- for fn in listdir(DATA_DIR / "homepages"):
- with open(DATA_DIR / "homepages" / fn, "r") as f:
- domain = fn[:-5]
- name = domain.replace(".", "")
- text = f.read()
- nip = name in text
- github = "github" in text
- li = "linkedin" in text
- sale = "for sale" in text or "register" in text or "parking" in text
- res["domain"] = {
- "name": name,
- "name_in_page": nip,
- "github": github,
- "linkedin": li,
- }
- ge = "✅" if github else " "
- le = "✅" if li else " "
- ne = "✅" if nip else " "
- se = "❌" if sale else " "
- print(f"{ne}{ge}{le}{se}{name:20}")
-
-
-@cli.command()
-def scan():
- ns = NameScanner()
- # for i in range(0, 26):
- # asyncio.run(ns.fetch_homepages(i))
- # ns.consolidate_names()
- ns.find_homepages()
diff --git a/cli/serve.py b/cli/serve.py
deleted file mode 100644
index 9910294..0000000
--- a/cli/serve.py
+++ /dev/null
@@ -1,15 +0,0 @@
-from http.server import HTTPServer, SimpleHTTPRequestHandler
-
-from .base import cli
-
-
-@cli.command()
-def serve():
- class BuildHTTPRequestHandler(SimpleHTTPRequestHandler):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, directory="build", **kwargs)
-
- print("Local server running on http://localhost:8000")
- server_address = ("", 8000)
- httpd = HTTPServer(server_address, BuildHTTPRequestHandler)
- httpd.serve_forever()