THIS should solve the naming problem
new class for the Proposals, only outputs their names if name contains "Proposal ", that gets cropped out if no proposal is specified the name of the sample shall not include one
This commit is contained in:
@@ -331,6 +331,14 @@ class Target(Material):
|
||||
self.description = material_data.get("body") or ""
|
||||
|
||||
|
||||
class Proposal:
|
||||
def __init__(self, proposal_data):
|
||||
if "Proposal " in proposal_data["title"]:
|
||||
self.name = proposal_data["title"].replace("Proposal ", "")
|
||||
else:
|
||||
self.name = proposal_data["title"]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# head = APIHandler("MyApiKey-123456789abcdef")
|
||||
# print(f"Example header:\n\t{head.header}\n")
|
||||
|
||||
29
src/main.py
29
src/main.py
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
import os, json, requests, h5py
|
||||
import numpy as np
|
||||
|
||||
# import dotenv
|
||||
from getpass import getpass
|
||||
from APIHandler import APIHandler
|
||||
from classes import *
|
||||
@@ -85,6 +87,27 @@ def call_layers_from_list(elabid_list):
|
||||
return list_of_layers # list of Layer-class objects
|
||||
|
||||
|
||||
def call_proposal_from_elabid(elabid):
|
||||
try:
|
||||
proposal_data = APIHandler(api_key).get_entry_from_elabid(
|
||||
elabid, entryType="items"
|
||||
)
|
||||
proposal_category = proposal_data.get("category_title")
|
||||
# TO-DO: correct this typo on elabftw: Subtrate → Substrate.
|
||||
if (
|
||||
"Proposal" not in proposal_category
|
||||
): # to avoid that same old problem with trailing spaces
|
||||
print(f"Category of the resource: {proposal_category}.")
|
||||
raise ValueError(
|
||||
f"The referenced resource (elabid = {elabid}) is not a proposal."
|
||||
)
|
||||
else:
|
||||
proposal = Proposal(proposal_data)
|
||||
except ConnectionError as e:
|
||||
raise ConnectionError(e)
|
||||
return proposal.name # String
|
||||
|
||||
|
||||
def chain_entrypoint_to_batch(sample_object):
|
||||
"""
|
||||
Takes an Entrypoint-class object, looks at its .batch_elabid attribute and returns a Material-class object containing data on the substrate batch associated to the starting sample.
|
||||
@@ -877,8 +900,9 @@ if __name__ == "__main__":
|
||||
data = handler.get_entry_from_elabid(elabid)
|
||||
sample = Entrypoint(data)
|
||||
sample_name = sample.name.strip().replace(" ", "_")
|
||||
operative_unit = "Napoli"
|
||||
if sample.proposal:
|
||||
sample_proposal = sample.proposal.strip().replace(" ", "_")
|
||||
sample_proposal = call_proposal_from_elabid(sample.proposal)
|
||||
else:
|
||||
sample_proposal = None
|
||||
substrate_object = chain_entrypoint_to_batch(sample) # Substrate-class object
|
||||
@@ -889,7 +913,8 @@ if __name__ == "__main__":
|
||||
fn_base = (
|
||||
"nffa-di_"
|
||||
+ (f"{sample_proposal}_" if sample_proposal else "")
|
||||
+ "Napoli_"
|
||||
+ operative_unit
|
||||
+ "_"
|
||||
+ sample_name
|
||||
)
|
||||
with open(f"output/{fn_base}.json", "w") as f:
|
||||
|
||||
Reference in New Issue
Block a user