From 4a4743bad000b2fca13e14fb5d53105e062f3b16 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 30 Jan 2018 10:51:08 +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/issue_builder.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 cgi-bin/issue_builder.py (limited to 'cgi-bin/issue_builder.py') diff --git a/cgi-bin/issue_builder.py b/cgi-bin/issue_builder.py new file mode 100644 index 0000000..caeb83b --- /dev/null +++ b/cgi-bin/issue_builder.py @@ -0,0 +1,53 @@ +#!C:\Python364\python3.exe +# -*- coding: utf-8 -*- +import sys, codecs +import cgi, cgitb +import pymysql +import issuedb +from issuedb import IssueDBFactory +sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) + +class Issue_Builder(object): + def build(issueId): + db = IssueDBFactory.produce() + cursor = db.cursor() + + tag_unit_html_file = open("tag_unit.html", 'r', encoding='utf8') + issue_html_file = open("issue.html", 'r', encoding='utf8') + issue_html = issue_html_file.read() + tag_unit_html = tag_unit_html_file.read() + + issue = "" + + try: + cursor.execute("select * from issue where issueId={0}".format(issueId)) + issue_content = cursor.fetchall() + issue_content = issue_content[0] + + if issue_content != None: + taglist = "" + cursor.execute("SELECT * FROM tag WHERE tagId IN (SELECT tagId FROM relation WHERE issueId = {0})".format(issueId)) + 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 = '' \ + ) + taglist += tag + issue = issue_html.format( \ + issueId = issue_content[0], \ + issueTitle = issue_content[1],\ + issueDescription = issue_content[2],\ + issueSolve = issue_content[3],\ + tags = taglist\ + ) + + cursor.close() + db.close() + return issue + except: + cursor.close() + db.close() + return ("Error: unable to fetch issue data \n" + e.message) + -- cgit v1.1-26-g67d0