generated from caltechlibrary/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
edit_videos.py
42 lines (37 loc) · 1.56 KB
/
edit_videos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os, json, csv, glob
from datetime import datetime
from datacite import DataCiteMDSClient, schema40
from caltechdata_api import caltechdata_edit, get_metadata
filename = "dois.csv"
# Get access token from TIND sed as environment variable with source token.bash
token = os.environ["TINDTOK"]
production = True
today = datetime.today().date().isoformat()
with open(filename, encoding="utf-8-sig") as csvfile:
filename_to_id = {}
reader = csv.DictReader(csvfile)
for row in reader:
doi = row["DOI"]
idv = doi.split("D1.")[1]
fname = row["movie"]
fpath = "cellatlas-videos/" + fname
metadata = get_metadata(idv, validate=False)
for date in metadata["dates"]:
if date["dateType"] == "Updated":
date["date"] = today
new_descr = []
for description in metadata["descriptions"]:
if description["descriptionType"] == "SeriesInformation":
description[
"description"
] = "Atlas of Bacterial and Archaeal Cell Structure"
if not description["description"].startswith("<br>Cite this record as:"):
new_descr.append(description)
metadata["descriptions"] = new_descr
new_id = []
for identifier in metadata["relatedIdentifiers"]:
if identifier["relatedIdentifier"] != None:
new_id.append(identifier)
metadata["relatedIdentifiers"] = new_id
response = caltechdata_edit(token, idv, metadata, {fpath}, {"mp4"}, production)
print(response)