-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconveris.py
More file actions
121 lines (88 loc) · 2.83 KB
/
converis.py
File metadata and controls
121 lines (88 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import requests
import os,sys
import logging
from xml.etree import ElementTree
#logging.basicConfig(level=logging.DEBUG)
class CInfoObject():
def __init__(self,cris,rtype):
self.rtype = rtype
self.cris = cris
def makeurl(self,what,rest):
ret = "{base}/ws/public/infoobject/{what}/{rtype}/{rest}".format(base=self.cris.url,rtype = self.rtype,what=what,rest = rest)
print(ret)
return ret
def makereq(self,what,rest):
url = self.makeurl(what, rest )
response = requests.get( url )
if response.status_code != 200:
response.raise_for_status()
tree = ElementTree.fromstring(response.content)
return tree
class Converis():
def __init__(self,url):
self.url = url
def pers(self,id):
return CPerson(id,self)
def orga(self,id):
return COrganization(id,self)
def card(self,id):
return CCard(id,self)
def publ(self,id):
return CPublication(id,self)
class CPerson(CInfoObject):
def __init__(self,personid,cris):
CInfoObject.__init__(self, cris, "Person")
self.id = personid
def cards(self):
tree = self.makereq('getrelated',"{0}/pers_has_card".format(self.id) )
ret=[]
for cardelem in tree.getchildren():
card = self.cris.card(cardelem.get('id'))
ret.append(card)
return ret
def get(self):
return self.makereq('get',"{0}".format(self.id) )
def publications():
raise Exception("unimplemented")
class CPublication(CInfoObject):
def __init__(self,pubid,cris):
CInfoObject.__init__(self, cris, "Publication")
self.id = pubid
def get(self):
return self.makereq('get',"{0}".format(self.id) )
class COrganization(CInfoObject):
def __init__(self,orgid,cris):
CInfoObject.__init__(self, cris, "Organization")
self.id = orgid
def cards(self):
return requests.get( "{0}/ws/public/infoobject/get/Person/{1}".format(self.cris.url,self.id) )
def people(self):
raise Exception("unimplemented")
def publications(self):
raise Exception("unimplemented")
class CCard(CInfoObject):
def __init__(self,cardid,cris):
CInfoObject.__init__(self, cris, "Card")
self.id = cardid
def publications(self):
tree = self.makereq('getrelated',"{0}/publ_has_card".format(self.id) )
ret=[]
for cardelem in tree.getchildren():
card = self.cris.publ(cardelem.get('id'))
ret.append(card)
return ret
def people(self):
raise Exception("unimplemented")
if __name__ == "__main__":
converis = Converis("https://research.utu.fi/converis")
#person = converis.pers(900334).get() # get person info
#print(person.get('id'))
cards = converis.pers(900334).cards() # get cards of person
card = cards[0]
print("card",card,card.rtype)
pubs = card.publications() # get publications of card
print(pubs)
pub = pubs[0].get()
print(ElementTree.tostring(pub, encoding='utf8', method='xml'))
import pdb; pdb.set_trace()
#publ = converis.publ(pubs[0].id) # Get publication info