Compare commits
2 commits
f2246b832d
...
a8e89ca579
Author | SHA1 | Date | |
---|---|---|---|
Skye | a8e89ca579 | ||
Skye | f8887eb7ac |
68
format.py
68
format.py
|
@ -238,21 +238,24 @@ if args.address_file.suffix == ".csv":
|
|||
csv_filename = args.address_file
|
||||
elif args.address_file.suffix == ".ods":
|
||||
# https://help.libreoffice.org/latest/en-US/text/shared/guide/csv_params.html
|
||||
export_options = "csv:Text - txt - csv (StarCalc):" + ",".join( # Magic CSV export string
|
||||
[
|
||||
str(ord(",")), # Field Separator
|
||||
str(ord('"')), # Text Delimiter
|
||||
"76", # Character Set - UTF-8 => 76
|
||||
"", # starting line; ignored in export
|
||||
"", # cell format codes; ignored in export
|
||||
"1033", # Language Identifier - en-US => 1033
|
||||
"", # Quoted field as text; default False
|
||||
"", # Detect special numbers; default True
|
||||
"", # Save cell contents as shown; default True
|
||||
"", # Export cell formulas; default false
|
||||
"", # Remove spaces; ignored in export
|
||||
"-1", # Export sheets - all sheets => -1
|
||||
]
|
||||
export_options = (
|
||||
"csv:Text - txt - csv (StarCalc):"
|
||||
+ ",".join( # Magic CSV export string
|
||||
[
|
||||
str(ord(",")), # Field Separator
|
||||
str(ord('"')), # Text Delimiter
|
||||
"76", # Character Set - UTF-8 => 76
|
||||
"", # starting line; ignored in export
|
||||
"", # cell format codes; ignored in export
|
||||
"1033", # Language Identifier - en-US => 1033
|
||||
"", # Quoted field as text; default False
|
||||
"", # Detect special numbers; default True
|
||||
"", # Save cell contents as shown; default True
|
||||
"", # Export cell formulas; default false
|
||||
"", # Remove spaces; ignored in export
|
||||
"-1", # Export sheets - all sheets => -1
|
||||
]
|
||||
)
|
||||
)
|
||||
result = subprocess.run(
|
||||
[
|
||||
|
@ -270,6 +273,19 @@ elif args.address_file.suffix == ".ods":
|
|||
else:
|
||||
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)
|
||||
rows = csv.DictReader(csvfile)
|
||||
|
||||
|
@ -283,12 +299,13 @@ mid = secrets.get("mailer_id")
|
|||
class Card(TypedDict):
|
||||
address: str
|
||||
avatar: Path | None
|
||||
row: dict[str, str]
|
||||
row: CSVRow
|
||||
imb: str
|
||||
|
||||
|
||||
cards: list[Card] = []
|
||||
for row in rows:
|
||||
row = CSVRow(**row)
|
||||
if row["Address"] == "":
|
||||
continue
|
||||
|
||||
|
@ -301,18 +318,19 @@ for row in rows:
|
|||
|
||||
address = row["Address"].split("\n") + country
|
||||
|
||||
if row.get("Avatar", "") != "":
|
||||
avatar = get_avatar(row["Avatar"], secrets)
|
||||
if (avatar_url := row.get("Avatar", "")) != "":
|
||||
avatar = get_avatar(avatar_url, secrets) # type: ignore
|
||||
else:
|
||||
avatar = None
|
||||
|
||||
card: Card = {
|
||||
"address": "\n".join(address),
|
||||
"avatar": avatar,
|
||||
"row": row,
|
||||
"imb": "",
|
||||
}
|
||||
cards.append(card)
|
||||
cards.append(
|
||||
{
|
||||
"address": "\n".join(address),
|
||||
"avatar": avatar,
|
||||
"row": row,
|
||||
"imb": "",
|
||||
}
|
||||
)
|
||||
|
||||
# Typst can't access files outside the project root, except through a symlink
|
||||
# Create one in cache to use here
|
||||
|
|
Loading…
Reference in a new issue