from LOGS import LOGS
from LOGS.Entities import SampleRequestParameter
from LOGS.Entities.ProjectRequestParameter import (
ProjectRequestParameter,
ProjectSortingOptions,
)
from LOGS.Entity.EntitySortBy import SortDirection
# Connect to LOGS
logs = LOGS()
# We assume that there is a sample called "LOGS-Py generated" exists and retrive it from the server
sample = logs.samples(SampleRequestParameter(searchTerm="LOGS-Py generated")).first()
# raise exception if the sample does not exist
if not sample:
raise Exception("Could not find the sample")
# We want to assign the sample to the newest project in the LOGS instance.
newest_project = logs.projects(
ProjectRequestParameter(
sortBy=[(ProjectSortingOptions.ENTERED_ON, SortDirection.DESC)]
)
).first()
# raise exception if the newest project does not exist
if not newest_project:
raise Exception("Could not find the newest project")
if sample.projects:
sample.projects.append(newest_project.toMinimal())
else:
sample.projects = [newest_project]
# We modify the name of the sample
sample.name = "LOGS-Py modified sample"
# The above modifications are still local. We can push them to the logs instance using the logs.update method.
logs.update(sample)