Skip to content

Commit

Permalink
Add content provider for YoDa.
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Jul 4, 2017
1 parent 54f6ca0 commit c7e0bb7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
60 changes: 60 additions & 0 deletions moai/yoda.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -63,5 +64,3 @@
],
test_suite='moai.test.suite'
)


0 comments on commit c7e0bb7

Please sign in to comment.