Page MenuHomeSoftware Heritage
Paste P691

random-swhid
ActivePublic

Authored by zack on Jun 9 2020, 10:31 AM.
#!/usr/bin/env python3
"""Generate a feed of random (hence bogus, but syntactically correct!) SWHIDs
"""
__copyright__ = "Copyright (C) 2020 Stefano Zacchiroli"
__license__ = "GPL-3.0-or-later"
import random
HEX_DIGITS = "0123456789abcdef"
SWHID_HEX_LEN = 40
SWHID_PREFIX = "swh"
SWHID_SEP = ":"
SWHID_TYPES = ["cnt", "dir", "rev", "rel", "snp"]
SWHID_VERSION = "1"
def random_swhid() -> str:
return SWHID_SEP.join(
[
SWHID_PREFIX,
SWHID_VERSION,
random.choice(SWHID_TYPES),
"".join(random.choices(HEX_DIGITS, k=SWHID_HEX_LEN)),
]
)
def main():
try:
while True:
print(random_swhid())
except (BrokenPipeError, KeyboardInterrupt):
pass
if __name__ == "__main__":
main()

Event Timeline

zack changed the title of this paste from untitled to random-swhid.