comparison zopePubmanConnector.py @ 6:49abb91d6c6a

getPreprints gibt nun hash mit metadate zurueck
author dwinter
date Fri, 03 May 2013 14:26:13 +0200
parents 245294b18a1d
children 06befe15f66f
comparison
equal deleted inserted replaced
5:245294b18a1d 6:49abb91d6c6a
13 import urllib 13 import urllib
14 import re 14 import re
15 import xml.etree.ElementTree as ET 15 import xml.etree.ElementTree as ET
16 import json 16 import json
17 import logging 17 import logging
18
19
20 cacheFolder ="/var/tmp/.cacheWWW"
18 21
19 def zptFile(self, path, orphaned=False): 22 def zptFile(self, path, orphaned=False):
20 """returns a page template file from the product""" 23 """returns a page template file from the product"""
21 if orphaned: 24 if orphaned:
22 # unusual case 25 # unusual case
58 return pt() 61 return pt()
59 62
60 63
61 def getPublications(self,personID,limit=None,publicationType=None): 64 def getPublications(self,personID,limit=None,publicationType=None):
62 """get all publications der personID""" 65 """get all publications der personID"""
63 h = httplib2.Http() 66 h = httplib2.Http(cacheFolder)
64 67
65 68
66 69
67 if publicationType is None: 70 if publicationType is None:
68 cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22&" 71 cn = self.connectorString+"cqlQuery=escidoc.any-identifier=%22"+personID+"%22&"
162 if query!="": 165 if query!="":
163 query=query+"AND (%s)"%ctxquery 166 query=query+"AND (%s)"%ctxquery
164 else: 167 else:
165 query="(%s)"%ctxquery 168 query="(%s)"%ctxquery
166 169
167 h = httplib2.Http() 170 h = httplib2.Http(cacheFolder)
168 171
169 logging.debug(cn%query) 172 logging.debug(cn%query)
170 resp, content = h.request(cn%query) 173 resp, content = h.request(cn%query)
171 174
172 ET.register_namespace("dcterms", "http://purl.org/dc/terms/") 175 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
199 202
200 def getEntryFromPubman(self,escidocid): 203 def getEntryFromPubman(self,escidocid):
201 """get one entry""" 204 """get one entry"""
202 205
203 escidocid=escidocid.lstrip().strip() 206 escidocid=escidocid.lstrip().strip()
204 h = httplib2.Http() 207 h = httplib2.Http(cacheFolder)
205 cn = self.connectorString+"cqlQuery=escidoc.objid=%s&" 208 cn = self.connectorString+"cqlQuery=escidoc.objid=%s&"
206 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending" 209 cn +="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending"
207 210
208 resp, content = h.request(cn%escidocid) 211 resp, content = h.request(cn%escidocid)
209 ET.register_namespace("dcterms", "http://purl.org/dc/terms/") 212 ET.register_namespace("dcterms", "http://purl.org/dc/terms/")
227 230
228 231
229 232
230 def getPreprintsFromContext(self,context,limit=None,publicationType=None): 233 def getPreprintsFromContext(self,context,limit=None,publicationType=None):
231 """get all publications des context""" 234 """get all publications des context"""
232 h = httplib2.Http() 235 h = httplib2.Http(cacheFolder)
233 236
234 237
235 238
236 if publicationType is None: 239 if publicationType is None:
237 cn = self.connectorString+"cqlQuery=escidoc.context.objid=%22"+context+"%22&" 240 cn = self.connectorString+"cqlQuery=escidoc.context.objid=%22"+context+"%22&"
254 257
255 #<escidocItem:item objid="escidoc:630782" 258 #<escidocItem:item objid="escidoc:630782"
256 259
257 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation" 260 citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation"
258 abstractpath=".//{http://purl.org/dc/terms/}abstract" 261 abstractpath=".//{http://purl.org/dc/terms/}abstract"
259 262 issuedpath=".//{http://purl.org/dc/terms/}issued"
263
264 creatorpath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/publication}creator/{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}person"
265 familyNamepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}family-name"
266 givenNamepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}given-name"
267
268
269 titlepath=".//{http://purl.org/dc/elements/1.1/}title"
260 270
261 objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item" 271 objxpath=".//{http://www.escidoc.de/schemas/item/0.8}item"
262 srcpath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/publication}source" 272 srcpath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/publication}source"
263 volumepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}volume" 273 volumepath=".//{http://escidoc.mpg.de/metadataprofile/schema/0.1/types}volume"
264 274
320 abstractTexts={} 330 abstractTexts={}
321 for abstract in abstracts: 331 for abstract in abstracts:
322 332
323 lang = abstract.get("{http://www.w3.org/XML/1998/namespace}lang") 333 lang = abstract.get("{http://www.w3.org/XML/1998/namespace}lang")
324 abstractTexts[lang]=abstract.text 334 abstractTexts[lang]=abstract.text
325 335
326 336
327 #if abstractDE is not None: 337
328 # abstactDEtext = abstractDE.text 338 authorsTags = citation.findall(creatorpath)
329 #else:
330 # abstactDEtext = ""
331
332 # abstractEN = citation.find(abstractENpath)
333 # if abstractEN is not None:
334 # abstactENtext = abstractEN.text
335 # else:
336 # abstactENtext = ""
337 #
338 339
339 ret.append((objId,text.text,vol.text,link,abstractTexts)) 340 authors=[]
341 for author in authorsTags:
342
343 gn= author.find(givenNamepath).text
344 fn= author.find(familyNamepath).text
345
346 authors.append((fn,gn))
347
348
349 titleTag = citation.find(titlepath)
350
351
352
353 if titleTag is not None:
354 title = titleTag.text
355 else:
356 title=""
357
358
359 issuedTag = citation.find(issuedpath)
360
361
362
363 if issuedTag is not None:
364 issued = issuedTag.text
365 else:
366 issued=""
367
368
369
370 ret.append((objId,{"citation":text.text,"volume":vol.text,
371 "link":link,
372 "abstracts":abstractTexts,
373 "authors":authors,
374 "title":title,
375 "year":issued}))
340 376
341 377
342 def cmpret(x,y): #sort by preprint number 378 def cmpret(x,y): #sort by preprint number
343 try: 379 try:
344 return -cmp(int(x[2]),int(y[2])) 380 return -cmp(int(x[2]),int(y[2]))