changeset 4:f845502cf73a

preprint methoden hinzugefuegt
author dwinter
date Tue, 30 Apr 2013 19:45:29 +0200
parents 602b6e46b176
children 245294b18a1d
files zopePubmanConnector.py
diffstat 1 files changed, 130 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/zopePubmanConnector.py	Tue Apr 30 18:34:18 2013 +0200
+++ b/zopePubmanConnector.py	Tue Apr 30 19:45:29 2013 +0200
@@ -176,6 +176,8 @@
          
         
     def getEntryFromPubman(self,escidocid):
+        """get one entry"""
+        
         escidocid=escidocid.lstrip().strip()
         h = httplib2.Http()
         cn = self.connectorString+"cqlQuery=escidoc.objid=%s&"
@@ -184,7 +186,7 @@
         resp, content = h.request(cn%escidocid)
         ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
         logging.debug(cn%escidocid)
-        
+       
         root = ET.fromstring(content)
         
         
@@ -200,6 +202,133 @@
         
     def pubmanConnectorURL(self):
         return self.connectorString
+    
+    
+    
+    def getPreprintsFromContext(self,context,limit=None,publicationType=None):
+        """get all publications des context"""
+        h = httplib2.Http()
+        
+        
+        
+        if publicationType is None:
+            cn = self.connectorString+"cqlQuery=escidoc.context.objid=%22"+context+"%22&"
+            #cn = self.connectorString+"cqlQuery=escidoc.objid=%22"+"escidoc:643455"+"%22&"
+        else:
+            cn = self.connectorString+"cqlQuery=escidoc.context.objid=%22"+context+"%22"
+            cn +="%20and%20escidoc.publication.type=%22"+publicationType+"%22&"
+        
+        cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
+        if limit:
+            cn+="&maximumRecords=%s"%limit
+  
+        logging.debug(cn)
+        resp, content = h.request(cn)
+    
+     
+        ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
+
+        root = ET.fromstring(content)
+        
+        #<escidocItem:item objid="escidoc:630782" 
+        
+        citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
+        abstractpath=".//{http://purl.org/dc/terms/}abstract"
+    
+        
+        objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
+        srcpath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/publication}source"
+        volumepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}volume"
+        
+        #linkspath=""".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content[@storage="internal-managed"]"""
+        linkspath=""".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content[@storage="external-url"]"""
+        #linkspath=".//{http://www.escidoc.de/schemas/components/0.8}component/{http://www.escidoc.de/schemas/components/0.8}content"
+        citations=root.findall(objxpath)
+        
+        ret=[]
+        for citation in citations:
+            objId = citation.get('objid')
+            
+            text = citation.find(citationxpath)
+            
+            #Get volume = preprintID
+            #  <publication:source type="series">
+            #      <dc:title>Max-Planck-Institut für Wissenschaftsgeschichte : Preprint</dc:title>
+            #      <escidoc:volume>437</escidoc:volume>
+  
+  
+
+            src= citation.find(srcpath)
+            vol = src.find(volumepath)
+            
+            
+            #get link to fulltext
+            #<escidocComponents:component objid="escidoc:644183">
+            #<escidocComponents:properties>
+            #   <prop:creation-date>2013-04-29T09:00:01.100Z</prop:creation-date>
+            #   <prop:valid-status>valid</prop:valid-status>
+            #   <prop:visibility>public</prop:visibility>
+            #   <prop:content-category>pre-print</prop:content-category>
+            #   <prop:file-name>P437.PDF</prop:file-name>
+            #   <prop:mime-type>application/pdf</prop:mime-type>
+             #  <prop:checksum>d0ccdc62d6707d934e60e9839ffe30bf</prop:checksum>
+            #   <prop:checksum-algorithm>MD5</prop:checksum-algorithm>
+            #</escidocComponents:properties>
+            #<escidocComponents:content xlink:type="simple" xlink:title="P437.PDF" storage="internal-managed"
+            #   xlink:href="http://pubman.mpiwg-berlin.mpg.de/pubman/item/escidoc:643686:3/component/escidoc:644183/P437.PDF"/>
+           #
+
+            src= citation.find(linkspath)
+            if src is not None:
+                
+                link=src.get("{http://www.w3.org/1999/xlink}href")
+                #logging.debug(src.attrib) 
+            
+            else:
+                link =""
+            
+            
+            #<dcterms:abstract xml:lang="deu">Dieser Preprint versammelt eine Auswahl von Beiträgen zum Symposium zu Ehren von Hans-Jörg Rheinbergers 65. Geburtstag. Es fand am 24.1.2011 im Max-Planck-Institute für Wissenschaftsgeschichte statt und brachte Freunde, Studenten und Kollegen von Hans-Jörg Rheinberger zusammen.</dcterms:abstract>
+            #<dcterms:abstract xml:lang="eng">In this preprint, a selection of contributions to the symposium in honor of Hans-Jörg Rheinberger’s 65th birthday is published. It took place on January 24, 2011 at the Max-Planck-Institute for the History of Science and assembled friends, students and colleagues of Hans-Jörg Rheinberger.</dcterms:abstract>
+              
+            
+            
+            abstracts = citation.findall(abstractpath)
+            
+            abstractTexts={}
+            for abstract in abstracts:
+                
+                lang = abstract.get("{http://www.w3.org/XML/1998/namespace}lang")
+                abstractTexts[lang]=abstract.text
+                
+            
+            #if abstractDE is not None:
+            #    abstactDEtext = abstractDE.text
+            #else:
+           #     abstactDEtext = ""
+            
+           # abstractEN = citation.find(abstractENpath)
+           # if abstractEN is not None:
+           #     abstactENtext = abstractEN.text
+           # else:
+            #    abstactENtext = ""
+          #
+          
+            ret.append((objId,text.text,vol.text,link,abstractTexts))
+            
+        
+        def cmpret(x,y): #sort by preprint number
+            try:
+                return -cmp(int(x[2]),int(y[2]))
+            except:
+                return 0
+            #return cmp(x[2],y[2])
+        
+        ret.sort(cmpret)
+        return ret
+    
+    
+        
         
 def manage_addZopePubmanConnectorForm(self):
         """Form for external Links"""