Browse Source

initial commit

master
Tobias Brunner 11 months ago
commit
85ef0c5574
  1. 3
      .gitignore
  2. 66
      main.py

3
.gitignore

@ -0,0 +1,3 @@
all.vcf
mannschaftslisten.csv
.vscode/

66
main.py

@ -0,0 +1,66 @@
import csv
import sys
from datetime import datetime
import phonenumbers
def convert(csvfile):
phone_rows = {
"HOME,CELL": "Mobil (Privat)",
"HOME,VOICE": "Festnetz (Privat)",
"WORK,CELL": "Mobil (Arbeit)",
}
with open(csvfile, "r", encoding="latin-1") as source:
reader = csv.DictReader(source)
for row in reader:
name = row["Name"]
firstname = row["Vorname"]
email = row["E-Mail"]
street = row["Strasse"]
postalcode = row["PLZ"]
place = row["Ort"]
title = row["Grad"]
notes = row["Zug"]
birthday = datetime.strftime(
datetime.strptime(row["Geburtsdatum"], "%d.%m.%Y"), "%Y%m%d"
)
phones = ""
for tpe, col in phone_rows.items():
if row[col]:
phonenumber_formatted = phonenumbers.format_number(
phonenumbers.parse(row[col], "CH"),
phonenumbers.PhoneNumberFormat.E164,
)
phones = phones + f'TEL;TYPE="{tpe}":{phonenumber_formatted}\n'
vcard = (
"BEGIN:VCARD\n"
"VERSION:3.0\n"
f"N:{name};{firstname};;;\n"
f"FN:{firstname} {name}\n"
f"ORG:Feuerwehr Urdorf\n"
f"EMAIL;TYPE=HOME:{email}\n"
f"ADR;TYPE=HOME:;;{street};{place};;{postalcode};\n"
f"TITLE:{title}\n"
f"{phones}"
f"BDAY;VALUE=DATE:{birthday}\n"
f"NOTE:{notes}\n"
"CATEGORIES:Feuerwehr\n"
"END:VCARD\n"
)
print(vcard)
def main(args):
if len(args) != 2:
print("Usage:")
print(args[0] + " filename")
return
convert(args[1])
if __name__ == "__main__":
main(sys.argv)
Loading…
Cancel
Save