diff --git a/moai/yoda.py b/moai/yoda.py new file mode 100644 index 0000000..f538cca --- /dev/null +++ b/moai/yoda.py @@ -0,0 +1,60 @@ +from lxml import etree +from datetime import datetime, timedelta + +from moai.utils import XPath + + +class YodaContent(object): + def __init__(self, provider): + self.provider = provider + self.id = None + self.modified = None + self.deleted = None + self.sets = None + self.metadata = None + + def update(self, path): + doc = etree.parse(path) + xpath = XPath(doc, nsmap={}) + + self.root = doc.getroot() + + id = xpath.string('//Project_ID') + self.id = 'oai:%s' % id + self.modified = datetime.now() - timedelta(days=1) + self.deleted = True + + author_data = [] + + # Add creator of dataset. + author_data.append({'name': [xpath.string('//Creator')], + 'role': [u'aut']}) + + # Add all contributors to dataset. + for num, el in enumerate(xpath('//Contributor'), 1): + contributor = [xpath.string('//Contributor[%d]' % num)] + author_data.append({'name': contributor, + 'role': [u'aut']}) + + # Add metadata of dataset. + self.metadata = {'identifier': [id], + 'title': [xpath.string('//Project_Title')], + 'subject': [xpath.string('//Project_Description')], + 'description': [xpath.string('//Project_Description')], + 'creator': [d['name'][0] for d in author_data], + 'author_data': author_data, + 'language': [xpath.string('//Language_dataset')], + 'date': [xpath.string('//Embargo')]} + + # Clean dataset type. + type = xpath.string('//Dataset_Type') + type = type.replace(" ", "_") + + # Specify dataset. + self.sets = {type: + {u'name':xpath.string('//Dataset_Title'), + u'description':xpath.string('//Dataset_Description')}} + + published = xpath.string('//Publish_Metadata') + if published == 'Yes': + self.deleted = False diff --git a/setup.py b/setup.py index 37c432c..bb92b60 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,8 @@ 'main=moai.wsgi:app_factory' ], 'moai.content':[ - 'moai_example=moai.example:ExampleContent' + 'moai_example=moai.example:ExampleContent', + 'moai_yoda=moai.yoda:YodaContent' ], 'moai.database':[ 'sqlite=moai.database:SQLDatabase', @@ -63,5 +64,3 @@ ], test_suite='moai.test.suite' ) - -