Skip to content

Commit

Permalink
Merge pull request #19 from uw-it-aca/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ezturner authored Aug 8, 2019
2 parents c9b1875 + d885501 commit e030f44
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions uw_bookstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from uw_bookstore.dao import Bookstore_DAO
from restclients_core.exceptions import DataFailureException
from uw_bookstore.models import Book, BookAuthor
from concurrent.futures import ThreadPoolExecutor
import json
import re

Expand Down Expand Up @@ -35,20 +36,20 @@ def get_books_by_quarter_sln(self, quarter, sln):

if len(sln_data):
for book_data in sln_data:
book = Book()
book.isbn = book_data["isbn"]
book.title = book_data["title"]
book.price = book_data["price"]
book.used_price = book_data["used_price"]
book.is_required = book_data["required"]
book.notes = book_data["notes"]
book.cover_image_url = book_data["cover_image"]
book.authors = []

for author_data in book_data["authors"]:
author = BookAuthor()
author.name = author_data["name"]
book.authors.append(author)
book = Book()
book.isbn = book_data["isbn"]
book.title = book_data["title"]
book.price = book_data["price"]
book.used_price = book_data["used_price"]
book.is_required = book_data["required"]
book.notes = book_data["notes"]
book.cover_image_url = book_data["cover_image"]
book.authors = []

for author_data in book_data["authors"]:
author = BookAuthor()
author.name = author_data["name"]
book.authors.append(author)

books.append(book)
return books
Expand All @@ -62,15 +63,17 @@ def get_books_for_schedule(self, schedule):

books = {}

for sln in slns:
try:
section_books = self.get_books_by_quarter_sln(
schedule.term.quarter, sln
)
books[sln] = section_books
except DataFailureException:
# do nothing if bookstore doesn't have sln
pass
with ThreadPoolExecutor(max_workers=10) as executor:
results = executor.map(
self.get_books_by_quarter_sln,
[schedule.term.quarter] * len(slns),
slns
)
executor.shutdown(wait=True)

for result, sln in zip(results, slns):
books[sln] = result

return books

def get_url_for_schedule(self, schedule):
Expand Down

0 comments on commit e030f44

Please sign in to comment.