-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_username
executable file
·93 lines (74 loc) · 2.29 KB
/
create_username
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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)]),
)
)