From df927b7c0ea81f9d89f8df9b58659662cbb1e87fca5f291c2eb92fccd8f94f69 Mon Sep 17 00:00:00 2001 From: PioApocalypse Date: Tue, 12 May 2026 13:51:59 +0200 Subject: [PATCH] Layer class methods to list attachments up and tested --- src/classes.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/classes.py b/src/classes.py index a3a2ac3..98a4883 100644 --- a/src/classes.py +++ b/src/classes.py @@ -1,4 +1,5 @@ import os, json, requests +from getpass import getpass from APIHandler import APIHandler @@ -149,8 +150,8 @@ class Layer: def list_attachments(self): """ Returns a dictionary of all the attachments linked to the layer, where: - * Each key is the attachment's elabid; - * Each value is a dictionary containing the attachment's filename, hashname and related experiment elabid (= self.elabid). + * Each key is the attachment's progressive ID (0, 1...); + * Each value is a dictionary containing the attachment's elabid, filename, hashname and related experiment elabid (= self.elabid). Data is already in layer_data, so the API key is unrequired. Same goes for: * fetch_textual_uploads() - no arguments; @@ -162,7 +163,8 @@ class Layer: if self.uploads == []: return {} attachments = { - attachment["id"]: { + self.uploads.index(attachment): { + "id": attachment["id"], "filename": attachment["real_name"], "hashname": attachment["long_name"], "related_experiment": attachment["item_id"], @@ -329,6 +331,13 @@ class Target(Material): if __name__ == "__main__": - head = APIHandler("MyApiKey-123456789abcdef") - print(f"Example header:\n\t{head.header}\n") - print("Warning: you're not supposed to be running this as the main program.") + # head = APIHandler("MyApiKey-123456789abcdef") + # print(f"Example header:\n\t{head.header}\n") + # print("Warning: you're not supposed to be running this as the main program.") + api_key = getpass("Paste API key here [no echo]: ") + handler = APIHandler(api_key=api_key) + exp58 = handler.get_entry_from_elabid(elabid=58, entryType="experiments") + layer58 = Layer(exp58) + print(layer58.list_attachments()) + print(layer58.fetch_textual_uploads()) + print(layer58.fetch_images())