import sys
from PyQt5 import QtCore, QtWidgets, QtGui, uic
from PyQt5.QtCore import QThread, pyqtSignal, QTimer, pyqtSlot,QSize, Qt
from PyQt5.QtCore import pyqtSlot,QSize, Qt
from PyQt5.QtWidgets import QLabel, QPushButton,QTableWidget, QTableWidgetItem, QProgressBar
import datetime
from PyQt5.QtGui import QIcon
import requests
import json
import sqlite3
class ThreadClass(QThread):
stastSignal = pyqtSignal(int)
finishSignal = pyqtSignal(str, list)
def __init__(self, u, l):
super(ThreadClass, self).__init__()
self.u=u
self.l=l
self.label1 = QLabel()
def run(self):
#СПИСКИ
self.icao_list=[]
self.flights_list=[]
self.date_teme_list=[]
self.icao_mill = []
self.list_l=[]
headers = {'Content-type': 'application/json'}
print(self.u)
print(self.l)
u= self.u
l= self.l
url1='http://127.0.0.1/VirtualRadar/ReportRows.json?rep=date&fromRow=-1&toRow=-1&date-L='+l+'&date-U='+u+'&sort1=date&sort1dir=asc&_='
#url1='https://flighttracking.jakami.de/VirtualRadar/ReportRows.json?rep=date&fromRow=-1&toRow=-1&date-L=2022-07-01&date-U=2022-07-01&sort1=date&sort1dir=asc&_=1656669712097'
response = requests.post(url1, headers=headers)
t=response.json()
acList=t["aircraftList"]
flights=t["flights"]
for i in acList:
self.icao_list.append(i['icao'])
for fl in flights:
fligt = int(fl['acIdx'])
self.flights_list.append(self.icao_list[fligt])
date_time_13 = str(fl['start'])
timestamp = date_time_13[6:19]
your_dt = datetime.datetime.fromtimestamp(int(timestamp)/1000) # using the local timezone
self.date_teme_list.append(your_dt.strftime("%d-%m-%Y %H:%M:%S"))
print(self.icao_list)
print(self.flights_list)
print(self.date_teme_list)
self.a = len(self.flights_list)
self.pb_down = (100 / self.a)
print(self.a)
self.p=-1
self.value = 0
for Address in self.flights_list:
self.p=self.p+1
if self.value < 100:
self.value = self.value + self.pb_down
print(self.value)
self.stastSignal.emit(self.value)
self.sqlite_connection = sqlite3.connect('pcfc1.sl3')
self.cursor = self.sqlite_connection.cursor()
print("Подключен к SQLite")
self.sql_select_query = """select * from PCFC where Address = ?"""
self.cursor.execute(self.sql_select_query, (Address,))
self.records = self.cursor.fetchall()
for row in self.records:
if row[6] == "True":
k=[self.date_teme_list[self.p], str(row[11]), str(row[1]),str(row[3]),str(row[4]),str(row[7]),"Военный", str(row[9]) ]
self.list_l.append(k)
self.icao_mill.append(row[6])
self.cursor.close()
self.finishSignal.emit("Всего:"+str(len(self.flights_list)) + ". " + "Военные:" + str(len(self.icao_mill)), self.list_l)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.centralwidget = QtWidgets.QWidget()
self.setCentralWidget(self.centralwidget)
self.centralwidget.resize(1100, 622)
#дата ОТ
now = datetime.datetime.now() # Получить текущую дату
dateedit = QtWidgets.QDateEdit(now) # Использовать ее в конструкторе
dateedit.setCalendarPopup(True) # Эта строка добавлена
#дата ДО
now1 = datetime.datetime.now() # Получить текущую дату
dateedit1 = QtWidgets.QDateEdit(now1) # Использовать ее в конструкторе
dateedit1.setCalendarPopup(True) # Эта строка добавлена
self.label1 = QLabel()
self.table = QTableWidget() # Создаём таблицу
self.table.setColumnCount(8) # Столбцы, число
self.table.setHorizontalHeaderLabels(["Дата и Время", "ICAO", "Рег. номер", " Модель"," Организация","Пренодлежность", "Статус", "Маршрут",])
self.table.horizontalHeaderItem(0).setTextAlignment(Qt.AlignLeft)
self.table.horizontalHeaderItem(1).setTextAlignment(Qt.AlignHCenter)
self.table.horizontalHeaderItem(2).setTextAlignment(Qt.AlignRight)
self.pbar = QtWidgets.QProgressBar()
self.pbar.setValue(0)
self.pushButton = QtWidgets.QPushButton("Отчет")
self.pushButton.clicked.connect(self.onButton)
self.layout = QtWidgets.QVBoxLayout(self.centralwidget)
self.layout.addWidget(dateedit)
self.layout.addWidget(dateedit1)
self.layout.addWidget(self.label1)
self.layout.addWidget(self.table)
self.layout.addWidget(self.pushButton)
self.layout.addWidget(self.pbar)
u = str(dateedit1.date().toString('yyyy-MM-dd'))
l= str(dateedit.date().toString('yyyy-MM-dd'))
self.threadclass = ThreadClass(u, l)
self.threadclass.stastSignal.connect(self.stast_process)
self.threadclass.finishSignal.connect(self.finishSignal_process)
self.timer = QTimer(self)
self.timer.timeout.connect(self.timeout_func)
def onButton(self):
self.pushButton.setEnabled(False)
self.pbar.setValue(0)
self.threadclass.start()
def stast_process(self, val):
val=int(val)
self.pbar.setValue(val)
def finishSignal_process(self, val, list_l):
self.label1.setText(val)
self.e=-1
self.list_l = list_l
for il in self.list_l:
self.e=self.e+1
self.table.setRowCount(self.e+1)
self.table.setItem(self.e, 0, QTableWidgetItem(str(il[0])))
self.table.setItem(self.e, 1, QTableWidgetItem(str(il[1])))
self.table.setItem(self.e, 2, QTableWidgetItem(str(il[2])))
self.table.setItem(self.e, 3, QTableWidgetItem(str(il[3])))
self.table.setItem(self.e, 4, QTableWidgetItem(str(il[4])))
self.table.setItem(self.e, 5, QTableWidgetItem(str(il[5])))
self.table.setItem(self.e, 6, QTableWidgetItem(str(il[6])))
self.table.setItem(self.e, 7, QTableWidgetItem(str(il[7])))
self.pbar.setValue(100)
self.pushButton.setEnabled(True)
def timeout_func(self):
self.progressBar.setValue(self.value)
self.value += 10
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())