1. Yang Zhang
  2. megamh

Commits

Yang Zhang  committed 48b263e

update_hot.py

  • Participants
  • Parent commits dbd5026
  • Branches default

Comments (0)

Files changed (2)

File model.py

View file
     @staticmethod
     def get_books(limit = 15, offset = 0):
         c = g.db.cursor()
-        c.execute("SELECT id,name ,last_chapter FROM book ORDER BY id LIMIT :limit OFFSET :offset",{'limit':limit,'offset':limit*offset})
+        c.execute("SELECT id,name ,last_chapter FROM book ORDER BY hot_score DESC LIMIT :limit OFFSET :offset",{'limit':limit,'offset':limit*offset})
         results = c.fetchall()
         tempbooks = []
         if(results is None):
     @staticmethod
     def get_jsonify_books(limit = 15, offset = 0):
         c = g.db.cursor()
-        c.execute("SELECT id,name ,author,intro,last_chapter FROM book ORDER BY id LIMIT :limit OFFSET :offset",{'limit':limit,'offset':limit*offset})
+        c.execute("SELECT id,name ,author,intro,last_chapter FROM book ORDER BY hot_score DESC LIMIT :limit OFFSET :offset",{'limit':limit,'offset':limit*offset})
         results = c.fetchall()
         tempbooks = []
         if(results is None):
     def get_books_bykeyword(keyword, offset = 0):
         c = g.db.cursor()
         c.execute("SELECT id,name ,last_chapter FROM book \
-            WHERE name LIKE :keyword OR author LIKE :keyword ORDER BY id ",\
+            WHERE name LIKE :keyword OR author LIKE :keyword ORDER BY hot_score DESC ",\
                 {'keyword':'%'+keyword+'%'})
         results = c.fetchall()
         tempbooks = []
         c = g.db.cursor()
         c.execute("SELECT b.id AS id,b.name AS name,b.last_chapter AS last_chapter \
                 FROM book b, label l WHERE l.name=:label AND l.bookid = b.id \
-                ORDER BY id LIMIT :limit OFFSET :offset",{'label':label,'limit':limit,'offset':limit*offset})
+                ORDER BY hot_score DESC LIMIT :limit OFFSET :offset",{'label':label,'limit':limit,'offset':limit*offset})
         results = c.fetchall()
         tempbooks = []
         if(results is None):

File update_hot.py

View file
+# -*- coding: utf-8 *-*
+import requests
+import sqlite3
+import time
+import datetime
+from model import Book,Chapter,Page
+import gevent.monkey
+gevent.monkey.patch_socket()
+import gevent
+from gevent.pool import Pool
+booklist_url ='http://m.manfun.funnylab.org:8090/mserver-web/books/category/%E7%83%AD%E9%97%A8%E8%BF%9E%E8%BD%BD/'
+import os
+DB = os.path.join(os.getcwd(),os.path.dirname(__file__),'db')
+con = sqlite3.connect(DB)
+con.row_factory = sqlite3.Row
+start = time.time()
+def get_booklist(id):
+    print booklist_url+str(id)
+    r = requests.get(booklist_url+str(id))
+    results = r.json['content']
+    return results
+        
+
+results = get_booklist(1)
+c = con.cursor()
+for result in results:
+    c.execute("UPDATE book SET hot_score= 100 WHERE name=:name",{'name':result['n']})
+        
+con.commit()
+print time.time() - start
+
+
+
+
+
+
+
+
+
+
+
+
+
+