Compare commits

..

8 Commits

6 changed files with 148 additions and 15 deletions

View File

@@ -48,3 +48,4 @@ hohe
geniale
sanfte
vokale
bunte

View File

@@ -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,17 +54,26 @@ 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
logo = svg2rlg("img/karaoke-outline.svg")
logo = svg2rlg("img/karaoke-2-outline.svg")
scaling_factor = ticket_height/logo.height/2
logo.scale(scaling_factor, scaling_factor)
logo_width = logo.width*scaling_factor
@@ -71,9 +89,30 @@ if __name__ == "__main__":
generated_codes = 0
for page in range(required_pages):
# Add crop marks in the margin area
if args.margin > 4:
pdf.setLineWidth(0.5)
for row in range(codes_per_row):
x = args.margin+row*(ticket_width+args.gap)
pdf.line(x1=x, y1=1, x2=x, y2=args.margin-3)
pdf.line(x1=x, y1=page_height-1, x2=x, y2=page_height-args.margin+3)
if args.gap > 0 or row == codes_per_row-1:
pdf.line(x1=x+ticket_width, y1=1, x2=x+ticket_width, y2=args.margin-3)
pdf.line(x1=x+ticket_width, y1=page_height-1, x2=x+ticket_width, y2=page_height-args.margin+3)
for col in range(codes_per_col):
y = args.margin+col*(ticket_height+args.gap/1.2)
pdf.line(x1=1, y1=y, x2=args.margin-3, y2=y)
pdf.line(x1=page_width-1, y1=y, x2=page_width-args.margin+3, y2=y)
if args.gap > 0 or col == codes_per_col-1:
pdf.line(x1=1, y1=y+ticket_height, x2=args.margin-3, y2=y+ticket_height)
pdf.line(x1=page_width-1, y1=y+ticket_height, x2=page_width-args.margin+3, y2=y+ticket_height)
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()
@@ -83,17 +122,24 @@ if __name__ == "__main__":
current_x = args.margin+(ticket_width+args.gap)*x
current_y = args.margin+(ticket_height+args.gap/1.2)*y
# Print outline around ticket for debugging
# pdf.setLineWidth(0.01)
# pdf.rect(current_x, current_y, ticket_width, ticket_height)
renderPDF.draw(logo, pdf, current_x, current_y+ticket_height*0.40)
drawing = Drawing(ticket_height, ticket_height, transform=[qr_code_size/code_width, 0, 0, qr_code_size/code_height, 0, 0])
drawing.add(qr_code)
renderPDF.draw(logo, pdf, current_x, current_y+35)
renderPDF.draw(drawing, pdf, current_x+logo_width, current_y+ticket_height*0.15)
pdf.setFont("Helvetica", 12)
pdf.drawRightString(current_x+logo_width, current_y+16, "Hier anmelden →")
font_scale = ticket_height/100
pdf.setFont("Helvetica", 8)
pdf.drawRightString(current_x+logo_width+qr_code_size-7, current_y, url)
pdf.setFont("Helvetica", 12*font_scale)
pdf.drawRightString(current_x+logo_width, current_y+ticket_height*0.25, "Hier anmelden →")
pdf.setFont("Helvetica", 8*font_scale)
pdf.drawRightString(current_x+logo_width+qr_code_size-7*font_scale, current_y+ticket_height*0.10, url)
renderPDF.draw(drawing, pdf, current_x+logo_width, current_y+5)
generated_codes += 1
if generated_codes >= args.number:
pdf.save()

41
img/karaoke-2-outline.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -38,3 +38,4 @@ Bonsai
Berg
Blitz
Garten
Luftballon

41
nomen-neutrum.txt Normal file
View File

@@ -0,0 +1,41 @@
Mikrofon
Klavier
Auge
Wort
Auto
Fahrrad
Ohr
Lama
Brot
Feuerwerk
Huhn
Boot
Cello
Schlagzeug
Herz
Geheimnis
Pferd
Geraet
Konzert
Bier
Schiff
Keyboard
Krokodil
Schaf
Wetter
Klima
Radio
Programm
Buch
Flugzeug
Spiel
Hobby
Leben
Experiment
Gesetz
Dorf
Spielzeug
Geschenk
Signal
Stroh
Gewitter

View File

@@ -39,3 +39,6 @@ Waffel
Limonade
Zeit
Tomate
Erbse
Rakete
Pause