Add type to CSV row
This commit is contained in:
parent
f8887eb7ac
commit
a8e89ca579
25
format.py
25
format.py
|
@ -273,6 +273,19 @@ elif args.address_file.suffix == ".ods":
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown file type for --address-file")
|
raise Exception("Unknown file type for --address-file")
|
||||||
|
|
||||||
|
|
||||||
|
class CSVRow(TypedDict):
|
||||||
|
Name: str
|
||||||
|
Address: str
|
||||||
|
DPC: str
|
||||||
|
Country: str
|
||||||
|
Design: str
|
||||||
|
Type: str
|
||||||
|
Personalization: str
|
||||||
|
Avatar: str | None
|
||||||
|
US: str
|
||||||
|
|
||||||
|
|
||||||
csvfile = open(csv_filename)
|
csvfile = open(csv_filename)
|
||||||
rows = csv.DictReader(csvfile)
|
rows = csv.DictReader(csvfile)
|
||||||
|
|
||||||
|
@ -286,12 +299,13 @@ mid = secrets.get("mailer_id")
|
||||||
class Card(TypedDict):
|
class Card(TypedDict):
|
||||||
address: str
|
address: str
|
||||||
avatar: Path | None
|
avatar: Path | None
|
||||||
row: dict[str, str]
|
row: CSVRow
|
||||||
imb: str
|
imb: str
|
||||||
|
|
||||||
|
|
||||||
cards: list[Card] = []
|
cards: list[Card] = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
row = CSVRow(**row)
|
||||||
if row["Address"] == "":
|
if row["Address"] == "":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -304,18 +318,19 @@ for row in rows:
|
||||||
|
|
||||||
address = row["Address"].split("\n") + country
|
address = row["Address"].split("\n") + country
|
||||||
|
|
||||||
if row.get("Avatar", "") != "":
|
if (avatar_url := row.get("Avatar", "")) != "":
|
||||||
avatar = get_avatar(row["Avatar"], secrets)
|
avatar = get_avatar(avatar_url, secrets) # type: ignore
|
||||||
else:
|
else:
|
||||||
avatar = None
|
avatar = None
|
||||||
|
|
||||||
card: Card = {
|
cards.append(
|
||||||
|
{
|
||||||
"address": "\n".join(address),
|
"address": "\n".join(address),
|
||||||
"avatar": avatar,
|
"avatar": avatar,
|
||||||
"row": row,
|
"row": row,
|
||||||
"imb": "",
|
"imb": "",
|
||||||
}
|
}
|
||||||
cards.append(card)
|
)
|
||||||
|
|
||||||
# Typst can't access files outside the project root, except through a symlink
|
# Typst can't access files outside the project root, except through a symlink
|
||||||
# Create one in cache to use here
|
# Create one in cache to use here
|
||||||
|
|
Loading…
Reference in a new issue