-
Notifications
You must be signed in to change notification settings - Fork 4
/
new_book_rss.py
62 lines (57 loc) · 1.88 KB
/
new_book_rss.py
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
#!/usr/bin/python
import sys
import xml.etree.ElementTree as ET
import requests
r""""Author: Alex Cooper
Date: 07/02/2019
Title: Publish Alma RSS Feed as HTML
Requires: Python2.7"""
def parse_xml(xml):
tree = ET.fromstring(xml.content)
channel = tree.find("channel")
items = channel.findall("item")
datastring = []
for item in items:
title = item.find("title")
title = title.text
title = title.rstrip(" /")
link = item.find("link")
link = link.text
author = item.find("author")
if author is not None:
author = author.text
else:
author = "N/A"
description = item.find("description")
description = description.text
language = item.find("language")
language = language.text
form = item.find("format")
if form is not None:
form = form.text
else:
form = "N/A"
mattype = item.find("mattype")
if mattype is not None:
mattype = mattype.text
else:
mattype = "N/A"
arrival = item.find("arrivalDate")
arrival = arrival.text
linked_title = title + "|" + link + "|" + author + "|" + description + "|" + language + "|" + form + "|" + mattype + "|" + arrival
datastring.append(linked_title)
return datastring
def main():
r = requests.get("https://na03.alma.exlibrisgroup.com/rep/getFile?institution_code=01GALI_EMORY&file=newBooks&type=RSS")
result = parse_xml(r)
data_piece = ""
for x in result:
x = x.split("|")
title = x[0]
link = x[1]
author = x[2]
data_piece = data_piece + '<p><a href="' + link + '">' + title + '</a></p>' + '<p>' + author + '</p><br/>'
data_set = '<!DOCTYPE html><html><body>' + data_piece + '</body></html>'
print data_set
if __name__=="__main__":
sys.exit(main())