Last active
August 29, 2015 14:14
-
-
Save bencrowder/2fc22baa4f6e744c9440 to your computer and use it in GitHub Desktop.
Home teaching slips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updated_date: "Feb 2015" | |
districts: | |
- david-smith | |
- william-adams | |
- robert-taylor | |
people: | |
- "David | Smith | Elizabeth | 435-131-1414 | 1000 S 1000 E" | |
- "William | Adams | Sarah | 435-272-2923 | 920 S 700 E" | |
- "Robert | Taylor | Emmeline | 435-717-1612 | 900 S 1000 E" | |
- "Adam | Quincy | Rebecca | 208-991-3191 | 987 S 910 E" | |
- "Harrison | Crewes | Abigail | 435-101-7311 | 1001 S 810 E" | |
- "Glade | Doxy | Whitney | 435-308-1934 | 818 S 1000 E" | |
- "Mario | Cinelli | Maria | 212-373-4214 | 829 S 1000 E" | |
- "Pierre | Wixom | Jessica | 801-229-0701 | 913 S 930 E" | |
- "Stephen | Potter | Mandy | 435-819-1221 | 785 S 910 E" | |
- "Tom | Calamari | Isla | 435-277-4431 | 885 S 1100 E" | |
- "Boyd | Riddle | Rachel | 435-491-8191 | 903 S 1100 E" | |
companionships: | |
- "1 | david-smith, harrison-crewes | pierre-wixom, tom-calamari" | |
- "2 | william-adams, mario-cinelli | harrison-crewes, robert-taylor, stephen-potter" | |
- "2 | adam-quincy, glade-doxy | william-adams, mario-cinelli, boyd-riddle" | |
- "3 | robert-taylor, pierre-wixom, stephen-potter | david-smith, adam-quincy" | |
- "3 | tom-calamari, boyd-riddle | glade-doxy, mario-cinelli" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
page_width = 612 | |
page_height = 792 | |
margin = 36 | |
gap = 35 | |
size(612, 792) | |
background(1) | |
class HomeTeaching: | |
updated_date = '' | |
districts = [] | |
people = {} | |
companionships = [] | |
def __init__(self, data): | |
self.updated_date = data['updated_date'] | |
self.districts = data['districts'] | |
self.people = self.parse_people_list(data['people']) | |
self.companionships = self.parse_companionship_list(data['companionships']) | |
def parse_people_list(self, people): | |
people_list = {} | |
for p in people: | |
data = p.split("|") | |
person_key = "{}-{}".format(data[0].lower().strip(), data[1].lower().strip()) | |
people_list[person_key] = { | |
"first_name": data[0].strip(), | |
"last_name": data[1].strip(), | |
"name": "{} {}".format(data[0].strip(), data[1].strip()), | |
"reversed_name": "{}, {}".format(data[1].strip(), data[0].strip()), | |
"wife": data[2].strip(), | |
"phone": data[3].strip(), | |
"address": data[4].strip(), | |
} | |
return people_list | |
def key_comp(self, companionship, key_comp): | |
new_list = [] | |
# If it's already there, do nothing | |
if companionship[0] == key_comp: | |
for x in companionship: | |
new_list.append(x) | |
return new_list | |
new_list.append(key_comp) | |
for x in companionship: | |
if x != key_comp: | |
new_list.append(x) | |
return new_list | |
def parse_companionship_list(self, companionships): | |
companionship_list = [] | |
for c in companionships: | |
data = c.split("|") | |
district = int(data[0].strip()) | |
companionship = [x.strip() for x in data[1].split(",")] | |
families = [x.strip() for x in data[2].split(",")] | |
comp = [] | |
for x in companionship: | |
comp = self.key_comp(companionship, x) | |
new_comp = { | |
"district": district, | |
"companionship": comp, | |
"families": families, | |
} | |
companionship_list.append(new_comp) | |
return companionship_list | |
def draw_companionship(c, x, y, width): | |
push() | |
translate(x, y) | |
start_y = 0 | |
dl = ht.people[ht.districts[int(c['district']) - 1]] | |
# Heading | |
font("Helvetica", size=7, italic=True) | |
text("District {} • Leader: {} ({}) • Updated {}".format( | |
c['district'], | |
dl['name'], | |
dl['phone'], | |
ht.updated_date), | |
0, start_y | |
) | |
start_y += 4 | |
stroke(0.25) | |
line(0, start_y, width, start_y) | |
# Companions | |
start_y += 15 | |
font(italic=False, weight="bold") | |
for p_id in c['companionship']: | |
p = ht.people[p_id] | |
font(size=10) | |
text(p['reversed_name'], 0, start_y) | |
font(size=8, weight="regular") | |
text(p['phone'], width * 0.54, start_y) | |
text(p['address'], width * 0.78, start_y) | |
start_y += 14 | |
font(size=7) | |
start_y += 5 | |
text("FAMILIES", 0, start_y) | |
start_y += 13 | |
for f_id in c['families']: | |
f = ht.people[f_id] | |
font(size=9) | |
fam_name = f['reversed_name'] | |
if f['wife']: | |
fam_name += " & {}".format(f['wife']) | |
text(fam_name, 0, start_y) | |
font(size=8, weight="regular") | |
text(f['phone'], width * 0.54, start_y) | |
text(f['address'], width * 0.78, start_y) | |
start_y += 13 | |
pop() | |
return start_y | |
# Load the data | |
with open('data.yaml', 'r') as f: | |
data = yaml.load(f.read()) | |
ht = HomeTeaching(data) | |
x = margin | |
start_y = margin | |
pdf = export("HTSlips.pdf") | |
for companionship in ht.companionships: | |
new_y = draw_companionship(companionship, x, start_y, 250) | |
start_y += new_y + gap | |
if start_y > (page_height - margin - 100): | |
if x == margin: | |
x = page_width - margin - 250 | |
start_y = margin | |
else: | |
pdf.add() | |
clear(all) | |
x = margin | |
start_y = margin | |
pdf.add() | |
pdf.finish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment