From a253c861daed44aad49ae9a195c9b0bc5d309134 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 25 Jan 2018 20:07:15 +0800 Subject: =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cgi-bin/tags.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'cgi-bin/tags.py') diff --git a/cgi-bin/tags.py b/cgi-bin/tags.py index e69de29..4e018f6 100644 --- a/cgi-bin/tags.py +++ b/cgi-bin/tags.py @@ -0,0 +1,41 @@ +#!C:\Python364\python3.exe +# -*- coding: utf-8 -*- +import sys, codecs +import cgi, cgitb +import pymysql +import issuedb +import config +from issuedb import IssueDBFactory +from config import Config + +sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) + +tag_unit_html_file = open("tag_unit.html", 'r', encoding='utf8') +tag_html_file = open("tags.html", 'r', encoding='utf8') +tag_unit_html = tag_unit_html_file.read() +tag_html = tag_html_file.read() + +db = IssueDBFactory.produce() +cursor = db.cursor() + +tagslist = "" +cursor.execute("SELECT tag.tagId, tagName, COUNT(*) FROM tag, relation WHERE \ + tag.tagId = relation.tagId GROUP BY tag.tagId;") +tags_rows = cursor.fetchall() +for tag_row in tags_rows: + tag = tag_unit_html.format(\ + tagid = tag_row[0], \ + tag_name = tag_row[1], \ + tag_count = '(' + str(tag_row[2]) + ')' \ + ) + tagslist += tag + +print("Content-type:text/html\n") +print(tag_html.format(tags = tagslist)) + +db.commit() +cursor.close() +db.close() +issue_unit_html_file.close() +page_html_file.close() + -- cgit v1.1-26-g67d0