Skip to content
Snippets Groups Projects
Commit 3574d18b authored by VentusTWY's avatar VentusTWY
Browse files

refactor python wrapper module

parent d0ba243d
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,8 @@ import subprocess
# Define the base URL here
STORAGE_PATH = "/home/wyt20/.AE_data_store_instance/storage"
BASE_URL = "http://localhost:5000/api"
# BASE_URL = "http://victor.ae.ic.ac.uk"
# BASE_URL = "http://localhost:5000/api"
BASE_URL = "http://victor.ae.ic.ac.uk"
# change the url if running on different server
def create_record(data: dict) -> dict:
......@@ -34,7 +34,7 @@ def get_record(record_number: int) -> dict:
if not isinstance(record_number, int):
raise TypeError("record_number must be an integer")
url = f"{BASE_URL}/api/records/{record_number}"
url = f"{BASE_URL}/records/{record_number}"
try:
response = requests.get(url)
......@@ -164,7 +164,7 @@ def symbolic_link_with_id(file_id: str, shortcut_file_name: str):
print(f"Symbolic link {shortcut_file_name} is not valid.")
return False
def get_file_id_from_records(record_id: int, file_key: str) -> str:
def get_file_id_from_record(record_id: int, file_key: str) -> str:
record_data = get_record(record_id)
bucket_id = record_data["metadata"]["bucket_id"]
os.chdir('AE_data_store')
......@@ -176,5 +176,5 @@ def get_file_id_from_records(record_id: int, file_key: str) -> str:
return file_id
def create_symbolic_link(record_id: int, file_key: str, shortcut_file_name: str) -> bool:
file_id = get_file_id_from_records(record_id, file_key)
file_id = get_file_id_from_record(record_id, file_key)
return symbolic_link_with_id(file_id, shortcut_file_name)
......@@ -35,7 +35,7 @@ This directory showcases the Python wrapper modules created to access the Inveni
- The `base_url` and `storage_URL` are set to localhost by default and should be modified according to the server ID and storage path.
- It also includes previous wrapper functions in Archive to initialize Invenio locally without REST API and HTTP server access.
- _Note: The `AE_DATA_STORE` repository must be cloned in the same directory for the `get_file_id` function to work._ (https://github.com/AI-for-Net-Zero/AE_data_store/tree/main) the branch used for the demonstration is ventus/demo
- Access to `victor.ae.ic.ac.uk` may require `/api` to be removed from the URL, depending on the server version.
- Access to `victor.ae.ic.ac.uk` may require `/api` to be added after the URL, if the routing on the server has been updated.
## Notes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment