-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
APSToolkitPython/Tutorials/08. Explore URL ACC Extract.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Extract Infomration From ACC URL Opening " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Example URL , make sure you opened the 3d model in the browser before copying the URL" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"url = \"https://acc.autodesk.com/docs/files/projects/ec0f8261-aeca-4ab9-a1a5-5845f952b17d?folderUrn=urn%3Aadsk.wipprod%3Afs.folder%3Aco.SQBGbt7LTWywCVcHfqSb1Q&entityId=urn%3Aadsk.wipprod%3Adm.lineage%3AoxAqhUL0SISdkPcNLzehag&viewModel=detail&moduleId=folders&viewableGuid=5d41dda7-eea1-eff5-77dd-ee1aa81fc3a8\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"ProjectId: b.ec0f8261-aeca-4ab9-a1a5-5845f952b17d\n", | ||
"folderUrn: urn%3Aadsk.wipprod%3Afs.folder%3Aco.SQBGbt7LTWywCVcHfqSb1Q\n", | ||
"entityId: urn%3Aadsk.wipprod%3Adm.lineage%3AoxAqhUL0SISdkPcNLzehag\n", | ||
"viewableGuid: 5d41dda7-eea1-eff5-77dd-ee1aa81fc3a8\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import requests\n", | ||
"from urllib.parse import urlparse\n", | ||
"\n", | ||
"def get_info_from_url(url):\n", | ||
" try:\n", | ||
" response = requests.get(url)\n", | ||
" response.raise_for_status()\n", | ||
" parsed_url = urlparse(url)\n", | ||
" \n", | ||
" # Extract project ID from URL path\n", | ||
" path_segments = parsed_url.path.split('/')\n", | ||
" project_id = path_segments[4] if len(path_segments) >= 4 else ''\n", | ||
" # Extract query parameters\n", | ||
" query_params = dict(q.split(\"=\") for q in parsed_url.query.split(\"&\"))\n", | ||
" folder_urn = query_params.get('folderUrn', '')\n", | ||
" entity_id = query_params.get('entityId', '')\n", | ||
" viewable_guid = query_params.get('viewableGuid', '')\n", | ||
" \n", | ||
" return {\n", | ||
" 'ProjectId': \"b.\"+project_id,\n", | ||
" 'folderUrn': folder_urn,\n", | ||
" 'entityId': entity_id,\n", | ||
" 'viewableGuid': viewable_guid\n", | ||
" }\n", | ||
" except Exception as e:\n", | ||
" print(\"Error occurred:\", e)\n", | ||
" return None\n", | ||
"info = get_info_from_url(url)\n", | ||
"if info:\n", | ||
" for key, value in info.items():\n", | ||
" print(f\"{key}: {value}\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Get Derivative URN" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Derivative URN Of Version 2: dXJuJTNBYWRzay53aXBwcm9kJTNBZG0ubGluZWFnZSUzQW94QXFoVUwwU0lTZGtQY05MemVoYWc_dmVyc2lvbj0y\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# convert entityId to derivative urn by base64encode\n", | ||
"import base64\n", | ||
"version = 2\n", | ||
"item_version = info['entityId']+ f\"?version={version}\"\n", | ||
"urn = base64.b64encode(item_version.encode()).decode()\n", | ||
"# change character \"/\" to \"_\n", | ||
"urn = urn.replace(\"/\", \"_\")\n", | ||
"print(f\"Derivative URN Of Version {version}: {urn}\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.11.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters