Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double uri quilifier and http / https fix #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
21 changes: 15 additions & 6 deletions src/ssoarMetaFileFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ def __init__(self, rootDir, targetDir):

def formatMetadata(self):
for filename in os.listdir(self.rootDir):
#print " F: " + filename
for recordId, recordMetadata in self.parseMetadata(os.path.join(self.rootDir, filename)):
#print " Rid: " + recordId
#print " 2F: " + filename
self.writeToFile(recordId, recordMetadata)

def getRootElements(self, root):
return root

def writeToFile(self, recordId, recordMetadata):
towrite = ElementTree.ElementTree(recordMetadata)
print " self.targetDir: " + self.targetDir
print " recordId: " + recordId
towrite.write(os.path.join(self.targetDir, recordId + ".xml"), "utf-8")
self.counter += 1
print "wrote %s (file no. %d)." %(os.path.join(self.targetDir, recordId + ".xml"), self.counter)
Expand All @@ -38,10 +43,13 @@ def parseMetadata(self, filename):
for dcElement in part.getchildren():
for dcValue in dcElement.getchildren():
if dcValue.get("qualifier") == "uri":
recordId = dcValue.text.replace("http://www.ssoar.info/ssoar/handle/document/", "")
yield recordId, attribute
except:
print "Caught error in filename %s." %filename
if "handle" in dcValue.text:
recordId = dcValue.text.replace("http://www.ssoar.info/ssoar/handle/document/", "")
recordId = recordId.replace("https://www.ssoar.info/ssoar/handle/document/", "")
yield recordId, attribute
except Exception as ee:
print "Caught error in filename " + filename
print " E: " + str(ee)

def usage():
print "usage: ssoarMetaFileFormatter.py <inputDir> <outputDir>"
Expand All @@ -52,6 +60,7 @@ def usage():
outputDir = sys.argv[2]
formatter = ssoarMetaFileFormatter(inputDir, outputDir)
formatter.formatMetadata()
except:
usage()
except Exception as e:
usage()
print " E: " + str(e)