Skip to content

Commit

Permalink
update parse url
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Nov 18, 2024
1 parent b0bfb34 commit 5d636bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions APSToolkitPython/src/aps_toolkit/BIM360.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,26 @@ def __init__(self, token: Token = None):
@staticmethod
def parse_url(url: str) -> dict:
"""
Parse url to get project_id, folder_urn, entity_id, model_guid
Parse url to get project_id, folder_urn, version_id, viewable_guid
:param url: the url from bim360 or autodesk construction cloud (ACC)
:return: :class:`dict` project_id, folder_urn, entity_id, model_guid
:return: :class:`dict` project_id, folder_urn, version_id, viewable_guid
"""
project_id_match = re.search(r'projects/([^\/?#]+)', url)
project_id = 'b.' + project_id_match.group(1) if project_id_match else ''
query_params = parse_qs(urlparse(url).query)
folder_urn = query_params.get('folderUrn', [''])[0]
entity_id = query_params.get('entityId', [''])[0]
model_guid = query_params.get('viewableGuid', [''])[0]
version_id = query_params.get('entityId', [''])[0]
item_id = None
if version_id is not None or version_id != '':
item_id =version_id.split("?")[0]
viewable_guid = query_params.get('viewable_guid', [''])[0]

return {
'project_id': project_id,
'folder_urn': folder_urn,
'entity_id': entity_id,
'model_guid': model_guid,
'item_id': item_id,
'version_id': version_id,
'viewable_guid': viewable_guid,
}

def publish_model(self, project_id: str, item_id: str):
Expand Down
2 changes: 1 addition & 1 deletion APSToolkitPython/src/test/test_bim360.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
self.version_id = "urn:adsk.wipprod:fs.file:vf.aK6QZ3gUQPGI63FxRBA3tQ?version=4"

def test_parse_url(self):
url = "https://acc.autodesk.com/docs/files/projects/ca790fb5-141d-4ad5-b411-0461af2e9748?folderUrn=urn%3Aadsk.wipprod%3Afs.folder%3Aco.uX9MsdjjSraK_3p5qXyE_A&entityId=urn%3Aadsk.wipprod%3Adm.lineage%3AwGXA2ljoSQaXtGOEepawIg&viewModel=detail&moduleId=folders"
url = "https://acc.autodesk.com/docs/files/projects/ca790fb5-141d-4ad5-b411-0461af2e9748?folderUrn=urn%3Aadsk.wipprod%3Afs.folder%3Aco.kHlWc1ajSHSxey-_bGjKwg&entityId=urn%3Aadsk.wipprod%3Afs.file%3Avf.QOFE_uOpSmaK-5JWkn3yYQ%3Fversion%3D5&viewModel=detail&moduleId=folders&viewableGuid=517b8739-48df-bcb2-be30-dda4b1eee186"
result = self.bim360.parse_url(url)
# check projectid
self.assertEqual(result['project_id'], "b." + "ca790fb5-141d-4ad5-b411-0461af2e9748")
Expand Down

0 comments on commit 5d636bf

Please sign in to comment.