Layer class methods to list attachments up and tested
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user