summaryrefslogtreecommitdiff
path: root/cgi-bin/tags.py
blob: 4e018f66ad0165ba758268d8b1dd04ac6b432381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()