Bring across my ‘create_username’ script
- ID
5daab81- date
2023-12-20 21:40:09+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
9284eb7- message
Bring across my 'create_username' script- changed files
1 file, 93 additions
Changed files
create_username (0) → create_username (2341)
diff --git a/create_username b/create_username
new file mode 100755
index 0000000..16794f2
--- /dev/null
+++ b/create_username
@@ -0,0 +1,93 @@
+#!/usr/bin/env python3
+"""
+On sites where I don't want to use my standard username (@alexwlchan) --
+for example, if I'm starring content but not creating anything -- I create
+alliterative usernames from the names provided by Docker.
+
+e.g. on GitHub I might use "goofy_galileo"
+
+This script generates an alliterative username for me.
+
+Usage: pass a single letter as first argument, and it offers five suggestions:
+
+ $ ./usernames.py a
+ angry_almeida
+ admiring_ardinghelli
+ admiring_austin
+ amazing_aryabhata
+ admiring_albattani
+
+"""
+
+import os
+import random
+import sys
+import tempfile
+from typing import TypedDict
+
+import httpx
+
+
+def get_name_options() -> tuple[list[str], list[str]]:
+ resp = httpx.get(
+ "https://raw.githubusercontent.com/moby/moby/master/pkg/namesgenerator/names-generator.go"
+ )
+ resp.raise_for_status()
+
+ go_src = resp.text
+
+ # The adjectives are an array of strings:
+ #
+ # var (
+ # left = [...]string{
+ # "admiring",
+ # "adoring",
+ # ...
+ # "zen",
+ # }
+ #
+ adjectives_src = go_src.split("left = [...]string{")[1].split("}")[0]
+
+ # The names are another array of strings, but with comments on names
+ # to explain their significance:
+ #
+ # right = [...]string{
+ # // Muhammad ibn Jābir ...
+ # "albattani",
+ #
+ # ...
+ #
+ # "zhukovsky",
+ # }
+ #
+ names_src = go_src.split("right = [...]string{")[1].split("\n)")[0]
+
+ adjectives = [
+ line.strip('\t",') for line in adjectives_src.splitlines() if line.strip('\t",')
+ ]
+
+ names = [
+ line.strip('\t",}')
+ for line in names_src.splitlines()
+ if not line.strip().startswith("//") and line.strip('\t",}')
+ ]
+
+ return adjectives, names
+
+
+if __name__ == "__main__":
+ try:
+ char = sys.argv[1].lower()
+ except IndexError:
+ sys.exit(f"Usage: {__file__} <CHAR>")
+
+ adjectives, names = get_name_options()
+
+ for _ in range(5):
+ print(
+ "%s_%s"
+ % (
+ random.choice([a for a in adjectives if a.startswith(char)]),
+ random.choice([n for n in names if n.startswith(char)]),
+ )
+ )