diff options
author | chai <chaifix@163.com> | 2018-07-10 22:01:22 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-07-10 22:01:22 +0800 |
commit | 1275e68efa680e55fd29a377c9c58c59bb7f235e (patch) | |
tree | c585d7402af76ad0ccd295b218205708012addb4 /cgi-bin/page.py | |
parent | 5d323b7430c446ceb81c2de52d9a1d28c7f34e52 (diff) |
更新
Diffstat (limited to 'cgi-bin/page.py')
-rw-r--r-- | cgi-bin/page.py | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/cgi-bin/page.py b/cgi-bin/page.py index 4b03bd4..2200390 100644 --- a/cgi-bin/page.py +++ b/cgi-bin/page.py @@ -1,11 +1,62 @@ -#!D:/Programs/Python/Python36/python.exe +#!D:/Programs/Python3/python.exe # -*- coding: utf-8 -*- import cgi, cgitb import pymysql import sys, codecs import configparser, codecs +import connect +from connect import Connect +import whisper +from whisper import Whisper +import config +from config import Config +import path +from path import Path -class PageBuilder(object): - def build(pagen): - +sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) +_url = Config.get("route", "url") +_static = Config.get("route", "static") + +page_file = open(Path.template("page.html"), 'r', encoding="utf8") +page_templ = page_file.read() +page_file.close() + +pagen = cgi.FieldStorage().getvalue('p') +if pagen == None: + pagen = 0 +pageprev = int(pagen) - 1 +if pageprev < 0: + pageprev = 0 +pagenext = int(pagen) + 1 + +# class PageBuilder(object): +# def build(pagen): +print("Content-type:text/html\n") + +db = Connect.produce() +cursor = db.cursor() + +query_allwhisper = "select * from whisper" +cursor.execute(query_allwhisper) + +_whispers="" +whispersdata = cursor.fetchall() +odd = True +for whisper in whispersdata: + _whispers += Whisper.build(whisper[0], whisper[1], odd) + odd = not odd + +page = page_templ.format(\ + url = _url, + static = _static, + whispers = _whispers, + page_prev = pageprev, + page_next = pagenext +) + +print(page) + +db.commit() +cursor.close() +db.close() |