コード例 #1
0
ファイル: readtxt.py プロジェクト: chrisbbenyard/bookreader
def task_update_catalog(catalog):
  catalog_url = catalog.key().name()
  last_check = Database.LastCheck.get_by_key_name(catalog_url)
  
  if last_check:
    if last_check.is_more_minutes(10):
      last_check.put()
    else:
      return False        
  else:
    last_check = Database.LastCheck.get_or_insert(catalog_url)
  # 开始更新
  new_catalog_info = BookParser.get_data(catalog_url)
  if (new_catalog_info['chapter_url_list'] != catalog.chapter_url_list) and (len(new_catalog_info['chapter_url_list'])>0):
    # 更新最后更新时间
    new_catalog_info.update( BookParser.get_data(catalog.cover_url) )
    catalog.put_info(new_catalog_info)
    catalog.update_bookmarks()
    return True
  else:
    return False
コード例 #2
0
ファイル: readtxt.py プロジェクト: chrisbbenyard/bookreader
def task_get_chapter(url, catalog, reload = False):
  if not url in catalog.chapter_url_list:
    return 'Error: The url does not exist!'
  
  
  chapter_url = catalog.chapter_url_prefix + url  
  chapter = Database.Chapter.get_or_insert(chapter_url, catalog_ref = catalog)
  
  if chapter:
    if reload or (not chapter.content_list) or (chapter.content_type != 'text'): 
      chapter_info = BookParser.get_data(chapter_url)
      chapter.put_info(chapter_info)
    return chapter
  else:
    return "Error: Can't get the chapter!"
コード例 #3
0
ファイル: readtxt.py プロジェクト: chrisbbenyard/bookreader
def task_add_book(user_info, url):
  if user_info == None:      
    return 'Error: User is not correct!'

  user = user_info['user']
  
  (book_info, parser) = BookParser.get_parser(url)

  if book_info == None:
    return 'Error: URL is not supported!'
  
  url_type = book_info['url_type']
  
  # 首先加入书页信息,获取必备的数据
  if book_info['cover_url']:
    book_info.update( BookParser.get_data(book_info['cover_url']) )
  
  # 必须有作者,标题,目录页,章节地址前缀
  # 如果没有这些就没法构造 Book 和 Catalog
  if not ( book_info.has_key('author') and 
           book_info.has_key('title') and 
           book_info.has_key('catalog_url') and 
           book_info.has_key('chapter_url_prefix') ):      
    return 'Error: The necessary information is not complete!' + '<br />' + str(book_info)
  author = book_info['author']
  title = book_info['title']
  catalog_url = book_info['catalog_url']
 

  # Book
  book_key_name = Database.generate_book_key_name(author, title)    
  book = Database.Book.get_or_insert(book_key_name)  
    
  # Catalog
  catalog_key_name = catalog_url
  catalog = Database.Catalog.get_or_insert(catalog_key_name, book_ref = book)
  last_check = Database.LastCheck.get_or_insert(catalog_url)
  # 判断是否需要重新获取目录
  if not book_info['last_url'] in catalog.chapter_url_list:    # 包括了catalog 是新生成的,即使last_url是None
    # 获取目录
    book_info.update( BookParser.get_data(catalog_url) )
    catalog.put_info(book_info)     
    last_check.put()
    
  # 用户想要添加的章节
  curr_url = None
  # 具体章节
  if url_type == 'chapter':     
    curr_url = url
  # 书页
  elif url_type == 'cover':       
    if book_info.has_key('last_url'):
      curr_url = book_info['last_url']
  # 目录
  elif url_type == 'catalog':
    curr_index = catalog.find_first_chapter_index()
    if curr_index != None:
      curr_url = catalog.chapter_url_list[curr_index]
   
  bookmark = Database.Bookmark(user_ref = user, book_ref = book, catalog_ref = catalog)
  bookmark.update_info( user_ref = user, book_ref = book, catalog_ref = catalog, curr_url = curr_url)