Skip to content

Instantly share code, notes, and snippets.

@derwiki
Created December 23, 2020 00:31
Show Gist options
  • Save derwiki/dce95bb4bedce72ad1cc4fc7820cab3a to your computer and use it in GitHub Desktop.
Save derwiki/dce95bb4bedce72ad1cc4fc7820cab3a to your computer and use it in GitHub Desktop.
From addresses.csv, print out a FROM and TO label on a sheet of paper
import csv
from fpdf import FPDF
pdf = FPDF()
MAJOR = 12
MINOR = 10
# download from Google Sheets as CSV to addresses.csv
with open('addresses.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader, None)
for first, last, address, city, state, postal, archived in reader:
is_archived = archived.strip() == '1'
if is_archived:
print(f'skipping {first} {last}')
continue
pdf.add_page()
pdf.set_font('Helvetica', 'B', MAJOR)
pdf.cell(40, 10, 'The Dereweckis')
pdf.ln(5)
pdf.set_font('Helvetica', 'B', MINOR)
pdf.cell(40, 10, '1010 Nothing St')
pdf.ln(5)
pdf.cell(40, 10, 'San Francisco, CA 94107')
pdf.ln(30)
pdf.set_font('Helvetica', 'B', MAJOR)
pdf.cell(190, h=10, txt=f'{first} {last}', align='C')
pdf.ln(5)
pdf.set_font('Helvetica', 'B', MINOR)
pdf.cell(190, h=10, txt=f'{address}', align='C')
pdf.ln(5)
pdf.cell(190, h=10, txt=f'{city}, {state} {postal}', align='C')
pdf.output('addresses.pdf', 'F')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment