fontsize = 10 progressbarstartborder = { progressbarendborder = } progressbarfilled = # progressbarempty = - imagepos = left screenpos = right verticalscreenpos = bottom horizontalscreenpos = right title = Current Playing: [Keys] clientid = clientsecret = """) config.close() exit() try: print("Attempting to authorize. . .") spotifyObject = Spotify(auth_manager=SpotifyOAuth(scope="user-read-playback-state", client_id=clientid, client_secret=clientsecret, redirect_uri="http://localhost:8080/", requests_timeout=5)) print("Authorized.") except Exception as err: print(f"Error authorizing: {err}") exit() class SpotifyOverlay: def __init__(self): try: print("Attempt to construct window. . .")
def Register(request): from configparser import ConfigParser import os conn = ConfigParser() file_path = os.path.join(os.path.abspath('.'), 'config.ini') if not os.path.exists(file_path): raise FileNotFoundError("文件不存在") conn.read(file_path) pghost = conn.get('api', 'pghost') pgport = conn.get('api', 'pgport') pguser = conn.get('api', 'pguser') pgpassword = conn.get('api', 'pgpassword') pgdatabase = conn.get('api', 'pgdatabase') iotdbIp = conn.get('api', 'iotdbIp') iotdbUser = conn.get('api', 'iotdbUser') iotdbPassword = conn.get('api', 'iotdbPassword') #iotdb_conn = JDBC.connect('org.apache.iotdb.jdbc.IoTDBDriver', "jdbc:iotdb://192.168.3.31:6667/", ['root', 'root'], 'iotdb-jdbc-0.9.0-SNAPSHOT-jar-with-dependencies.jar') iotdb_conn = get_jdbc_connection(iotdbIp, iotdbUser, iotdbPassword) iotdb_curs = iotdb_conn.cursor() # conn = psycopg2.connect(host = '172.16.50.7', port = 5432, user = '******', password = '******', database='protodw') conn = psycopg2.connect(host=pghost, port=pgport, user=pguser, password=pgpassword, database=pgdatabase) cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) x = print(request.POST) print(request.body) print("1") body = json.loads(str(request.body, encoding='utf8')) if not body['roidList']: print('No roidList!') iotdb_curs.close() iotdb_conn.close() cursor.close() conn.close() return HttpResponse('No roidList!') roidList = body['roidList'] print(roidList) errors = [] for roid in roidList: sql = "SELECT * FROM plt_tsm_railline WHERE plt_oid = '" + roid + "'" cursor.execute(sql) qr = cursor.fetchall() line_id = qr[0]["plt_lineid"] sql = "SELECT * FROM plt_cus_car WHERE plt_railline = '" + roid + "'" cursor.execute(sql) car_qr = cursor.fetchall() sql = "SELECT * FROM plt_tsm_protocol WHERE plt_oid = '" + qr[0][ 'plt_protoid'] + "'" cursor.execute(sql) protocol_qr = cursor.fetchall() work_condition = [] for protocol in protocol_qr: poid = protocol["plt_oid"] sql = "SELECT plt_tsm_template.* FROM ((plt_tsm_protocol INNER JOIN plt_tsm_r_pro2temp ON plt_tsm_protocol.plt_oid = plt_tsm_r_pro2temp.plt_leftoid) INNER JOIN plt_tsm_template ON plt_tsm_r_pro2temp.plt_rightoid = plt_tsm_template.plt_oid) WHERE plt_tsm_protocol.plt_oid = '" + poid + "'" cursor.execute(sql) template_qr = cursor.fetchall() for template in template_qr: toid = template["plt_oid"] sql = "SELECT plt_tsm_templatepara.* FROM ((plt_tsm_template INNER JOIN plt_tsm_r_tem2tempara ON plt_tsm_template.plt_oid = plt_tsm_r_tem2tempara.plt_leftoid) INNER JOIN plt_tsm_templatepara ON plt_tsm_r_tem2tempara.plt_rightoid = plt_tsm_templatepara.plt_oid) WHERE plt_tsm_template.plt_oid = '" + toid + "'" cursor.execute(sql) tempara_qr = cursor.fetchall() for tempara in tempara_qr: if (tempara["plt_paratype"] != "工况参数"): continue name = tempara["plt_paraid"] type = tempara["plt_datatype"] iotdb_type = "" iotdb_encoding = "" if type == "Int": iotdb_type = "INT32" iotdb_encoding = "RLE" elif type == "Long": iotdb_type = "INT64" iotdb_encoding = "RLE" elif type == "Float": iotdb_type = "FLOAT" iotdb_encoding = "GORILLA" elif type == "Double": iotdb_type = "DOUBLE" iotdb_encoding = "GORILLA" elif type == "String": iotdb_type = "TEXT" iotdb_encoding = "PLAIN" elif type == "Boolean": iotdb_type = "BOOLEAN" iotdb_encoding = "RLE" work_condition.append((name, iotdb_type, iotdb_encoding)) for car in car_qr: car_id = car["plt_carid"] coid = car["plt_oid"] sql = "SELECT * FROM plt_cus_terminal WHERE plt_carid = '" + coid + "'" cursor.execute(sql) terminal_qr = cursor.fetchall() for terminal in terminal_qr: position = terminal["plt_position"] terminal_id = terminal["plt_terminalid"] if position == "车头": terminal_id = "Head" elif position == "车尾": terminal_id = "Tail" storage_group = "root." + line_id + "." + car_id + "." + terminal_id iotdb_sql = "set storage group to " + storage_group try: iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) try: iotdb_sql = "create timeseries " + storage_group + ".OriginalPackage with datatype=TEXT,encoding=PLAIN" iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for i in range(1, 7): for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage" + str( i) + "." + wc[0] + " with datatype=" + wc[ 1] + ",encoding=" + wc[2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str( e ) != 'java.sql.SQLException: Method not supported' ): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage11." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage12." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage21." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage22." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage31." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage32." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage41." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage42." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage51." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage52." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage61." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) for wc in work_condition: try: iotdb_sql = "create timeseries " + storage_group + "." + "Carriage62." + wc[ 0] + " with datatype=" + wc[1] + ",encoding=" + wc[ 2] iotdb_curs.execute(iotdb_sql) except Exception as e: if (str(e) != 'java.sql.SQLException: Method not supported'): errors.append(str(e)) iotdb_curs.close() iotdb_conn.close() cursor.close() conn.close() return HttpResponse(errors)
def Query(request): from configparser import ConfigParser import os conn = ConfigParser() file_path = os.path.join(os.path.abspath('.'), 'config.ini') if not os.path.exists(file_path): raise FileNotFoundError("文件不存在") conn.read(file_path) pghost = conn.get('api', 'pghost') pgport = conn.get('api', 'pgport') pguser = conn.get('api', 'pguser') pgpassword = conn.get('api', 'pgpassword') pgdatabase = conn.get('api', 'pgdatabase') iotdbIp = conn.get('api', 'iotdbIp') iotdbUser = conn.get('api', 'iotdbUser') iotdbPassword = conn.get('api', 'iotdbPassword') print(request.body) body = json.loads(str(request.body, encoding='utf8')) if not body['railLineOid']: print('No railLineOid!') return JsonResponse({'state': 'Error', 'value': '没有选择线路!'}) roid = body['railLineOid'] if not body['carList']: print('No carList!') return JsonResponse({'state': 'Error', 'value': '没有选择列车!'}) carList = body['carList'] if not body['terminalList']: print('No terminalList!') return JsonResponse({'state': 'Error', 'value': '没有选择终端!'}) tmp = body['terminalList'].split(',') terminalList = [] for i in tmp: if i == '车头': terminalList.append('Head') elif i == '车尾': terminalList.append('Tail') if not body['CarriageList']: print('No CarriageList!') return JsonResponse({'state': 'Error', 'value': '没有选择车厢!'}) carriageList = body['CarriageList'].split(',') if not body['paraList']: print('No paraList!') return JsonResponse({'state': 'Error', 'value': '没有选择工况!'}) paraList = body['paraList'] if not body['startTime']: print('No startTime!') return JsonResponse({'state': 'Error', 'value': '没有选择开始时间!'}) startTime = body['startTime'].split('.')[0] if not body['endTime']: print('No endTime!') return JsonResponse({'state': 'Error', 'value': '没有选择结束时间!'}) endTime = body['endTime'].split('.')[0] if startTime > endTime: print('startTime > endTime!') return JsonResponse({'state': 'Error', 'value': '开始时间晚于结束时间!'}) #iotdb_conn = JDBC.connect('org.apache.iotdb.jdbc.IoTDBDriver', "jdbc:iotdb://192.168.3.31:6667/", ['root', 'root'], 'iotdb-jdbc-0.9.0-SNAPSHOT-jar-with-dependencies.jar') iotdb_conn = get_jdbc_connection(iotdbIp, iotdbUser, iotdbPassword) iotdb_curs = iotdb_conn.cursor() # conn = psycopg2.connect(host = '172.16.50.7', port = 5432, user = '******', password = '******', database='protodw') conn = psycopg2.connect(host=pghost, port=pgport, user=pguser, password=pgpassword, database=pgdatabase) cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) sql = "SELECT * FROM plt_tsm_railline WHERE plt_oid = '" + roid + "'" cursor.execute(sql) qr = cursor.fetchall() line_id = qr[0]["plt_lineid"] ret = [] for i in carList: for j in terminalList: for k in carriageList: for l in paraList: #time_series = "root." + "BJ8T00" + "." + i + "." + j + ".Carriage" + k time_series = "root." + line_id + "." + i + "." + j + ".Carriage" + k if l == "OriginalPackage": time_series = "root." + line_id + "." + i + "." + j #time_series = "root." + "BJ8T00.H411.Head"+".Carriage" + k # logging.warning(time_series) sql = "SELECT " + l + " FROM " + time_series + " where time >= " + startTime + " && time <= " + endTime #sql = "SELECT " + l + " FROM " + "root.BJ8T00.H411.Head.Carriage2" + " where time <= " + endTime # logging.warning(sql) try: iotdb_curs.execute(sql) qr = iotdb_curs.fetchall() # print(qr) for r in qr: ret.append([time_series + "." + l, r[0], r[1]]) except Exception as e: print(e) cursor.close() conn.close() iotdb_curs.close() iotdb_conn.close() return JsonResponse({'state': 'OK', 'value': ret})