-
Notifications
You must be signed in to change notification settings - Fork 13
Samples
Hannah Sistrunk edited this page Sep 14, 2020
·
6 revisions
from asnake.aspace import ASpace
from openpyxl import Workbook
repo = ASpace().repositories(2)
# authenticates the session
auth = requests.post('{baseURL}/users/{user}/login?password={password}&expiring=false'.format(**dictionary)).json()
session = auth["session"]
headers = {'X-ArchivesSpace-Session':session}
# The Parameters of the Fiscal Year
dateStart = "2017-06-30"
dateEnd = "2018-07-01"
#make a new spreadsheet
wb = Workbook()
ws = wb.active
# Spreadsheet Header
ws.append(["Accession ID", "Accession Date", "Collection ID", "Title", "Extent", "Extent Type", "Content Description"])
# Loop though all accessions
for accession in repo.accessions:
# The date of the accession
accessionDate = accession.accession_date
# Check if accession falls within the fiscal year
if accessionDate > dateStart and accessionDate < dateEnd:
# start a row to add for an accession
row = []
# Accession ID
if "id_1" in dir(accession):
accessionID = accession.id_0 + "." + accession.id_1
else:
accessionID = accession.id_0
row.append(accessionID)
# print ID and title to console
if "title" in dir(accession):
print (accessionID + " - " + accession.title)
else:
print (accessionID + " - ")
# Accession Date
row.append(accession.accession_date)
# Collection ID
if len(accession.related_resources) > 0:
collectionList = []
for collection in accession.related_resources:
collectionList.append(collection.id_0)
row.append(", ".join(collectionList))
else:
row.append("")
# Title
if "title" in dir(accession):
row.append(accession.title)
else:
row.append("")
# Extents
if len(accession.extents) > 0:
extentNumber = []
extentType = []
for extent in accession.extents:
extentNumber.append(extent.number)
extentType.append(extent.extent_type)
row.append(", ".join(extentNumber))
row.append(", ".join(extentType))
else:
row.append("")
row.append("")
# Content Description
if "content_description" in dir(accession):
row.append(accession.content_description)
else:
row.append("")
# Add the row to the worksheet
ws.append(row)
# Save the Spreadsheet
wb.save("accessionsFY2017.xlsx")