Esempio n. 1
0
def main(mode,novel):
    dbconf = gen_dbconf(mode)
    #conn = tornado.database.Connection(dbconf['host'],dbconf['db'],user=dbconf['user'],password=dbconf['passwd'])
    pool = DBPool(host=dbconf['host'],database=dbconf['db'],user=dbconf['user'],password=dbconf['passwd'],min_conn=2,max_conn=3)
    conn = pool.connect()
    if not novel:
        for key in books:
            if mode == 'pro' and books[key][3] == True:
                pass
            else:
                book_module = book_relative_import(books[key])
                book = book_module()
                path = gen_content_path(mode,book.dir_name)
                if not os.path.exists(path):
                    os.mkdir(path)
                os.chdir(path)

                book.process(conn)
    else:
        key = novel
        if mode == 'pro' and books[key][3] == True:
            pass
        else:
            book_module = book_relative_import(books[key])
            book = book_module()
            path = gen_content_path(mode,book.dir_name)
            if not os.path.exists(path):
                os.mkdir(path)
            os.chdir(path)

            book.process(conn)

    conn.close()
    pool.close()
Esempio n. 2
0
 def get(self,name,id):
     book = self.application.books[name]
     filename = '%s_%s.txt' % (name,id,)
     filename = os.path.join(gen_content_path(self.application.mode,book.dir_name),filename)
     try:
         conn = self.pool.connect()
         cur = conn.get("select id,num,title from %s where num='%s' " % (name,id,))
         together_next = conn.query("select id,num,title from %s where id>=%d order by id limit 6" % (name,int(cur['id']),))
         together = conn.query("select id,num,title from %s where id<%d order by id desc limit 3" % (name,int(cur['id']),))
         conn.close()
         together.reverse()
         together.extend(together_next)
         cur_num = 0
         for i,para in enumerate(together):
             if para['id'] == cur['id']:
                 cur_num = i
             para['num'] = book.translate_link(para['num'])
         pre_para = '0'
         next_para = '0'
         if cur_num-1>=0:
             pre_para = together[cur_num-1]['num']
         if cur_num+1<len(together):
             next_para = together[cur_num+1]['num']
         
         content = self.application.bookcontent_cache.get(filename) 
         if content == None:
             fp = open(filename,'r')
             content = fp.read()
             self.application.bookcontent_cache.set(filename,content)
         self.render('detail.html',dic={'content':filter_link(content),'back':'/'+name,'cur':cur,'together':together,'pre':pre_para,'next':next_para})
     except Exception,e:
         pass
Esempio n. 3
0
def main(mode, novel):
    dbconf = gen_dbconf(mode)
    #conn = tornado.database.Connection(dbconf['host'],dbconf['db'],user=dbconf['user'],password=dbconf['passwd'])
    pool = DBPool(host=dbconf['host'],
                  database=dbconf['db'],
                  user=dbconf['user'],
                  password=dbconf['passwd'],
                  min_conn=2,
                  max_conn=3)
    conn = pool.connect()
    if not novel:
        for key in books:
            if mode == 'pro' and books[key][3] == True:
                pass
            else:
                book_module = book_relative_import(books[key])
                book = book_module()
                path = gen_content_path(mode, book.dir_name)
                if not os.path.exists(path):
                    os.mkdir(path)
                os.chdir(path)

                book.process(conn)
    else:
        key = novel
        if mode == 'pro' and books[key][3] == True:
            pass
        else:
            book_module = book_relative_import(books[key])
            book = book_module()
            path = gen_content_path(mode, book.dir_name)
            if not os.path.exists(path):
                os.mkdir(path)
            os.chdir(path)

            book.process(conn)

    conn.close()
    pool.close()
Esempio n. 4
0
    def get(self, name, id):
        book = self.application.books[name]
        filename = "%s_%s.txt" % (name, id)
        filename = os.path.join(gen_content_path(self.application.mode, book.dir_name), filename)
        try:
            conn = self.pool.connect()
            cur = conn.get("select id,num,title from %s where num='%s' " % (name, id))
            together_next = conn.query(
                "select id,num,title from %s where id>=%d order by id limit 6" % (name, int(cur["id"]))
            )
            together = conn.query(
                "select id,num,title from %s where id<%d order by id desc limit 3" % (name, int(cur["id"]))
            )
            conn.close()
            together.reverse()
            together.extend(together_next)
            cur_num = 0
            for i, para in enumerate(together):
                if para["id"] == cur["id"]:
                    cur_num = i
                para["num"] = book.translate_link(para["num"])
            pre_para = "0"
            next_para = "0"
            if cur_num - 1 >= 0:
                pre_para = together[cur_num - 1]["num"]
            if cur_num + 1 < len(together):
                next_para = together[cur_num + 1]["num"]

            content = self.application.bookcontent_cache.get(filename)
            if content == None:
                fp = open(filename, "r")
                content = fp.read()
                self.application.bookcontent_cache.set(filename, content)
            self.render(
                "detail.html",
                dic={
                    "content": filter_link(content),
                    "back": "/" + name,
                    "cur": cur,
                    "together": together,
                    "pre": pre_para,
                    "next": next_para,
                },
            )
        except Exception, e:
            pass