'''
Harvester for Dryad for the SHARE project

Example API call: http://www.datadryad.org/oai/request?verb=ListRecords&metadataPrefix=oai_dc
'''
from __future__ import unicode_literals

from lxml import etree
import logging

from scrapi.base import OAIHarvester

logger = logging.getLogger(__name__)


class DryadHarvester(OAIHarvester):
    short_name = 'dryad'
    long_name = 'Dryad Data Repository'
    url = 'http://www.datadryad.org/oai/request'

    base_url = 'http://www.datadryad.org/oai/request'
    property_list = ['rights', 'format', 'relation', 'date',
                     'identifier', 'type', 'setSpec']
    timezone_granularity = True

    def normalize(self, raw_doc):
        str_result = raw_doc.get('doc')
        result = etree.XML(str_result)

        status = (result.xpath('//dc:status/node()', namespaces=self.namespaces) or [''])[0]
        if str(status).lower() == 'deleted' or str(status).lower() == 'item is not available':
            logger.info('Not normalizing record with ID {}, status {}'.format(raw_doc['docID'], status))
            return None

        return super(OAIHarvester, self).normalize(raw_doc)

@@ -686,48 +686,8 @@
 c):%0A
-        str_result = raw_doc.get('doc')%0A
     
@@ -713,18 +713,22 @@
 XML(
-str_result
+raw_doc%5B'doc'%5D
 )%0A%0A 
@@ -850,19 +850,20 @@
 lower() 
-== 
+in %5B
 'deleted
@@ -867,34 +867,9 @@
 ted'
- or str(status).lower() ==
+,
  'it
@@ -888,16 +888,17 @@
 ailable'
+%5D
 :%0A      

update for clarity