import os, sys, \ pymysql, urlparse3 def application(environ, start_response): #sys.stdout._encoding = 'utf-8' status = '200 OK' # проверяем наличие параметров в запросе и всяко-разно реагируем if environ['QUERY_STRING'] == '': output = bytes((header() + body() + footer()).encode('utf8')) elif environ['QUERY_STRING'].split('&'): paramDict = {item.split('=')[0]: item.split('=')[1] for item in environ['QUERY_STRING'].split('&')} if paramDict.get('query_type') == 'internal': output = bytes((header() + body() + getInternalNumbers() + footer()).encode('utf8')) elif paramDict.get('query_type') == 'external': output = bytes((header() + body() + getCOline() + footer()).encode('utf8')) else: output = bytes((header() + body() + footer()).encode('utf8')) response_headers = [('Content-type', 'text/html;charset=utf-8'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] def header(): txtHeader = '\n' \ '\n' \ '\n' \ 'Телефоны\n' \ '\n' return txtHeader def footer(): txtFooter = '\n' return txtFooter def body(): txtBody = '\n' \ '

ТЕЛЕФОНЫ

{}
\n'.format(menu()) return txtBody def menu(): #
txtMenu = '\n' return txtMenu def getInternalNumbers(): conn = connectDB() c = conn.cursor() order = 'int_number' result = '

Список внутренних телефонов

' qwr = "SELECT * FROM int_number ORDER by " + order c.execute(qwr) listHeader = '\n' \ '\n' \ '\n' \ '\n' result = result + listHeader for row in c.fetchall(): rowData = "\n" % (row[0], row[1], row[2], row[4], row[3]) result = result + rowData return (result + "
№ п/пТелефонФИООписаниеЭлектро-почта
%s%s%s%s%s
\n") def getCOline(): conn = connectDB() c = conn.cursor() order = 'ext_co_line' result = '

Список внешних линий

' qwr = "SELECT * FROM ext_co_line ORDER by " + order c.execute(qwr) listHeader = '\n' \ '\n' \ '\n' \ '\n' result = result + listHeader for row in c.fetchall(): rowData = "" % (row[0], row[1], row[2], row[3]) result = result + rowData return (result + "
№ п/пЛинияНомер телефонаОписание
%s%s%s%s
\n") def connectDB(): c = pymysql.connect( db='ats_test', user='ats', passwd='', host='kis', charset='utf8') return c