This repository was archived by the owner on Oct 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfaculty_notifications.py
More file actions
53 lines (41 loc) · 2.43 KB
/
faculty_notifications.py
File metadata and controls
53 lines (41 loc) · 2.43 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
import lxml.etree as et
import json, os, re, smtplib, urllib, yaml
from book import Book
from department import Department, ChildrensLit, NotifyAboutEverything, SpanishInterestGroup
ATOM_NAMESPACE = 'http://www.w3.org/2005/Atom' # The feed element
ATOM = "{%s}" % ATOM_NAMESPACE # replaces the % and the s and replaces it follwed by anything after %
config = yaml.safe_load(open('conf/evergreen.yml'))
config.update(yaml.safe_load(open('conf/output.yml')))
departments = []
departments_config = yaml.safe_load(open('conf/departments.yml'))
for d in departments_config['departments']:
data = d.values()[0]
departments.append(Department(d.keys()[0], ','.join(data['emails']), data['regex']))
# Add custom departments to the list
departments.append(SpanishInterestGroup('test@example.com'))
departments.append(NotifyAboutEverything('test@example.com'))
departments.append(ChildrensLit('test@example.com'))
if 'shelving_location' in config:
if isinstance(config['shelving_location'], list):
loc_string = '©Location='.join(str(location) for location in config['shelving_location'])
else:
loc_string = str(config['shelving_location'])
feed_url = 'http://' + config['opac_host'] + '/opac/extras/browse/atom-full/item-age/' + config['org_unit'] + '/1/' + str(config['num_items_to_fetch']) + '?status=0&status=1&status=6&status=7©Location=' + loc_string # the URL that will return all the data we need
else:
feed_url = 'http://' + config['opac_host'] + '/opac/extras/browse/atom-full/item-age/' + config['org_unit'] + '/1/' + str(config['num_items_to_fetch']) + '?status=0&status=1&status=6&status=7'
original = et.parse(feed_url) # parse the data from that URL
books = original.findall(ATOM + 'entry') # goes through the xml file that we have in memory and finds everything that is an entry and all the entries are books
books_for_json = []
for book in books: # now that we have data from the book that are being saved in 'books'
possible_book = Book(book)
if possible_book.has_image():
books_for_json.append(possible_book.to_dict())
for department in departments:
if department.is_interested_in (possible_book):
department.mark_book_for_email (possible_book)
for department in departments:
if department.has_enough_data_for_email():
department.send_email()
exhibit_data = {'items': books_for_json} #putting in a format that exhibit js can read
with open(config['json_output_path'], 'w') as json_file:
json_file.write(json.dumps(exhibit_data))