-
Notifications
You must be signed in to change notification settings - Fork 2
/
ticket_generator.py
123 lines (107 loc) · 3.75 KB
/
ticket_generator.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import requests
import qrcode
import random
import csv
import os
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
def get_column(file, word):
with open(file) as csvfile:
reader = csv.reader(csvfile)
for row in reader:
for k,v in enumerate(row):
if v.lower() == word.lower():
return k+1
page_num = 0
cont = ""
while True:
# Get eventbrite token
token = open('token.txt', 'r').read()
event_id = "80301061637" # Extracted from event url
page_num += 1
req = "https://www.eventbriteapi.com/v3/events/%s/attendees" % event_id
if(page_num > 1):
req += "?continuation=" + cont
response = requests.get(
req,
headers = {
"Authorization": "Bearer " + token,
},
verify = True, # Verify SSL certificate
)
attendees = response.json()['attendees']
if(page_num < 7):
cont = response.json()['pagination']['continuation']
for i, attendee in enumerate(attendees):
# for i in range(1):
# TICKET TEMPLATE
mod = 6 - i%6
ticket_template = Image.open("templates/%s.png" % str(mod))
#colour
r, g, b = (0,0,0)
qr_colour = '#'
if mod == 1 or mod == 2:
r, g, b = (91,150,153)
qr_colour = '#3F696B'
elif mod == 3 or mod == 4:
r, g, b = (198,161,139)
qr_colour = '#8A7061'
else:
r, g, b = (126,107,132)
qr_colour = '#645569'
# QR CODE GENERATION
order_id = attendee['order_id']
checked_in = attendee['checked_in']
name = attendee['profile']['name'].upper()
student_id = attendee['profile']['email'][0:9]
seq_num = "{0:0=3d}".format(i + 1)
file_name = ("%s_%s" % (attendee['profile']['first_name'], attendee['profile']['last_name'])).upper()
qr = qrcode.QRCode(
version = 2,
error_correction = qrcode.constants.ERROR_CORRECT_H,
box_size = 20, # Adjust size for output onto image
border = 0,
)
table_number = str(get_column("tables.csv", student_id))
qr_data = attendee['barcodes'][0]['barcode']
qr.add_data(qr_data)
qr.make(fit=True)
qr_img = qr.make_image(fill_color=qr_colour)
qr_img = qr_img.resize((310,310))
# logo = Image.open("logo.png")
# logo = logo.resize((100, 100))
# qr_img.paste(logo, (105, 105),mask=logo)
ticket_template.paste(qr_img, (345, 1444))
ticket = ImageDraw.Draw(ticket_template)
#fonts
id_font = ImageFont.truetype("Oswald-regular.ttf", 52)
name_font = ImageFont.truetype("Oswald-regular.ttf", 57)
table_font = ImageFont.truetype("Oswald-bold.ttf", 63)
nick_marshall_font = ImageFont.truetype("Oswald-regular.ttf",46)
#name
if name == 'NICOLAS BRIAN THOMAS MARSHALL':
w,h = ticket.textsize('NICOLAS BRIAN THOMAS MARSHALL', nick_marshall_font)
offset = nick_marshall_font.getoffset('NICOLAS BRIAN THOMAS MARSHALL')
ticket.text(((1000-w)/2-3,66-offset[1]), 'NICOLAS BRIAN THOMAS MARSHALL', (r,g,b), font=nick_marshall_font)
else:
w,h = ticket.textsize(name, name_font)
offset = name_font.getoffset(name)
ticket.text(((1000-w)/2-3,66-offset[1]), name, (r,g,b), font=name_font, align ="centre")
#student id
if name == 'Janice Au Yeung'.upper() or name == 'Erik Morales'.upper() or name == 'Franklin Zhang'.upper():
student_id = 'GUEST'
w, h= ticket.textsize(student_id, id_font)
ticket.text(((1000-w)/2,1927-h), student_id, (0,0,0), font=id_font)
#student id
w, h= ticket.textsize('TABLE ' + table_number, table_font)
x = (1000-w)/2+ticket.textsize('TABLE ', table_font)[0]
ticket.text(((1000-w)/2,1802-h+49), 'TABLE '+table_number, (0,0,0), font=table_font)
ticket.text((x,1802-h+49), table_number, (r,g,b), font=table_font)
if os.path.isfile("tickets/%s.png" % file_name.lower()):
ticket_template.save("tickets/%s1.png" % file_name.lower())
else:
ticket_template.save("tickets/%s.png" % file_name.lower())
if(page_num == 7):
break
print('all done!')