diff options
author | chai <chaifix@163.com> | 2018-01-30 10:51:08 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-01-30 10:51:08 +0800 |
commit | 4a4743bad000b2fca13e14fb5d53105e062f3b16 (patch) | |
tree | 5f6ccc2a2ab1c9c152faa51a16547b14a72cd67b | |
parent | 5d77906331243354710712ddf45b8bcb2152dacc (diff) |
-rw-r--r-- | cgi-bin/.issue_builder.py.un~ | bin | 0 -> 15873 bytes | |||
-rw-r--r-- | cgi-bin/.page_builder.py.un~ | bin | 0 -> 18046 bytes | |||
-rw-r--r-- | cgi-bin/.path.py.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | cgi-bin/issue_builder.py | 53 | ||||
-rw-r--r-- | cgi-bin/page_builder.py | 75 |
5 files changed, 128 insertions, 0 deletions
diff --git a/cgi-bin/.issue_builder.py.un~ b/cgi-bin/.issue_builder.py.un~ Binary files differnew file mode 100644 index 0000000..9f9c4c4 --- /dev/null +++ b/cgi-bin/.issue_builder.py.un~ diff --git a/cgi-bin/.page_builder.py.un~ b/cgi-bin/.page_builder.py.un~ Binary files differnew file mode 100644 index 0000000..85c4e86 --- /dev/null +++ b/cgi-bin/.page_builder.py.un~ diff --git a/cgi-bin/.path.py.swp b/cgi-bin/.path.py.swp Binary files differnew file mode 100644 index 0000000..d101b00 --- /dev/null +++ b/cgi-bin/.path.py.swp 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) + diff --git a/cgi-bin/page_builder.py b/cgi-bin/page_builder.py new file mode 100644 index 0000000..096fda8 --- /dev/null +++ b/cgi-bin/page_builder.py @@ -0,0 +1,75 @@ +#!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) + +class Page_Builder(object): + def build(pagen): + db = IssueDBFactory.produce() + cursor = db.cursor() + + tag_unit_html_file = open("tag_unit.html", 'r', encoding='utf8') + page_html_file = open("page.html", 'r', encoding= 'utf8') + issue_unit_html_file = open("issue_unit.html", 'r', encoding = 'utf8') + page_html = page_html_file.read() + issue_unit_html = issue_unit_html_file.read() + tag_unit_html = tag_unit_html_file.read() + + issue_unit_html_file.close() + page_html_file.close() + tag_unit_html_file.close() + + issues_list = "" + issues_count = Config.get("config", "issues_count") + issues_count = int(issues_count) + if pagen == None: + pagen = 0 + pageprev = int(pagen) - 1 + if pageprev < 0: + pageprev = 0 + pagenext = int(pagen) + 1 + try: + cursor.execute("select * from issue ORDER BY issueId DESC LIMIT {0}, {1}".format(pagen*issues_count, issues_count)) + issues_rows = cursor.fetchall() + odd = True + for row in issues_rows: + tagslist = "" + cursor.execute("select * from tag where tagId in (select tagId from \ + relation where issueId = {0})".format(row[0])) + 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 = '' + ) + tagslist += tag + issue = issue_unit_html.format(\ + issueid = row[0], \ + title = row[1], \ + description = row[2], \ + tags = tagslist, \ + oddoreven = ((odd == True) and "odd" or "even") + ) + odd = not odd + issues_list += issue + except: + print("Error: unable to fetch data") + + page = page_html.format(\ + issues = issues_list, \ + page_prev = pageprev, \ + page_next = pagenext,\ + ) + db.commit() + cursor.close() + db.close() + return page + |