adds test function
This commit is contained in:
47
src/main.py
Normal file
47
src/main.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os, json, requests
|
||||
from getpass import getpass
|
||||
from classes import Header
|
||||
|
||||
def get_sample_layers_data(elabid):
|
||||
'''
|
||||
Return the following data from every eLabFTW experiment linked
|
||||
to a certain sample, identified by elabid.
|
||||
|
||||
- Title of the experiment
|
||||
- Category (should check it's "PLD Deposition")
|
||||
- Layer number - if present (PLD depositions)
|
||||
- Deposition time - returns error if not present
|
||||
- Repetition rate - returns error if not present
|
||||
'''
|
||||
# header = {
|
||||
# "Authorization": apikey,
|
||||
# "Content-Type": "application/json"
|
||||
# }
|
||||
sample_data = requests.get(
|
||||
headers = header,
|
||||
url = f"https://elabftw.fisica.unina.it/api/v2/items/{elabid}",
|
||||
verify=True
|
||||
).json()
|
||||
related_experiments = sample_data["related_experiments_links"]
|
||||
result = []
|
||||
for exp in related_experiments:
|
||||
experiment_data = requests.get(
|
||||
headers = header,
|
||||
url = f"https://elabftw.fisica.unina.it/api/v2/experiments/{exp.get("entityid")}",
|
||||
verify=True
|
||||
).json()
|
||||
extra = experiment_data["metadata_decoded"]["extra_fields"]
|
||||
result.append(
|
||||
{"title": exp.get("title"),
|
||||
"layer_number": extra.get("Layer Progressive Number").get("value"),
|
||||
"category": exp.get("category_title"),
|
||||
"deposition_time": extra.get("Duration").get("value"),
|
||||
"repetition_rate": extra.get("Repetition rate").get("value")}
|
||||
)
|
||||
return result
|
||||
|
||||
apikey = getpass("Paste API key here: ") # consider replacing with .env file
|
||||
header = Header(apikey)
|
||||
header = header.dump()
|
||||
result = get_sample_layers_data(1108) # edit id at will in case of deletion of remote source
|
||||
print(json.dumps(result))
|
||||
Reference in New Issue
Block a user