Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doi_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys

import os.path
from utils.gsheets_manager import retrieve_doi_mets, write_doi_mets
from utils.sheets_creds_builder import refresh_credentials
from utils.doi_mets import JournalMetsHandler, DoiMinter
Expand Down Expand Up @@ -47,6 +48,7 @@
)
print("Writing proposed DOIs to patron metadata sheet...")
write_doi_mets(sys.argv[3], dois)
DoiMinter.doi_registration(issue_level_mets, dois)
print("Complete.")

elif sys.argv[1] == "retrieve-fda-handles":
Expand All @@ -61,6 +63,7 @@
6. Report that write-out was successful
"""


elif sys.argv[1] == "build-xml":
print("Retrieving metadata from template sheet...")
issue_level_mets = retrieve_doi_mets(sys.argv[3], "mets_main")
Expand Down
75 changes: 72 additions & 3 deletions utils/doi_mets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import os.path
from utils.gsheets_manager import retrieve_doi_mets
from random import random
import uuid
from datetime import datetime
from global_settings import ALLOWED_CHARS, DEPOSITOR_NAME, DEPOSITOR_EMAIL_ADDRESS
from global_settings import (
ALLOWED_CHARS, DEPOSITOR_NAME, DEPOSITOR_EMAIL_ADDRESS,
G_TOKEN_FILE,
MAIN_DOI_REGISTRY_SHEET,
REGISTRY_TEMPLATE_TITLE_COLUMN_RANGE
)
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
import re


Expand Down Expand Up @@ -339,11 +347,72 @@ def mint(reg_sheet_id, number_needed):
break
return generated_dois

def doi_registration(list_dois,title="",journal="",date="",unit="",contact="",url="",handle=""):
def doi_registration(key, list_dois, unit=None, contact=None, url=None):
"""
This function should write the DOIs passed as a pararamter (e.g. list of DOIs) to the registry GSheet
In addition to the list of DOIs to register, it should include a series of optional parameters to write to the other columns of the sheet
as well as auto-increment column A. The write step should be treated as an append to the values already in the GSheet to prevent accidentally
overwriting what is there.
:return:
"""
"""
Journal = key[2][0]
Volume = key[5][3]
Issue = key[5][4]
Journal_information = f'{Journal}, {Volume} {Issue}'
# Issue Contents Metadata
Issue = key[8:]

if os.path.exists(G_TOKEN_FILE):
creds = Credentials.from_authorized_user_file(G_TOKEN_FILE)

service = build("sheets", "v4", credentials=creds)
sheet = service.spreadsheets()

# Get the value from MAIN_DOI_REGISTRY_SHEET
result = sheet.values().get(spreadsheetId=MAIN_DOI_REGISTRY_SHEET,
range=REGISTRY_TEMPLATE_TITLE_COLUMN_RANGE).execute()
column_values = result.get("values", [])
# Find where the blank in MAIN_DOI_REGISTRY_SHEET begins
index = column_values[-1][0]

# Get current date
current_date = datetime.now()
formatted_date = current_date.strftime('%Y-%m-%d')

# Add Journal data to MAIN_DOI_REGISTRY_SHEET
doi_index = -1
index = int(index) + 1
new_value = [index] + [Journal_information] + [Journal_information] + [formatted_date] + [unit, contact,
url] + [
list_dois[doi_index]]
print(new_value)
body = {
'values': [new_value]
}

sheet.values().append(
spreadsheetId=MAIN_DOI_REGISTRY_SHEET,
range=REGISTRY_TEMPLATE_TITLE_COLUMN_RANGE,
valueInputOption="RAW",
body=body,
).execute()

# Add Issue data to MAIN_DOI_REGISTRY_SHEET row by row
doi_index = 0
for row in Issue:
index = int(index) + 1
new_value = [index] + [row[1]] + [Journal_information] + [formatted_date] + [unit, contact, url] + [
list_dois[doi_index]]
doi_index = doi_index + 1
print(new_value)
body = {
'values': [new_value]
}

sheet.values().append(
spreadsheetId=MAIN_DOI_REGISTRY_SHEET,
range=REGISTRY_TEMPLATE_TITLE_COLUMN_RANGE,
valueInputOption="RAW",
body=body,
).execute()

1 change: 1 addition & 0 deletions utils/sheets_creds_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ def refresh_credentials():
with open('doi_workflow_token.json', 'w') as token:
token.write(creds.to_json())