adds various main.py functions to call entries from elabid's
also replaces "pass" with "continue" in loops
This commit is contained in:
53
src/main.py
53
src/main.py
@@ -4,6 +4,55 @@ from APIHandler import APIHandler
|
|||||||
from classes import *
|
from classes import *
|
||||||
|
|
||||||
|
|
||||||
|
def call_entrypoint_from_elabid(elabid):
|
||||||
|
try:
|
||||||
|
sample_data = APIHandler(apikey).get_entry_from_elabid(elabid, entryType="items")
|
||||||
|
if not sample_data.get("category_title") == "Sample":
|
||||||
|
raise ValueError("The resource you selected is not a sample, therefore it can't be used as an entrypoint.")
|
||||||
|
sample_object = Entrypoint(sample_data)
|
||||||
|
except ConnectionError as e:
|
||||||
|
raise ConnectionError(e)
|
||||||
|
return sample_object # Entrypoint-class object
|
||||||
|
|
||||||
|
def call_material_from_elabid(elabid):
|
||||||
|
try:
|
||||||
|
material_data = APIHandler(apikey).get_entry_from_elabid(elabid, entryType="items")
|
||||||
|
# TO-DO: correct this typo on elabftw: Subtrate → Substrate.
|
||||||
|
if not sample_data.get("category_title") in ["PLD Target", "Substrate batch", "Subtrate batch"]:
|
||||||
|
raise ValueError(f"The referenced resource (elabid = {elabid}) is not a material.")
|
||||||
|
material_object = Material(material_data)
|
||||||
|
except ConnectionError as e:
|
||||||
|
raise ConnectionError(e)
|
||||||
|
return material_object # Material-class object
|
||||||
|
|
||||||
|
def call_layers_from_list(elabid_list):
|
||||||
|
list_of_layers = []
|
||||||
|
for elabid in elabid_list:
|
||||||
|
try:
|
||||||
|
layer_data = APIHandler(apikey).get_entry_from_elabid(elabid, entryType="experiments")
|
||||||
|
if not layer_data.get("category_title") == "PLD Deposition":
|
||||||
|
continue
|
||||||
|
layer_object = Layer(layer_data)
|
||||||
|
list_of_layers.append(layer_object)
|
||||||
|
except ConnectionError as e:
|
||||||
|
nums = [ layer.layer_number for layer in list_of_layers ]
|
||||||
|
nums.sort()
|
||||||
|
print(f"LISTA DEI LAYER PROCESSATI FINORA (in ordine sparso):\n" + str(nums))
|
||||||
|
raise ConnectionError(f"An error occurred while fetching the experiment with elabid = {elabid}:\n" +
|
||||||
|
str(e) + f"\nPlease solve the problem before retrying." + "\n\n" +
|
||||||
|
f"Last resource attempted to call: {ELABFTW_API_URL}/experiments/{elabid}"
|
||||||
|
)
|
||||||
|
return list_of_layers # list of Layer-class objects
|
||||||
|
|
||||||
|
def from_entrypoint_to_material(sample_object):
|
||||||
|
material_elabid = sample_object.batch_elabid
|
||||||
|
material_object = call_material_from_elabid(material_elabid)
|
||||||
|
return sample_object, material_object
|
||||||
|
|
||||||
|
sample_object = call_entrypoint_from_elabid(elabid)
|
||||||
|
from_entrypoint_to_material(sample_object)
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
print(f"=======================\n===== DEBUG MODE! =====\n=======================\n")
|
print(f"=======================\n===== DEBUG MODE! =====\n=======================\n")
|
||||||
ELABFTW_API_URL = "https://elabftw.fisica.unina.it/api/v2"
|
ELABFTW_API_URL = "https://elabftw.fisica.unina.it/api/v2"
|
||||||
@@ -19,14 +68,14 @@ if __name__=="__main__":
|
|||||||
eT = eT[0]
|
eT = eT[0]
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Usage: i|item|items|i[ELABID] for items, e|experiment|experiments|e[ELABID] for experiments.")
|
print("Usage: i|item|items|i[ELABID] for items, e|experiment|experiments|e[ELABID] for experiments.")
|
||||||
pass
|
continue
|
||||||
match eT:
|
match eT:
|
||||||
case "items" | "i" | "item":
|
case "items" | "i" | "item":
|
||||||
entryType = "items"
|
entryType = "items"
|
||||||
case "experiments" | "e" | "exp" | "experiment":
|
case "experiments" | "e" | "exp" | "experiment":
|
||||||
entryType = "experiments"
|
entryType = "experiments"
|
||||||
case _:
|
case _:
|
||||||
pass
|
continue
|
||||||
# This will probably be reworked in production
|
# This will probably be reworked in production
|
||||||
try:
|
try:
|
||||||
elabid = elabid
|
elabid = elabid
|
||||||
|
|||||||
Reference in New Issue
Block a user