def main(): user1 = User("user1", "*****@*****.**") bob = Author("UncleBob", "*****@*****.**") john = Author("john", "*****@*****.**") # author2 = Author("author2", "*****@*****.**") # author3 = Author("author3", "*****@*****.**") # author4 = Author("author4", "*****@*****.**") members = [bob, user1] for member in members: member.show_member_details() print("#" * 100) cleancode = Book("CLean Code for software engineers", 400, bob) cleanagile = Book("CLean Agile", 500, bob) python = Book("Python for Pro", 600, john) print(cleancode) bob.publish_book(cleancode) bob.publish_book(cleanagile) john.publish_book(python) print(f"Author for {cleancode} is {cleancode.author}") print(bob.published_books) print(bob.number_of_published_books) print("#" * 100) bob.buy_book(python) # john.buy_book(python) # print(bob.bought_books) # print(john.bought_books) print("*" * 100) Book.to_json() Author.to_json()
def _edit_tongji(self): # no need to set self.edited to True, because this doesn't need sync to douban try: url, datas = tongji.get_by_isbn(self.isbn) b = Book.get_by_isbn(self.isbn) b.set_tongji_info(url, datas) except Exception: # there may be errors, like this book 9787544717731, it also has e-version in TJ Lib.. pass
def post(self): isbn = self.request.get('isbn') if not isbn: return url, datas = tongji.get_by_isbn(isbn) b = Book.get_by_isbn(isbn) if b: b.set_tongji_info(url, datas) return
def _worker(tag_name): """ Retrieve the titles of books relevant to the tag_name. @returns: a list of (isbn_string, title_string) """ isbns = helper.isbns(tag_name) bs = Book.get_titles(isbns) results = [] for p in bs: if p[1] is not None: results.append((p[0], p[1].title)) return results
def post(self): isbn = self.request.get('isbn') if not isbn: return try: b = douban.get_book_by_isbn(isbn) except Exception: return if not b: return b_db = Book.get_by_isbn(isbn) if b_db: b_db.update_to(b) return
def get(self): action = self.request.get('action') if action == 'clear': # clear all data in db msg = self._clear() user = None elif action == 'load': email = auth.get_email_from_cookies(self.request.cookies) user = auth.user.User.get_by_email(email) if not user: self.redirect('/login') return # load books from douban # these books are for defense only.. ids = ["20381804", "10555435", "1432683"] for douban_id in ids: if Book.get_by_douban_id(douban_id) is None: # load it! b = douban.get_book_all_by_id(douban_id, user) b.merge_into_datastore(user) msg = "DONE" else: # default case email = auth.get_email_from_cookies(self.request.cookies) user = auth.user.User.get_by_email(email) if not user: self.redirect('/login') return msg = self._test(user) template = utils.get_jinja_env().get_template('test.html') context = { 'user': user, 'msg': msg } self.response.out.write(template.render(context)) return