forked from vine-stone/HVZ-Feed-Card-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRfeedcards.py
104 lines (84 loc) · 3.81 KB
/
QRfeedcards.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
"""
Author: Liana Piedra
Edits: Jackson Warley
Created: March 2015
A program that generates feed cards for Claremont HVZ
with a feed code and its corresponding feeding URL.
This is a python2 program. If you get nameerrors it's because
you're running it as a python3 program. Stop doing that.
If you don't have it already, you need to install the python
package manager, pip, in order to install the following dependencies.
Then just run "pip install pyqrcode" and "pip install XlsxWriter" as
root in order to install them.
For pyqrcode: https://pypi.python.org/pypi/PyQRCode
Necessary to create the neat QR code image.
For xlsxwriter: http://xlsxwriter.readthedocs.io/contents.html
This website was a huge source, literally the coolest thing ever.
Does practically anything you would want to do in an Excel sheet.
"""
import pyqrcode
import xlsxwriter
import random
import string
charSet = 'ACELNOPSTWXZ' # currently accepted letters for QR code
numCodes = int(raw_input("How many feed cards would you like to create? [Integer] "))
semester = str.capitalize(raw_input("What semester, Fall [F] or Spring [S]? "))
year = raw_input("What year? [Last two digits] ")
# Create a new Excel file and add a worksheet
workbook = xlsxwriter.Workbook('FeedCardSheets.xlsx')
worksheet = workbook.add_worksheet()
# These measurements are very specific to the paper being used,
# and will accomodate 2" x 3.5" perforated cards.
worksheet.set_margins(left=.75,right=.75,top=.5,bottom=.5)
worksheet.set_column('A:A', 31.3)
worksheet.set_column('B:B', 12.0)
worksheet.set_column('C:C', 43.3)
# Counter variables
rows = 0
cards = 1
fileNum = 1
# This giant loop will create the necessary formatting for each card
for number in range(1, numCodes+1):
# Create QR code images specific to each feed code
num = str(number)
feed = ''.join(random.choice(charSet) for i in range(5)) #range is how long the feed code is
url = pyqrcode.create('http://www.claremonthvz.org/login/?next=/eat/'+feed,
error='L', version=5, mode='binary')
url.png('hvz'+num+'.png', scale=8) # I suggest not changing the version or scale numbers
# Set rows and columns to specific sizes for the paper
worksheet.set_row(rows, 68) #row for name and QR code
worksheet.set_row(rows+1, 80) #row for feed code
rows += 2
# Setup for image insertion
num = str(cards)
num2 = str(cards+1)
# Format the name and QR image boxes of the card
name_format = workbook.add_format({'align':'left', 'valign':'top', 'italic': True,
'bold': True, 'size':10, 'font':'Rockwell', 'border':1})
nameCell = 'A'+num
qrCell = 'B'+num
worksheet.write(nameCell, ' Name:', name_format) # the space in front is for alignment
worksheet.write(qrCell, '', name_format)
# These values are really finicky. The ones in the original code never worked for me so
# I figured these out by trial and error. This might just work for my system though so
# try changing them if things aren't lining up for you. -Jackson
worksheet.insert_image(qrCell, 'hvz'+str(fileNum)+'.png', {'x_offset': 6,
'y_offset': 5, 'x_scale': 0.23, 'y_scale': 0.23})
# Insert each HVZ logo image
logoCell = 'C'+num
worksheet.insert_image(logoCell, 'HVZlogo.png', {'x_scale': 0.29,
'y_scale': 0.29, 'x_offset': 24, 'y_offset':15})
# Merge the cells where the feed code goes
mergeCell = 'A'+num2+':B'+num2
code_format = workbook.add_format({'align':'center', 'valign':'vcenter',
'size':55, 'font':'Rockwell', 'bold': True, 'border':1})
worksheet.merge_range(mergeCell, feed, code_format)
#Merge the cells where the logo goes
logoMerge = 'C'+num+':C'+num2
info_format = workbook.add_format({'align':'center', 'valign':'bottom',
'size':11.5, 'font':'Rockwell', 'bold': True, 'border':1})
worksheet.merge_range(logoMerge, "claremonthvz.org "+semester+" '"+year
+" (909) 525-4551", info_format)
cards += 2
fileNum += 1
workbook.close()