Skip to content

Commit

Permalink
new version of the deposit based on the OAI-PMH service
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazztok45 committed Dec 9, 2024
1 parent baaed4e commit 0f112b0
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/swmath2swh/staging_deposit_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from swmath2swh.restApi_software_Json import process_metadata
from swmath2swh.convertSoftware_from_json_toXml import convert_json_to_xml
import lxml.etree as ET
import pandas as pd
import subprocess
import time
import tempfile
import os

env = os.environ.copy()
env['SWMATH_USER_DEPOSIT'] = os.getenv('SWMATH_USER_DEPOSIT')
env['SWMATH_PWD_DEPOSIT'] = os.getenv('SWMATH_PWD_DEPOSIT')
env['SWMATH_PWD_DEPOSIT'] = os.getenv('SWMATH_PWD_DEPOSIT')

import requests

r = requests.get("https://oai.staging.mardi4nfdi.org/oai/OAIHandler?verb=GetRecord&metadataPrefix=codemeta&identifier=oai:swmath.org:4532")

xml = r.text


# Write transformed XML to a temporary file
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.xml') as temp_file:
temp_file.write(xml)
temp_filename = temp_file.name
print(f"Temporary file created: {temp_filename}")
# Format current time for deposit status
current_time = time.localtime()
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", current_time)
dict_deposit = str({
"deposit_id": str(4532),
"deposit_status": "done",
"deposit_date": formatted_time
})

# Run the command with the temporary XML file
subprocess.run([
"swh", "deposit", "metadata-only",
"--username", env["SWMATH_USER_DEPOSIT"],
"--password", env["SWMATH_PWD_DEPOSIT"],
"--url", "https://deposit.staging.swh.network/1",
"--metadata", temp_filename,
"--format", "json"
])

0 comments on commit 0f112b0

Please sign in to comment.