Skip to content

Commit

Permalink
Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm104 committed May 4, 2021
1 parent 5b37d68 commit a14064d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions rda-to-bf-conversion-for-sinopia/post_to_sinopia.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
print("Copy and paste a Java Web Token for Sinopia-Stage below.")
jwt = input("> ")

yes_to_all = False

start = timer()
bar = Bar('Posting to Sinopia-Stage', max=num_of_resources, suffix='%(percent)d%%') # progress bar
for entity in resource_dict.keys():
Expand All @@ -40,7 +42,7 @@
headers = {"Authorization": f"Bearer {jwt}", "Content-Type": "application/json"}

resource_id = resource.split('.')[0]
resource_iri = f'https://api.stage.sinopia.io/resource/a{resource_id[1:]}'
resource_iri = f'https://api.stage.sinopia.io/resource/{resource_id}'

resource = open(f'../output/{currentDate}/{entity}_json/{resource}')
data = resource.read()
Expand All @@ -59,8 +61,22 @@
print("Copy and paste a Java Web Token for Sinopia-Stage below.")
jwt = input("> ")
elif error_code == 409: # conflict
print("\nWarning: IRI is not unique. Make sure you are uploading the correct data.")
break
if yes_to_all == False:
print("\nWarning: IRI is not unique. Overwrite existing data? (y/n)")
overwrite = input("> ")
if overwrite.lower() == "y":
requests.put(resource_iri, data=data.encode('utf-8'), headers = headers)
success_dict[entity].append(resource_iri)
print("\nOverwrite data for all repeated IRIs? (y/n)")
overwrite_all = input("> ")
if overwrite_all.lower() == "y":
yes_to_all = True
else:
fail_dict[entity].append((resource_id, error_code))
else:
requests.put(resource_iri, data=data.encode('utf-8'), headers = headers)
success_dict[entity].append(resource_iri)
resource_loop = False
else:
fail_dict[entity].append((resource_id, error_code))
resource_loop = False
Expand All @@ -70,7 +86,7 @@
bar.next()
bar.finish()

with open(f'post_to_sinopia_report.txt', 'w') as report:
with open(f'post_to_sinopia_report_{currentDate}.txt', 'w') as report:
currentTime = time.strftime("%Y-%m-%dT%H:%M:%S")
report.write(f"Time of report: {currentTime}\n\n---\n")
for entity in resource_dict.keys():
Expand Down

0 comments on commit a14064d

Please sign in to comment.