from audioop import add import base64 import os import json from unicodedata import name from codecs import ignore_errors from pickle import TRUE import turtle from xmlrpc.client import boolean import numpy as np from asyncore import write import xlrd import pandas as pd import openpyxl from xlrd import Book import datetime import time from flask import Flask,request from encodings import utf_8 import pymssql import json import base64 from out_school import out_school from in_school import in_school import time class view(): def view1(p,json_data): print(type(json_data['name'])) area=json_data['name'] data={ 'height':[], 'middle':[], 'low':[] } conn =pymssql.connect( server="LAPTOP-FLH9FTB4",#本地服务器 user="sa",password="as2799094948", database="software_project", charset="utf8" #这里设置全局的GBK,如果设置的是UTF—8需要将数据库默认的GBK转化成UTF-8 ) if conn: print('连接数据库成功!')#测试是否连接上 #高风险地区 cursor =conn.cursor() #使用cursor()方法获取操作游标 if area=='全部':sql_select="SELECT location FROM height order by location" else:sql_select="SELECT location FROM height where area ='{}' order by location".format(area) # sql_select="SELECT location FROM height where location like '{}%'".format(area) #数据库查询语句 cursor.execute(sql_select) #执行语句 results =cursor.fetchall() #获取所有记录列表 if len(results)==0: print('该地区暂无高风险区域') data['height'].append('该地区暂无高风险区域') else: print('共查询到{}条信息'.format(len(results))) data['height'].append('共查询到{}条信息'.format(len(results))) for result in results: print(result[0]) data['height'].append(result[0]) #中风险地区 cursor =conn.cursor() #使用cursor()方法获取操作游标 if area=='全部':sql_select="SELECT location FROM middle order by location" else:sql_select="SELECT location FROM middle where area ='{}' order by location".format(area) cursor.execute(sql_select) #执行语句 results =cursor.fetchall() #获取所有记录列表 if len(results)==0: print('该地区暂无中风险区域') data['middle'].append('该地区暂无中风险区域') else: print('共查询到{}条信息'.format(len(results))) data['middle'].append('共查询到{}条信息'.format(len(results))) for result in results: print(result[0]) data['middle'].append(result[0]) #低风险地区 cursor =conn.cursor() #使用cursor()方法获取操作游标 if area=='全部':sql_select="SELECT location FROM low order by location" else:sql_select="SELECT location FROM low where area ='{}' order by location".format(area) cursor.execute(sql_select) #执行语句 results =cursor.fetchall() #获取所有记录列表 if len(results)==0: print('该地区暂无低风险区域') data['low'].append('该地区暂无低风险区域') else: print('共查询到{}条信息'.format(len(results))) data['low'].append('共查询到{}条信息'.format(len(results))) for result in results: print(result[0]) data['low'].append(result[0]) conn.commit() cursor.close() conn.close() b=json.dumps(data,ensure_ascii=False) return b