コード例 #1
0
ファイル: pymysqltest.py プロジェクト: longmao88888/assets
def keywordquery():
    query = request.form['query']
    arealist, stationlist = areaandstationlist(cursor)
    info = []
    idinfo = []
    global info0
    for station in stationlist:
        sql = "SELECT stationid,name1,IDENTIFIER,assetid FROM %s \
              WHERE stationid LIKE '%%%s%%' OR name1 LIKE  '%%%s%%'" % (
            station, query, query)
        try:
            # 执行SQL语句
            cursor.execute(sql)
            # 获取所有记录列表
            results = cursor.fetchall()
            if results != None:
                info.extend(results)
                idinfo.extend([i[3] for i in results])
        except:
            print("Error: unable to fetch data")
    if info == []:
        queryerr = 1
        return render_template('index.html', queryerr=queryerr)
    for i in range(len(idinfo)):
        if idinfo[i] is None:
            idinfo[i] = "该基站未进行资产匹配!,".strip(',').split(',')
        else:
            idinfo[i] = idinfo[i].strip(',').split(',')
    info0 = info
    return render_template('keywordquery.html', assets=info, idinfo=idinfo)
コード例 #2
0
ファイル: pymysqltest.py プロジェクト: longmao88888/assets
def keywordquery():
    query = request.form['query']
    arealist,stationlist = areaandstationlist(cursor)
    station = u'站址'
    info = []
    idinfo =[]
    global info0
    sql = "SELECT id,crru,c基站,c室分站,c直放站,lrru,l基站,资产个数 FROM %s WHERE id LIKE '%%%s%%' " % (station, query)
    try:
        # 执行SQL语句
        cursor.execute(sql)
        results = cursor.fetchall()
        if results != None:
            info = list(results)
    except:
        print("Error: unable to fetch data")
    if info == []:
        queryerr = 1
        return render_template('index.html', queryerr=queryerr)
    # for i in range(len(idinfo)):
    #     if idinfo[i] is None:
    #         idinfo[i]="该基站未进行资产匹配!,".strip(',').split(',')
    #     else:
    #         idinfo[i] = idinfo[i].strip(',').split(',')
    info0 = info
    return render_template('keywordquery.html', assets=info)
コード例 #3
0
import pymysql
import time
from match_f import areaandstationlist, assetmatch, stationmatch

starttime = time.clock()
# 连接数据库
db = pymysql.connect("localhost",
                     "root",
                     "",
                     "assetsmanagement",
                     charset='utf8')
cursor = db.cursor()

# 查询数据库中的表格
(arealist, stationlist) = areaandstationlist(cursor)
#打开保存匹配结果文件
f = open('result.txt', 'w+')
# 资产匹配基站
for area in arealist:
    assetmatch(cursor, area, stationlist, f)

f.close()

f = open('result.txt', 'a+')
# 基站匹配资产
for station in stationlist:
    stationmatch(cursor, station, arealist, f)
f.close()
db.close()
print(time.clock() - starttime)