created code, for printing the Ruder-IDs
This commit is contained in:
90
Nextcloud_Material/upload_print_pdf.ipynb
Normal file
90
Nextcloud_Material/upload_print_pdf.ipynb
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e4755f4e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import requests\n",
|
||||
"import os"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "689fd1ef",
|
||||
"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"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4967214a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"parent_folder = os.path.dirname(os.getcwd())\n",
|
||||
"LOCAL_FILE_PATH = os.path.join(parent_folder,'LaTex','print_Ruder-IDs.pdf')\n",
|
||||
"REMOTE_FILE_PATH = \"Shared/Ruderverein/Material/print_Ruder-IDs.pdf\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "515eaaac",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"# --- Construction ---\n",
|
||||
"# The WebDAV endpoint for files is /remote.php/dav/files/USER/\n",
|
||||
"upload_url = f\"{NEXTCLOUD_URL}/remote.php/dav/files/{USERNAME}/{REMOTE_FILE_PATH}\"\n",
|
||||
"\n",
|
||||
"with open(LOCAL_FILE_PATH, 'rb') as f:\n",
|
||||
" response = requests.put(\n",
|
||||
" upload_url, \n",
|
||||
" data=f, \n",
|
||||
" auth=(USERNAME, APP_PASSWORD)\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"# --- Results ---\n",
|
||||
"if response.status_code in [201, 204]:\n",
|
||||
" print(\"Upload successful!\")\n",
|
||||
"else:\n",
|
||||
" print(f\"Failed! Status code: {response.status_code}\")\n",
|
||||
" print(response.text)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
||||
Reference in New Issue
Block a user