Skip to content

Instantly share code, notes, and snippets.

@ar0ch
Last active April 16, 2024 06:04
Show Gist options
  • Save ar0ch/889051aef865d23597dc31d207737a42 to your computer and use it in GitHub Desktop.
Save ar0ch/889051aef865d23597dc31d207737a42 to your computer and use it in GitHub Desktop.
Zola guest list CSV to formatted addresses
"""Quick and dirty transform of the Zola guest list CSV export to formatted addresses"""
import csv
from dataclasses import dataclass
from pathlib import Path
from typing import Optional, Union
@dataclass
class Address:
person_1: str
person_2: str
line_1: str
line_2: str
city: str
state: str
zip: Union[str, int]
country: Optional[str]
def __str__(self):
address = f"{self.person_1}"
address += f" & {self.person_2}\n" if self.person_2 != "" else "\n"
address += f"{self.line_1}\n"
address += f"{self.line_2}\n" if self.line_2 else ""
address += f"{self.city}, {self.state} {self.zip} {self.country}"
return address
file = Path("/Users/arch/Downloads/export.csv")
addresses = []
with file.open() as fh:
reader = csv.DictReader(fh)
for line in reader:
p1, p2 = "", ""
p1 = f"{line["Title"]} " if line["Title"] else ""
p1 += f"{line["First Name"]} {line["Last Name"]}"
p2 = f"{line["Partner Title"]} " if line["Partner Title"] else ""
p2 += f"{line["Partner First Name"]} {line["Partner Last Name"]}"
addresses.append(
Address(
p1,
p2,
line["Street Address"],
line["Street Address (line 2)"],
line["City"],
line["State / Region"],
line["Zip / Postal Code"],
line["Country"],
)
)
output_file = Path("/Users/arch/Downloads/addresses.txt")
with output_file.open("w") as fh:
for a in addresses:
fh.write(f"{a}\n---------\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment