|
|
|
@@ -12,11 +12,18 @@ from reportlab.graphics import renderPDF
|
|
|
|
|
from svglib.svglib import svg2rlg
|
|
|
|
|
from urllib.parse import urljoin
|
|
|
|
|
|
|
|
|
|
def generate_random_username(female_nouns, male_nouns, adjectives, used_usernames):
|
|
|
|
|
def generate_random_username(female_nouns, male_nouns, neuter_nouns, adjectives, used_usernames):
|
|
|
|
|
random_username = None
|
|
|
|
|
while True:
|
|
|
|
|
nouns = choice([female_nouns, male_nouns])
|
|
|
|
|
random_username = f"{adjectives[randrange(len(adjectives)-1)]}{'' if nouns is female_nouns else 'r'}-{nouns[randrange(len(nouns)-1)].lower()}"
|
|
|
|
|
nouns = choice([female_nouns, male_nouns, neuter_nouns])
|
|
|
|
|
|
|
|
|
|
adjektive_suffix = ""
|
|
|
|
|
if nouns is male_nouns:
|
|
|
|
|
adjektive_suffix = "r"
|
|
|
|
|
elif nouns is neuter_nouns:
|
|
|
|
|
adjektive_suffix = "s"
|
|
|
|
|
|
|
|
|
|
random_username = f"{adjectives[randrange(len(adjectives))]}{adjektive_suffix}-{nouns[randrange(len(nouns))].lower()}"
|
|
|
|
|
if random_username not in used_usernames:
|
|
|
|
|
used_usernames.add(random_username)
|
|
|
|
|
print(random_username)
|
|
|
|
@@ -30,12 +37,14 @@ if __name__ == "__main__":
|
|
|
|
|
parser.add_argument("-s", "--size", type=int, help="Ticket height, defaults to 150.", default=150)
|
|
|
|
|
parser.add_argument("-m", "--margin", type=int, help="Margin (depends on printer), defaults to 0.", default=0)
|
|
|
|
|
parser.add_argument("-g", "--gap", type=int, help="Gap between tickets, defaults to 0.", default=0)
|
|
|
|
|
parser.add_argument("--exclude-usernames-from", action="append", help="File with usernames that should not be used.", default=[])
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
adjectives = set()
|
|
|
|
|
female_nouns = set()
|
|
|
|
|
male_nouns = set()
|
|
|
|
|
neuter_nouns = set()
|
|
|
|
|
with open('adjektive-weiblich.txt', 'r') as file:
|
|
|
|
|
for line in file:
|
|
|
|
|
adjectives.add(line.strip())
|
|
|
|
@@ -45,13 +54,22 @@ if __name__ == "__main__":
|
|
|
|
|
with open('nomen-maennlich.txt', 'r') as file:
|
|
|
|
|
for line in file:
|
|
|
|
|
male_nouns.add(line.strip())
|
|
|
|
|
with open('nomen-neutrum.txt', 'r') as file:
|
|
|
|
|
for line in file:
|
|
|
|
|
neuter_nouns.add(line.strip())
|
|
|
|
|
adjectives = list(adjectives)
|
|
|
|
|
female_nouns = list(female_nouns)
|
|
|
|
|
male_nouns = list(male_nouns)
|
|
|
|
|
neuter_nouns = list(neuter_nouns)
|
|
|
|
|
|
|
|
|
|
pdf = canvas.Canvas(args.output, pagesize=A4)
|
|
|
|
|
page_width, page_height = A4
|
|
|
|
|
|
|
|
|
|
used_usernames = set()
|
|
|
|
|
for exclude_usernames_file in args.exclude_usernames_from:
|
|
|
|
|
with open(exclude_usernames_file, 'r') as file:
|
|
|
|
|
for line in file:
|
|
|
|
|
used_usernames.add(line.strip())
|
|
|
|
|
|
|
|
|
|
ticket_height = args.size
|
|
|
|
|
qr_code_size = ticket_height/1.5
|
|
|
|
@@ -73,7 +91,7 @@ if __name__ == "__main__":
|
|
|
|
|
for page in range(required_pages):
|
|
|
|
|
# Add crop marks in the margin area
|
|
|
|
|
if args.margin > 4:
|
|
|
|
|
pdf.setLineWidth(0.01)
|
|
|
|
|
pdf.setLineWidth(0.5)
|
|
|
|
|
|
|
|
|
|
for row in range(codes_per_row):
|
|
|
|
|
x = args.margin+row*(ticket_width+args.gap)
|
|
|
|
@@ -94,7 +112,7 @@ if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
for y in range(codes_per_col):
|
|
|
|
|
for x in range(codes_per_row):
|
|
|
|
|
url = urljoin(args.url, generate_random_username(female_nouns, male_nouns, adjectives, used_usernames))
|
|
|
|
|
url = urljoin(args.url, generate_random_username(female_nouns, male_nouns, neuter_nouns, adjectives, used_usernames))
|
|
|
|
|
qr_code = QrCodeWidget(url)
|
|
|
|
|
bounds = qr_code.getBounds()
|
|
|
|
|
|
|
|
|
|