-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchable_id_count
56 lines (48 loc) · 1.74 KB
/
searchable_id_count
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
import requests
from lxml import etree
#global variables
apikey = '' #use your api key from Ex Libris's Developer network
offset = '0'
response = None
course_ids = []
#*************************
#method to call course api and retrieve all courses
#parameters: none
#response: xml response of courses
#****************************
def retrieve_courses():
print("*******retrieving courses*******")
#create search parameters
payload = {
'apikey' : apikey,
'limit' : '100',
'offset' : offset,
'order_by' : 'code,section',
'direction' : 'ASC'
#'q' : 'code~2016'
}
#create request url
response = requests.get('https://api-na.hosted.exlibrisgroup.com/almaws/v1/courses/', params=payload)
print("***" + response.url + "***")
root = etree.fromstring(response.content)
return root
#************************
# first retrieve list of courses from get courses api
# then get searhable ids object and count its length
# if greater than 3, return that course code and status
#**********************
root = retrieve_courses()
response_contains_courses = etree.XPath("/courses/course")
while response_contains_courses(root):
courses = root.xpath('//courses/course')
for course in root.iter("course"):
code = course.findall(".//code")
ids = course.findall(".//searchable_ids")
for id in ids:
if len(id) > 3:
courses_with_ids.append([course.findall(".//code")[0].text,course.findall(".//status")[0].text])
offset = str(int(offset) + 100)
root = retrieve_courses()
coursefile = open('coursefile.txt', 'w')
for course_with_3 in courses_with_ids:
coursefile.write(course_with_3[0] + "," + course_with_3[1] + "\n")