added code for automatic creation of video folders

This commit is contained in:
2026-03-20 09:58:44 +01:00
parent 21bd9c42bd
commit 4be223390c
2 changed files with 187 additions and 2 deletions

View File

@@ -0,0 +1,184 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"id": "152c4ce0",
"metadata": {},
"outputs": [],
"source": [
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "041b0ab6",
"metadata": {},
"outputs": [],
"source": [
"# --- Configuration ---\n",
"NEXTCLOUD_URL = \"https://nextcloud.karnelegger.eu\"\n",
"USERNAME = \"Georg Brantegger\"\n",
"with open('app_pw.txt','r') as f:\n",
" APP_PASSWORD = f.readline()\n",
"\n",
"\n",
"# Modern Nextcloud WebDAV endpoint format:\n",
"WEBDAV_BASE_URL = f\"{NEXTCLOUD_URL}/remote.php/dav/files/{USERNAME}/Shared/Ruderverein/Videoanalyse\""
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "19ec4c3e",
"metadata": {},
"outputs": [],
"source": [
"def create_nextcloud_folder(folder_url):\n",
" \"\"\"Sends a MKCOL request to Nextcloud to create a folder.\"\"\"\n",
" response = requests.request(\"MKCOL\", folder_url, auth=(USERNAME, APP_PASSWORD))\n",
" \n",
" if response.status_code in [201, 207]:\n",
" print(f\"✅ Success: Created folder at {folder_url}\")\n",
" elif response.status_code == 405:\n",
" # WebDAV returns 405 Method Not Allowed if the folder already exists\n",
" print(f\"⏩ Skipped: Folder already exists at {folder_url}\")\n",
" elif response.status_code == 409:\n",
" print(f\"❌ Error: Parent folder doesn't exist for {folder_url}\")\n",
" else:\n",
" print(f\"❌ Error {response.status_code}: Could not create folder.\")\n",
" print(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "b4c04efb",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import vobject\n",
"\n",
"\n",
"# This is the \"URL slug\" of your address book. \n",
"# Usually, if you name it \"Athletes\", the slug is \"athletes\" (lowercase).\n",
"# You can find the exact name by going to Contacts -> Settings (bottom left) -> \n",
"# Click the 3 dots next to your address book -> \"Copy link\". \n",
"# The link will end with /addressbooks/users/username/THIS_PART/\n",
"ADDRESSBOOK_NAME = \"rv-villach-athletinnen\" \n",
"\n",
"\n",
"# The ?export parameter tells Nextcloud to dump the whole address book at once\n",
"CARDDAV_URL = f\"{NEXTCLOUD_URL}/remote.php/dav/addressbooks/users/{USERNAME}/{ADDRESSBOOK_NAME}/?export\"\n",
"\n",
"def get_athlete_names():\n",
" print(f\"Fetching contacts from the '{ADDRESSBOOK_NAME}' address book...\")\n",
" response = requests.get(CARDDAV_URL, auth=(USERNAME, APP_PASSWORD))\n",
" \n",
" if response.status_code != 200:\n",
" print(f\"❌ Error {response.status_code}: Could not fetch address book.\")\n",
" print(\"Check your URL, credentials, and make sure the ADDRESSBOOK_NAME is exactly right.\")\n",
" return []\n",
"\n",
" vcf_data = response.text\n",
" athletes = []\n",
"\n",
" # Parse the multi-contact VCF data\n",
" for vcard in vobject.readComponents(vcf_data):\n",
" # The 'n' property in a vCard holds the structured Name (First, Last, etc.)\n",
" if hasattr(vcard, 'n'):\n",
" first_name = vcard.n.value.given\n",
" last_name = vcard.n.value.family\n",
" \n",
" # Combine them. The .strip() helps if someone only has a first or last name\n",
" full_name = f\"{last_name} {first_name}\".strip()\n",
" \n",
" if full_name:\n",
" athletes.append(full_name)\n",
" \n",
" # Fallback just in case a contact only has a \"Formatted Name\" (fn) saved\n",
" elif hasattr(vcard, 'fn'):\n",
" athletes.append(vcard.fn.value)\n",
" \n",
" return athletes"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "306aef25",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"⏩ Skipped: Folder already exists at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse\n",
"Fetching contacts from the 'rv-villach-athletinnen' address book...\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Aufegger%20Tobias\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Praschnig%20Flora\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Buchacher%20Eva\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Gigacher%20Olivia\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/McGrath%20Samuel\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Magdalena%20Truppe\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Yang%20Ruien\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Yang%20Xiaoen\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Kofler%20Hannah\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Tropea%20Manfredi\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Spath-Glantschnig%20%20Christoph\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Acerbi%20Sofia\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Aufegger%20Emilia\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Henriks%20Alva\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Tscherne%20Tobias\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Pressinger%20Laurin\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Bodner%20Emma\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Jop%20Nicolas\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Assmann-Hafenscherer%20Felix\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Henriks%20Konstantin\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Loidl%20Lieselotte\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Poga%C4%8Dar%20Anamary\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Polessnig%20Valentina\n",
"✅ Success: Created folder at https://nextcloud.karnelegger.eu/remote.php/dav/files/Georg Brantegger/Shared/Ruderverein/Videoanalyse/Paulik%20Elena\n"
]
}
],
"source": [
"# 1. Create the main base folder first (just in case it doesn't exist)\n",
"create_nextcloud_folder(WEBDAV_BASE_URL)\n",
"\n",
"# 2. Loop through your athletes and create a folder for each\n",
"for athlete in get_athlete_names():\n",
" # It's usually good practice to replace spaces with underscores for web URLs, \n",
" # but Nextcloud handles spaces fine if we format the URL correctly.\n",
" # We use requests.utils.quote to properly encode spaces and special characters.\n",
" safe_folder_name = requests.utils.quote(athlete)\n",
" athlete_folder_url = f\"{WEBDAV_BASE_URL}/{safe_folder_name}\"\n",
" \n",
" create_nextcloud_folder(athlete_folder_url)"
]
}
],
"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
}