Skip to content

Commit

Permalink
Add update date to eprints script
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorrell committed Dec 4, 2019
1 parent f61fa53 commit f875729
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ Example usage:

python run_archives_report.py accession_report accession.csv -subject "Manuscript Collection"

### Update Eprints

Perform update options using the Eprints API. Supports url updates to https for
resolver field, special character updates, and adjusting the item modified date
(which also regenerates the public view of the page).

Example usage:

python run_eprints_updates.py update_date authors -recid 83420 -user tmorrell -password

### CODA Reports

Runs reports on Caltech Library repositories. Current reports:
Expand Down
1 change: 1 addition & 0 deletions ames/matchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
from .datacite import submit_report
from .eprints import resolver_links
from .eprints import special_characters
from .eprints import update_date
12 changes: 12 additions & 0 deletions ames/matchers/eprints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
import re
from datetime import datetime
from progressbar import progressbar
from ames.harvesters import get_eprint
from ames.harvesters import get_records
Expand Down Expand Up @@ -42,6 +43,17 @@ def resolver_links(source, keys, outfile=None):
print(response)


def update_date(source, recid):
url = source + "/rest/eprint/" + str(recid) + "/lastmod.txt"
now = datetime.utcnow()

dt_string = now.strftime("%Y-%m-%d %H:%M:%S")
print(dt_string)
headers = {"content-type": "text/plain"}
response = requests.put(url, data=dt_string, headers=headers)
print(response)


def replace_character(metadata, field, replacements):
"""replace characters based on a dictionary"""
new = None
Expand Down
7 changes: 6 additions & 1 deletion run_eprints_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from py_dataset import dataset
from ames.harvesters import get_caltechfeed
from ames.harvesters import get_eprint_keys
from ames.matchers import resolver_links, special_characters
from ames.matchers import resolver_links, special_characters, update_date

if __name__ == "__main__":
if os.path.isdir("data") == False:
Expand All @@ -17,6 +17,7 @@
"repository",
help="options: thesis, authors; others including test only work if using eprints source)",
)
parser.add_argument("-recid", help="Eprints recid")
parser.add_argument(
"-test",
help="Uses feeds data and writes report of what would be changed, but makes no changes. Provide output file name",
Expand Down Expand Up @@ -44,5 +45,9 @@
file_out = None
if args.update_type == "resolver":
resolver_links(source, keys, file_out)
elif args.update_type == "update_date":
update_date(source, args.recid)
elif args.update_type == "special_characters":
special_characters(source, keys, file_out)
else:
print(f"Report {args.update_type} not known")

0 comments on commit f875729

Please sign in to comment.