generate different, pseudo-random subdomains every week

This commit is contained in:
Connor Olding 2021-08-11 18:50:47 -07:00
parent d2d4917a53
commit 7a1a728a5a

View file

@ -14,17 +14,24 @@ def right_now():
return datetime.now(timezone.utc)
def nonsense_consistent(domain):
def nonsense_consistent(domain, weekly=True):
from datetime import datetime, timezone
from random import Random
from string import ascii_lowercase
from zlib import crc32
rng = Random(crc32(domain.encode("utf-8")))
if weekly:
week = datetime.now(timezone.utc).isocalendar().week
week_bytes = bytes((week, week, week, week))
seed = crc32(week_bytes + domain.encode("utf-8"))
else:
seed = crc32(domain.encode("utf-8"))
rng = Random(seed)
length = rng.choices((9, 10, 11, 12), (4, 5, 3, 2))[0]
return "".join(rng.choice(ascii_lowercase) for i in range(length))
def concat_nonsense(domain):
return nonsense_consistent(domain) + "." + domain
def concat_nonsense(domain, weekly=True):
return nonsense_consistent(domain, weekly=weekly) + "." + domain
def head(n, it):