-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
68 lines (54 loc) · 1.96 KB
/
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
"""
2018
Louis Lombardo IV
Creation of QR codes from csv documents for:
TIGER CREATIVE, ADMISSIONS
"""
import qrcode
import csv
import sys
def create_qr(data, path, title):
# https://pillow.readthedocs.io/en/3.1.x/reference/Image.html
img = qrcode.make(data)
img.save(path + "/" + title)
def process_csv(csv_location, export_location, start_row=False, end_row=False):
with open(csv_location, 'r') as csvfile:
# Students.CSV
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# | Term_Descrip | PACIFIC_ID | LAST_NAME | FIRST_NAME | STREET_LINE1 | ... | PAC_EMAIL |
# |--------------+------------+-----------+------------+--------------+-----+-----------|
# | Fall 2018 | 9893000000 | Smith | John | N / A | ... | N / A |
# | | |
# | | + > Second part of file name.
# | + > First part of file name.
# + > Data for the QR generator.
# Smith_John.png { 9893000000 }
current_row = -1
csv_reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in csv_reader:
current_row += 1
if start_row or end_row:
if current_row < start_row:
continue
if current_row >= end_row:
break
else:
# Create the QR Code and save to the export location
create_qr(row[1], export_location, row[2] + "_" + row[3] + ".jpeg")
if __name__ == "__main__":
if len(sys.argv) > 2:
print("CSV Location : %s" % sys.argv[1])
print("Export Location : %s" % sys.argv[2])
start_row = False
if len(sys.argv) > 3:
print("Start Row: %s" % sys.argv[3])
start_row = sys.argv[3]
end_row = False
if len(sys.argv) > 4:
print("End Row: %s" % sys.argv[4])
end_row = sys.argv[4]
process_csv(sys.argv[1], sys.argv[2], start_row=start_row, end_row=end_row)
else:
print("Please provide a path to your csv and an export location.")