Last active
July 24, 2022 12:48
-
-
Save Abbe98/27079ce4813d6d1e30b9d213f240b203 to your computer and use it in GitHub Desktop.
Python script for importing CSV to ugc.kulturarvsdata.se
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from ksamsok import KSamsok | |
from sochugc import UGC | |
api_key = input('Please enter your API key: ') | |
file_name = input('The name of input CSV: ') | |
username = input('Which username would you like to use: ') | |
soch = KSamsok() | |
ugc = UGC(key=api_key) | |
with open(file_name, newline='') as csvfile: | |
spamreader = csv.reader(csvfile, delimiter=',') | |
for i, row in enumerate(spamreader): | |
# validation and formatting of SOCH URI | |
if not soch.formatUri(row[0], 'rawurl'): | |
continue | |
# if there is a forth comment column | |
comment = None | |
if len(row) == 4: | |
comment = row[3] | |
# SOCH URI, relation, target URI, username, and optional comment | |
print(i, soch.formatUri(row[0], 'rawurl'), row[1], row[2], username, comment) | |
ugc.create_item_relation(soch.formatUri(row[0], 'rawurl'), row[1], row[2], username, comment) | |
print('DONE') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment