Commits

Yang Zhang  committed 37e3432

add update_date for view

  • Participants
  • Parent commits 6a28b39

Comments (0)

Files changed (4)

File application.py

 @jsonify
 def get_search_booklist(keyword):
     if(keyword is None): abort(404)
-    if(len(keyword) < 2): abort(404)
     books = Book.get_jsonify_books_bykeyword(keyword)
     return make_book_json_proxy(books)
 '''test'''
     def get_jsonify_books_bykeyword(keyword, offset = 0):
         c = g.db.cursor()
         c.execute("SELECT id,name ,intro, author,last_chapter FROM book \
-            WHERE name LIKE :keyword OR author LIKE :keyword ORDER BY hot_score DESC ",\
+            WHERE name LIKE :keyword OR author LIKE :keyword\
+            ORDER BY hot_score DESC LIMIT 5",\
                 {'keyword':'%'+keyword+'%'})
         results = c.fetchall()
         tempbooks = []
     @staticmethod
     def get_book_byid(id):
         c = g.db.cursor()
-        c.execute("SELECT name, author,intro,last_chapter FROM book WHERE id=:id",{'id':id})
+        c.execute("SELECT name,update_date ,author,intro,last_chapter FROM book WHERE id=:id",{'id':id})
         result = c.fetchone()
         if(result is None):
             return None
         temppyb = Book(result['name'], None,result['author'],result['intro'],None,result['last_chapter'])
         temppyb.id = id
+        temppyb.update_date = result['update_date']
         c.execute("SELECT id,name,link FROM chapter WHERE bookid=:id ORDER BY id",{'id':id})
         results = c.fetchall()
         for result in results:

File templates/showbook.html

         <span>
             <h3>最近更新:<span clas='span6'>更新至{{book.last_chapter}}</span></h3>
         </span>
+        {%if book.update_date%}
+        <span>
+            <h3>更新时间:<span clas='span6'>{{book.update_date.replace(second=0, microsecond=0)}}</span></h3>
+        </span>
+        {%endif%}
     </div>
 </div>
 <div class='offset2'><h3>简介</h3>

File update_comic.py

     print booklist_url+str(id)
     r = requests.get(booklist_url+str(id))
     results = r.json['content']
+    results.sort(reverse = True)
     for result in results:
         threads.append(gevent.spawn(update_books,result))
     gevent.joinall(threads)
     c.execute('SELECT id,last_chapter FROM book WHERE name=:name',\
         {'name':name})
     check_result = c.fetchone()
-    if(check_result['last_chapter'] == last_chapter):
+    if(check_result is None \
+        or check_result['last_chapter'] == last_chapter):
         return
     #print name
     r = requests.get(book_url + oid)