deprecated athletes form V1, because it was unhandleable.

This commit is contained in:
2026-03-20 09:58:24 +01:00
parent 65d800685a
commit 21bd9c42bd

View File

@@ -0,0 +1,383 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "1293f184",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import os\n",
"import requests\n",
"import urllib\n",
"import io\n",
"import base64\n",
"\n",
"from matplotlib import pyplot as plt\n",
"import matplotlib.image as mpimg"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2946897b",
"metadata": {},
"outputs": [],
"source": [
"for file in os.listdir('temp'):\n",
" os.remove(os.path.join('temp',file))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cb57d754",
"metadata": {},
"outputs": [],
"source": [
"user = \"Georg Brantegger\"\n",
"with open('app_pw.txt','r') as f:\n",
" app_pw = f.readline()\n",
"\n",
"\n",
"base_url_csv = \"https://nextcloud.karnelegger.eu/remote.php/webdav\"\n",
"folders = [\"Forms\",\"2 - Kontaktdatenerhebung Ruder-innen RV Villach\",\"Ergebnisse CSV\"]\n",
"folder_string = '/'.join([urllib.parse.quote(folder) for folder in folders])\n",
"filename_csv = \"Kontaktdatenerhebung Ruder-innen RV Villach (Antworten).csv\"\n",
"\n",
"url_csv = '/'.join([base_url_csv,folder_string,urllib.parse.quote(filename_csv)])\n",
"\n",
"\n",
"r = requests.get(url_csv, auth=(user, app_pw))\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "543d5103",
"metadata": {},
"outputs": [],
"source": [
"def extract_tel(row,col):\n",
" # remove the first ' and all whitespaces within number\n",
"\n",
" tel = str(row[col])\n",
"\n",
" replace_dict = {\"'\":'',' ':''}\n",
" \n",
" for key, value in replace_dict.items():\n",
" tel = tel.replace(key,value)\n",
"\n",
" # handle people who don't know how country codes work\n",
" if tel[0] == '0':\n",
" tel = '+43'+tel[1:]\n",
" if tel[0] == '6':\n",
" tel = '+43'+tel\n",
" if tel[0:4] == '+430':\n",
" tel = '+43'+tel[4:]\n",
" if tel[0:3] == '+49':\n",
" tel = '+43'+tel[3:]\n",
" if tel[0:2] == '43':\n",
" tel = '+43'+tel[2:]\n",
" if tel[0:2] == '+6':\n",
" tel = '+43'+tel[1:]\n",
" \n",
" return tel"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a74d9129",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(io.StringIO(r.text))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ba590c1",
"metadata": {},
"outputs": [],
"source": [
"name_replacement_dict = {',':'',\n",
" 'Christoph Spath-Glantschnig': 'Spath-Glantschnig Christoph',\n",
" 'Felix Assmann-Hafenscherer': 'Assmann-Hafenscherer Felix',\n",
" 'Elias Assmann': 'Assmann Elias',\n",
" 'Bernadette Assmann ': 'Assmann Bernadette',\n",
" 'Tropea Giuseppe Manfredi': 'Tropea Manfredi Giuseppe',\n",
" 'Sabrina': 'Bellotti Sabrina',\n",
" 'Ich bin 18': None,\n",
" }\n",
"\n",
"df['Mein Name ist:'] = df['Mein Name ist:'].replace(name_replacement_dict,regex=True).str.strip()\n",
"df['Name Kontaktperson/Kind 1'] = df['Name Kontaktperson/Kind 1'].replace(name_replacement_dict,regex=True).str.strip()\n",
"df['Name Kontaktperson/Kind 2'] = df['Name Kontaktperson/Kind 2'].replace(name_replacement_dict,regex=True).str.strip()\n",
"df['Name Kontaktperson/Kind 3'] = df['Name Kontaktperson/Kind 3'].replace(name_replacement_dict,regex=True).str.strip()\n",
"\n",
"df['Meine Telefonnummer ist:'] = df.apply(extract_tel,axis=1,args=('Meine Telefonnummer ist:',))\n",
"df['Telefonnummer Kontaktperson 1'] = df.apply(extract_tel,axis=1,args=('Telefonnummer Kontaktperson 1',))\n",
"df['Telefonnummer Kontaktperson 2'] = df.apply(extract_tel,axis=1,args=('Telefonnummer Kontaktperson 2',))\n",
"df['Telefonnummer Kontaktperson 3'] = df.apply(extract_tel,axis=1,args=('Telefonnummer Kontaktperson 3',))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b664ba7",
"metadata": {},
"outputs": [],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58057da5",
"metadata": {},
"outputs": [],
"source": [
"# manually fix_Felix row\n",
"row = df.loc[df['Mein Name ist:'] == 'Hafenscherer Rita',:]\n",
"row['Mein Name ist:'] = 'Assmann-Hafenscherer Felix'\n",
"row['Ich bin:'] = 'Ruder:in'\n",
"row['Meine Telefonnummer ist:'] = '+4367764409018'\n",
"row['Name Kontaktperson/Kind 1'] = 'Hafenscherer Rita'\n",
"row['Telefonnummer Kontaktperson 1'] = '+436509623400'\n",
"df.loc[df['Mein Name ist:'] == 'Hafenscherer Rita',:] = row"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "562a911b",
"metadata": {},
"outputs": [],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc8568d6",
"metadata": {},
"outputs": [],
"source": [
"rowers_columns = ['Mein Name ist:',\n",
" 'Mein Jahrgang ',\n",
" 'Lade ein nettes Selfy hoch!',\n",
" 'Meine Telefonnummer ist:',\n",
" 'Name Kontaktperson/Kind 1',\n",
" 'Telefonnummer Kontaktperson 1',\n",
" 'Name Kontaktperson/Kind 2',\n",
" 'Telefonnummer Kontaktperson 2',\n",
" 'Name Kontaktperson/Kind 3',\n",
" 'Telefonnummer Kontaktperson 3']\n",
"\n",
"rowers_dict = {key: [] for key in rowers_columns}\n",
"\n",
"parents_columns = ['Mein Name ist:',\n",
" 'Lade ein nettes Selfy hoch!',\n",
" 'Meine Telefonnummer ist:',\n",
" 'Name Kontaktperson/Kind 1',\n",
" 'Telefonnummer Kontaktperson 1',\n",
" 'Name Kontaktperson/Kind 2',\n",
" 'Telefonnummer Kontaktperson 2',\n",
" 'Name Kontaktperson/Kind 3',\n",
" 'Telefonnummer Kontaktperson 3']\n",
"\n",
"parents_dict = {key: [] for key in parents_columns}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2d44beb8",
"metadata": {},
"outputs": [],
"source": [
"for _,row in df.iterrows():\n",
" if (row['Ich bin:'] == 'Ruder:in') | (row['Mein Name ist:']=='Assmann-Hafenscherer Felix'):\n",
" for col in rowers_columns:\n",
" rowers_dict[col].append(row[col])\n",
" \n",
" elif row['Ich bin:'] == 'Elternteil/erwachsene Ansprechperson':\n",
" for col in parents_columns:\n",
" parents_dict[col].append(row[col])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "118dd1a7",
"metadata": {},
"outputs": [],
"source": [
"rowers_df = pd.DataFrame(rowers_dict)\n",
"parents_df = pd.DataFrame(parents_dict)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f1b7dd6b",
"metadata": {},
"outputs": [],
"source": [
"rowers_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f1e3f59d",
"metadata": {},
"outputs": [],
"source": [
"parents_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df2c876c",
"metadata": {},
"outputs": [],
"source": [
"# def get_photo_for_row(row):\n",
"\n",
"# filename = row['Foto']\n",
"\n",
"# found_photo = False\n",
"# i = 0\n",
"# while found_photo is False:\n",
"# print(f\"trying folder {i}\")\n",
"# base_url_photo = \"https://nextcloud.karnelegger.eu/remote.php/webdav\"\n",
"# folders = [\"Forms\",\"4 - Kontaktdatenerhebung Trainerteam\",f\"{i}\",\"19 - Foto\"]\n",
"# folder_string = '/'.join([urllib.parse.quote(folder) for folder in folders])\n",
"# filename_photo = urllib.parse.quote(filename)\n",
"\n",
"# url_photo = '/'.join([base_url_photo,folder_string,urllib.parse.quote(filename_photo)])\n",
"\n",
"# r = requests.get(url_photo, auth=(user, app_pw))\n",
"# if r.status_code != 200:\n",
"# i+=1\n",
"# if i > 100:\n",
"# break\n",
"# continue\n",
"# else:\n",
"# photo_bytes = r.content\n",
"# found_photo = True\n",
"# photo_b64 = base64.b64encode(photo_bytes).decode(\"utf-8\")\n",
" \n",
"# i = base64.b64decode(photo_b64)\n",
"# i = io.BytesIO(i)\n",
"# i = mpimg.imread(i, format='JPG')\n",
"\n",
"# plt.imshow(i, interpolation='nearest')\n",
"# plt.show()\n",
"\n",
"# return photo_b64\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8c9db8d6",
"metadata": {},
"outputs": [],
"source": [
"# def convert_rows_to_vcf(row):\n",
"# # Map CSV columns to vCard fields\n",
"# first_name = row['Vorname']\n",
"# last_name = row['Nachname']\n",
"# phone = row['Telefonnummer']\n",
"# org = 'Ruderverein Villach von 1881'\n",
"# photo_b64 = get_photo_for_row(row)\n",
" \n",
"\n",
"# lines = [\n",
"# \"BEGIN:VCARD\",\n",
"# \"VERSION:3.0\",\n",
"# f\"FN:{first_name} {last_name}\",\n",
"# f\"N:{last_name};{first_name};;;\",\n",
"# f\"ORG:{org}\",\n",
"# f\"TEL;TYPE=CELL:{phone}\"]\n",
"\n",
"# if photo_b64:\n",
"# lines.append(f\"PHOTO;ENCODING=b;TYPE=JPEG:{photo_b64}\")\n",
"\n",
"# lines.append(\"END:VCARD\")\n",
"\n",
"# vcard_content = \"\\n\".join(lines)\n",
"\n",
"# # Save to file\n",
"# filename = f\"{last_name}_{first_name}.vcf\".replace(\" \", \"_\")\n",
"# with open(os.path.join('temp', filename), 'w') as f:\n",
"# f.write(vcard_content)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "61659f5b",
"metadata": {},
"outputs": [],
"source": [
"# df.apply(convert_rows_to_vcf,axis=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37b2a51b",
"metadata": {},
"outputs": [],
"source": [
"# base_url = \"https://nextcloud.karnelegger.eu/remote.php/dav/addressbooks/users/Georg%20Brantegger/rv-villach-trainer/\"\n",
"\n",
"# for vcf_file in os.listdir('temp'):\n",
"\n",
"# url = base_url + vcf_file\n",
"\n",
"# with open(f'temp/{vcf_file}', \"rb\") as f:\n",
"# r = requests.put(\n",
"# url,\n",
"# data=f,\n",
"# auth=(user, app_pw),\n",
"# headers={\"Content-Type\": \"text/vcard\"}\n",
"# )\n",
"\n",
"# print(vcf_file, r.status_code)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}