用python改变td类

时间:2015-02-26 10:40:46

标签: python html css

您好我有执行sql查询的Python代码。然后我把它放在html表中。我为html td做了css。我需要的是用这个pyton改变html TD类来改变td line的颜色。

#!/opt/nagios/python/bin/python
# -*- coding: cp1251 -*-

import sys
import errno
import psycopg2

not_needed = ['Ðàäèîïîêðûòèå', 'Êîíòåíò-óñëóãè', 'Ïðîåêò NPS - æàëîáû', 'Ïåðåêëþ÷åíèå ñ Àóòñîðñèíãà']

conn = psycopg2.connect(database="statistic", user="foris-mscp", password="foris-mscp")
cur = conn.cursor()

if len(sys.argv) != 5 or (sys.argv[1] != "all" and not sys.argv[1].isdigit()) or not sys.argv[2].isdigit() or not sys.argv[3].isdigit() or sys.argv[4] not in ["warning", "critical"]:
        print "Wrong or empty argument(s) given"
        sys.exit(2)
else:
        warn_threshold = int(sys.argv[2])
        crit_threshold = int(sys.argv[3])
        current_check = sys.argv[4]

        ex_code = 0
        if current_check == "warning":
                ex_code = 1
                where_statement = "complains_qty >= %s AND complains_qty < %s" % (warn_threshold, crit_threshold)

        elif current_check == "critical":
                ex_code = 2
                where_statement = "complains_qty >= %s" % (crit_threshold)

        if sys.argv[1] == "all":
                #ïðîâåðÿåì âñå æàëîáû
                cur.execute("SELECT subcategory_name, complains_qty FROM cms_data_view WHERE %s AND dt IN (SELECT max(dt) FROM cms_data_view GROUP BY subcategory_id)" % (where_statement))
                if cur.rowcount > 0:
                        result = []
                        for row in cur.fetchall():
                                if(row[0] not in not_needed):
                                        result.append("Ïî óñëóãå '%s' çàôèêñèðîâàíî %s æàëîá" % (row[0], row[1]))

                        if len(result) > 0:
                                print "<br>".join(result)
                                sys.exit(ex_code)
                        else:
                                sys.exit(0)
 else:
                cur.execute("SELECT subcategory_name, complains_qty FROM cms_data_view WHERE subcategory_id     = %s AND %s AND dt IN (SELECT max(dt) FROM cms_data_view GROUP BY subcategory_id)" % (int(sys.argv[1]), where_statement))
                if cur.rowcount > 0:
                        result = []
                        for row in cur.fetchall():
                                result.append("Ïî óñëóãå '%s' çàôèêñèðîâàíî %s æàëîá" % (row[0], row[1]))

                        if len(result) > 0:
                                print "<br>".join(result)
                                sys.exit(ex_code)
                        else:
                                sys.exit(0)

我试过把它放在这里 - print "<br> <td class="statusWARNING>".join(result)  但它不起作用。

1 个答案:

答案 0 :(得分:0)

我认为 statusWARNING 之前的引号正在抛弃。 尝试使用斜杠\

转义它
cur.execute("SELECT subcategory_name, complains_qty FROM cms_data_view WHERE subcategory_id     = %s AND %s AND dt IN (SELECT max(dt) FROM cms_data_view GROUP BY subcategory_id)" % (int(sys.argv[1]), where_statement))
                if cur.rowcount > 0:
                        result = []
                        for row in cur.fetchall():
                                result.append("По услуге '%s' зафиксировано %s жалоб" % (row[0], row[1]))

                        if len(result) > 0:
                                print "<br> <td class=\"statusWARNING>".join(result)
                                sys.exit(ex_code)
                        else:
                                sys.exit(0)