コード例 #1
0
ファイル: FOLME.py プロジェクト: emper0r/IVAO-status
 def status(self, callsign):
     self.callsign = callsign
     Q_db = SQL_queries.sql_query('Get_FMC_data', (str(callsign),))
     info = Q_db.fetchall()
     self.ui.VidText.setText(str(info[0][0]))
     self.ui.FMCRealname.setText(str(info[0][1].encode('latin-1'))[:-4])
     self.ui.SoftwareText.setText('%s %s' % (str(info[0][6]), str(info[0][7])))
     self.ui.ConnectedText.setText(str(info[0][2]))
     try:
         Q_db = SQL_queries.sql_query('Get_Country_from_ICAO', (str(callsign[:4]),))
         flagCodeOrig = Q_db.fetchone()
         image_flag = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../flags')
         flagCodePath_orig = (image_flag + '/%s.png') % flagCodeOrig
         Pixmap = QPixmap(flagCodePath_orig)
         self.ui.Flag.setPixmap(Pixmap)
         Q_db = SQL_queries.sql_query('Get_Airport_from_ICAO', (str(callsign[:4]),))
         city_orig = Q_db.fetchone()
     except:
         self.ui.ControllingText.setText('Pending...')
     ImagePath = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../images')
     ratingImagePath = (ImagePath + '/ZZZZ.png')
     Pixmap = QPixmap(ratingImagePath)
     self.ui.rating_img.setPixmap(Pixmap)
     try:
         start_connected = datetime.datetime(int(str(info[0][5])[:4]), int(str(info[0][5])[4:6])
                                             , int(str(info[0][5])[6:8]), int(str(info[0][5])[8:10])
                                             , int(str(info[0][5])[10:12]), int(str(info[0][5])[12:14]))
         diff = datetime.datetime.utcnow() - start_connected
         self.ui.TimeOnLineText.setText('Time on line: ' + str(diff)[:-7])
     except:
         self.ui.TimeOnLineText.setText('Pending...')
コード例 #2
0
ファイル: StatusFlight.py プロジェクト: emper0r/IVAO-status
def status_flight(callsign):
    """This function is to get the action of the Pilot but for now I try to show using percent and
       some ground speeds of the track. I'm pretty sure with more check VARS can better this part"""
    Q_db = SQL_queries.sql_query('Get_Status', (str(callsign),))
    get_status = Q_db.fetchone()
    status = '-'
    for row_pilot in get_status:
        try:
            Q_db = SQL_queries.sql_query('Get_City', (str(get_status[2]),))
            city_orig = Q_db.fetchone()
            city_orig_point = float(city_orig[1]), float(city_orig[2])
            Q_db = SQL_queries.sql_query('Get_City', (str(get_status[3]),))
            city_dest = Q_db.fetchone()
            city_dest_point = float(city_dest[1]), float(city_dest[2])
            pilot_position = get_status[8], get_status[9]
            total_miles = distance.distance(city_orig_point, city_dest_point).miles
            dist_traveled = distance.distance(city_orig_point, pilot_position).miles
            percent = (float(dist_traveled) / float(total_miles)) * 100.0

            if percent > 105 :
                status = 'Diverted'
                return status
            else:
                if int(str(get_status[4])) == 0:
                    if (percent >= 0.0) and (percent <= 2.0):
                        status = 'Takeoff'
                    if (percent >= 2.0) and (percent <= 7.0):
                        status = 'Initial Climbing'
                    if (percent >= 7.0) and (percent <= 10.0):
                        status = 'Climbing'
                    if (percent >= 10.0) and (percent <= 80.0):
                        status = 'On Route'
                    if (percent >= 80.0) and (percent <= 90.0):
                        status = 'Descending'
                    if (percent >= 90.0) and (percent <= 97.0):
                        status = 'Initial Approach'
                    if (97.0 <= percent <= 105.0) and (360 >= get_status[6] >= 30):
                        status = 'Final Approach'
                    return status
                else:
                    if (0 < get_status[6] <= 30) and (percent < 1.0):
                        status = 'Departing'
                    if (get_status[6] > 30) and (get_status[6] < 150) and (percent < 1.0):
                        status = 'Takeoff'
                    if (97.0 <= percent <= 105.0) and (270 >= get_status[6] >= 30):
                        status = 'Landed'
                    if (get_status[6] < 30) and (percent > 99.0):
                        status = 'Taxing to Gate'
                    if (get_status[6] == 0) and (percent > 99.0):
                        status = 'On Blocks'
                    if (get_status[6] == 0) and (percent <= 1.0):
                        status = 'Boarding'
                    if (get_status[6] == 0) and (10.0 <= percent <= 90.0):
                        status = 'Altern Airport'
                    return status
        except:
            status = 'Fill Flight Plan'
            return status
コード例 #3
0
ファイル: Controllers.py プロジェクト: emper0r/IVAO-status
 def status(self, callsign):
     self.callsign = callsign
     self.position_atc = {"0":"Observer", "1":"Flight Service Station", "2":"Clearance Delivery"
                          , "3":"Ground", "4":"Tower", "5":"Approach", "6":"Center", "7":"Departure"}
     Q_db = SQL_queries.sql_query('Get_Controller_data', (str(callsign),))
     info = Q_db.fetchall()
     self.ui.VidText.setText(str(info[0][0]))
     self.ui.ControllerText.setText(str(info[0][1].encode('latin-1')))
     self.ui.SoftwareText.setText('%s %s' % (str(info[0][9]), str(info[0][10])))
     self.ui.ConnectedText.setText(str(info[0][2]))
     self.ui.ATISInfo.setText(str(info[0][7].encode('latin-1')).replace('^\xa7', '\n'))
     ImageFlags = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../flags')
     ImageRatings = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../ratings')
     try:
         Q_db = SQL_queries.sql_query('Get_Country_from_ICAO', (str(callsign[:4]),))
         flagCodeOrig = Q_db.fetchone()
         if flagCodeOrig is None:
             if str(callsign[-4:]) == '_CTR':
                 Q_db = SQL_queries.sql_query('Get_Country_from_FIR', (str(callsign[:4]),))
                 flagCodeOrig = Q_db.fetchone()
             else:
                 Q_db = SQL_queries.sql_query('Get_Country_by_Id', (str(callsign[:2]),))
                 flagCodeOrig = Q_db.fetchone()
                 if flagCodeOrig is None:
                     Q_db = SQL_queries.sql_query('Get_Country_from_Prefix', (str(callsign[:2]),))
                     flagCodeOrig = Q_db.fetchone()
         flagCodePath_orig = (ImageFlags + '/%s.png') % flagCodeOrig
         Pixmap = QPixmap(flagCodePath_orig)
         self.ui.Flag.setPixmap(Pixmap)
         Q_db = SQL_queries.sql_query('Get_Airport_from_ICAO', (str(callsign[:4]),))
         city_orig = Q_db.fetchone()
         if city_orig is None:
             if str(callsign[-4:]) == '_CTR':
                 Q_db = SQL_queries.sql_query('Get_FIR_from_ICAO', (str(callsign[:4]),))
                 city_orig = Q_db.fetchone()
             else:
                 Q_db = SQL_queries.sql_query('Get_Country_by_Id', (str(callsign[:2]),))
                 city_orig = Q_db.fetchone()
                 if city_orig is None:
                     Q_db = SQL_queries.sql_query('Get_Country_from_Prefix', (str(callsign[:2]),))
                     city_orig = Q_db.fetchone()
         self.ui.ControllingText.setText(str(city_orig[0].encode('latin-1')))
     except:
         self.ui.ControllingText.setText('Pending...')
     ratingImagePath = ImageRatings + '/atc_level%d.gif' % int(info[0][5])
     Pixmap = QPixmap(ratingImagePath)
     self.ui.rating_img.setPixmap(Pixmap)
     self.ui.facility_freq_Text.setText(str(self.position_atc[str(info[0][6])]) + ' ' + str(info[0][4]) + ' MHz')
     try:
         start_connected = datetime.datetime(int(str(info[0][8])[:4]), int(str(info[0][8])[4:6])
                                             , int(str(info[0][8])[6:8]), int(str(info[0][8])[8:10])
                                             , int(str(info[0][8])[10:12]), int(str(info[0][8])[12:14]))
         diff = datetime.datetime.utcnow() - start_connected
         self.ui.TimeOnLineText.setText('Time on line: ' + str(diff)[:-7])
     except:
         self.ui.TimeOnLineText.setText('Pending...')
コード例 #4
0
ファイル: FOLME.py プロジェクト: bbr1870/IVAO-status
 def status(self, callsign):
     self.callsign = callsign
     Q_db = SQL_queries.sql_query('Get_FMC_data', (str(callsign), ))
     info = Q_db.fetchall()
     self.ui.VidText.setText(str(info[0][0]))
     self.ui.FMCRealname.setText(str(info[0][1].encode('latin-1'))[:-4])
     self.ui.SoftwareText.setText('%s %s' %
                                  (str(info[0][6]), str(info[0][7])))
     self.ui.ConnectedText.setText(str(info[0][2]))
     try:
         Q_db = SQL_queries.sql_query('Get_Country_from_ICAO',
                                      (str(callsign[:4]), ))
         flagCodeOrig = Q_db.fetchone()
         image_flag = os.path.join(
             os.path.dirname(os.path.abspath(__file__)), '../flags')
         flagCodePath_orig = (image_flag + '/%s.png') % flagCodeOrig
         Pixmap = QPixmap(flagCodePath_orig)
         self.ui.Flag.setPixmap(Pixmap)
         Q_db = SQL_queries.sql_query('Get_Airport_from_ICAO',
                                      (str(callsign[:4]), ))
         city_orig = Q_db.fetchone()
     except:
         self.ui.ControllingText.setText('Pending...')
     ImagePath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              '../images')
     ratingImagePath = (ImagePath + '/ZZZZ.png')
     Pixmap = QPixmap(ratingImagePath)
     self.ui.rating_img.setPixmap(Pixmap)
     try:
         start_connected = datetime.datetime(int(str(info[0][5])[:4]),
                                             int(str(info[0][5])[4:6]),
                                             int(str(info[0][5])[6:8]),
                                             int(str(info[0][5])[8:10]),
                                             int(str(info[0][5])[10:12]),
                                             int(str(info[0][5])[12:14]))
         diff = datetime.datetime.utcnow() - start_connected
         self.ui.TimeOnLineText.setText('Time on line: ' + str(diff)[:-7])
     except:
         self.ui.TimeOnLineText.setText('Pending...')
コード例 #5
0
def Scheduling():
    """This part is a parse HTML from Schedule website from IVAO, because i can't access
       directly to IVAO database to download schedule, so I have to get by other way where users can
       see the schedule for controllers and pilots"""
    config = ConfigParser.RawConfigParser()
    config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               '../Config.cfg')
    config.read(config_file)
    SQL_queries.sql_query('Clear_Scheduling_tables')
    parser = etree.HTMLParser()
    qApp.processEvents()
    try:
        use_proxy = config.getint('Settings', 'use_proxy')
        auth = config.getint('Settings', 'auth')
        host = config.get('Settings', 'host')
        port = config.get('Settings', 'port')
        user = config.get('Settings', 'user')
        pswd = config.get('Settings', 'pass')
        if use_proxy == 2 and auth == 2:
            passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
            passmgr.add_password(None, 'http://' + host + ':' + port, user,
                                 pswd)
            authinfo = urllib2.ProxyBasicAuthHandler(passmgr)
            proxy_support = urllib2.ProxyHandler(
                {"http": "http://" + host + ':' + port})
            opener = urllib2.build_opener(proxy_support, authinfo)
            urllib2.install_opener(opener)
            QNetworkProxy.setApplicationProxy(
                QNetworkProxy(QNetworkProxy.HttpProxy, str(host), int(port),
                              str(user), str(pswd)))
        if use_proxy == 2 and auth == 0:
            proxy_support = urllib2.ProxyHandler(
                {"http": "http://" + host + ':' + port})
            opener = urllib2.build_opener(proxy_support)
            urllib2.install_opener(opener)
            QNetworkProxy.setApplicationProxy(
                QNetworkProxy(QNetworkProxy.HttpProxy, str(host), int(port)))
        if use_proxy == 0 and auth == 0:
            pass
        """This lines set locales of enviroment at default "English" language to can parse with web"""
        save_locale = locale.getlocale()
        locale.setlocale(locale.LC_ALL, 'C')

        SchedATC_URL = urllib2.urlopen(config.get('Info',
                                                  'scheduling_atc')).read()
        tree = etree.parse(StringIO.StringIO(SchedATC_URL), parser)
        table_atc = tree.xpath("/html/body/div/center/table")[0]
        actual_today = datetime.datetime.today()

        for line_atc_table in table_atc[1:]:
            for day in range(actual_today.day, 31):
                if '%s %s' % (day, calendar.month_name[datetime.datetime.now(
                ).month]) in line_atc_table[4][0].text:
                    columns = [td[0].text for td in line_atc_table]
                    SQL_queries.sql_query('Add_Schedule_ATC', columns)
                    qApp.processEvents()

        SchedFlights_URL = urllib2.urlopen(
            config.get('Info', 'scheduling_flights')).read()
        tree = etree.parse(StringIO.StringIO(SchedFlights_URL), parser)
        table_flights = tree.xpath("/html/body/div/div/center/table")[0]

        for line_flights_table in table_flights[2:]:
            for day in range(actual_today.day, 31):
                if '%s %s' % (day, calendar.month_name[datetime.datetime.now(
                ).month]) in line_flights_table[7][0].text:
                    columns = [td[0].text for td in line_flights_table]
                    SQL_queries.sql_query('Add_Schedule_Flights', columns)
                    qApp.processEvents()
        """Restore locales"""
        locale.setlocale(locale.LC_ALL, save_locale)
        return True
    except IOError:
        return False
コード例 #6
0
ファイル: Pilots.py プロジェクト: emper0r/IVAO-status
    def status(self, callsign):
        self.callsign = callsign
        Q_db = SQL_queries.sql_query('Get_Pilot_data', (str(callsign),))
        info = Q_db.fetchall()
        ImageFlags = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../flags')
        ImageAirlines = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../airlines')
        ImageRatings = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../ratings')
        if info[0][19] == 'FOLME':
            pass
        else:
            try:
                Q_db = SQL_queries.sql_query('Get_Country_from_ICAO', (str(info[0][5]),))
                flagCodeOrig = Q_db.fetchone()
                flagCodePath_orig = (ImageFlags + '/%s.png') % flagCodeOrig
                Pixmap = QPixmap(flagCodePath_orig)
                self.ui.DepartureImage.setPixmap(Pixmap)
                Q_db = SQL_queries.sql_query('Get_Airport_Location', (str(info[0][5]),))
                city_orig = Q_db.fetchone()
                self.ui.DepartureText.setText(str(city_orig[0].encode('latin-1')))
                city_orig_point = city_orig[1], city_orig[2]
            except:
                self.ui.DepartureText.setText('Pending...')
                city_orig_point = None

        try:
            Q_db = SQL_queries.sql_query('Get_Country_from_ICAO', (str(info[0][6]),))
            flagCodeDest = Q_db.fetchone()
            flagCodePath_dest = (ImageFlags + '/%s.png') % flagCodeDest
            Pixmap = QPixmap(flagCodePath_dest)
            self.ui.DestinationImage.setPixmap(Pixmap)
            Q_db = SQL_queries.sql_query('Get_Airport_Location', (str(info[0][6]),))
            city_dest = Q_db.fetchone()
            self.ui.DestinationText.setText(str(city_dest[0].encode('latin-1')))
            city_dest_point = city_dest[1], city_dest[2]
        except:
            self.ui.DestinationText.setText('Pending...')
            city_dest_point = None

        self.ui.vidText.setText(str(info[0][0]))
        try:
            code_airline = callsign[:3]
            airlineCodePath = (ImageAirlines + '/%s.gif') % code_airline
            if os.path.exists(airlineCodePath) is True:
                Pixmap = QPixmap(airlineCodePath)
                airline = QLabel(self)
                self.ui.airline_image.setPixmap(Pixmap)
            else:
                Q_db = SQL_queries.sql_query('Get_Airline', str(callsign[:3]))
                airline_code = Q_db.fetchone()
                self.ui.airline_image.setText(str(airline_code[0]))
        except:
            pass
        self.ui.callsign_text.setText(callsign)
        self.ui.PilotNameText.setText(str(info[0][1][:-4].encode('latin-1')))
        self.ui.RouteText.setText(str(info[0][9]))
        self.ui.GroundSpeedNumber.setText(str(info[0][3]))
        self.ui.AltitudeNumber.setText(str(info[0][2]))
        self.ui.PobText.setText(str(info[0][8]))
        self.ui.TransponderText.setText(str(info[0][11]))
        self.ui.GSFiledText.setText(str(info[0][17]))
        self.ui.FLText.setText(str(info[0][7]))
        Q_db = SQL_queries.sql_query('Get_Airport_from_ICAO', (str(info[0][15]),))
        altern_city_1 = Q_db.fetchone()
        Q_db = SQL_queries.sql_query('Get_Airport_from_ICAO', (str(info[0][16]),))
        altern_city_2 = Q_db.fetchone()
        if altern_city_1 is None:
            self.ui.Altern_Airport_Text.setText(str('-'))
        else:
            self.ui.Altern_Airport_Text.setText(str(altern_city_1[0]))
        if altern_city_2 is None:
            self.ui.Altern_Airport_Text_2.setText(str('-'))
        else:
            self.ui.Altern_Airport_Text_2.setText(str(altern_city_2[0]))
        try:
            if str(info[0][4]) != '':
                Q_db = SQL_queries.sql_query('Get_Model', ((info[0][4].split('/')[1]),))
                data = Q_db.fetchall()
                self.ui.AirplaneText.setText('Model: %s Fabricant: %s Description: %s' \
                                             % (str(data[0][0]), str(data[0][1]), str(data[0][2])))
        except:
            self.ui.AirplaneText.setText('Pending...')
        Q_db = SQL_queries.sql_query('Get_Country_from_ICAO', (str(info[0][1][-4:]),))
        flagCodeHome = Q_db.fetchone()
        flagCodePath = (ImageFlags + '/%s.png') % flagCodeHome
        Pixmap = QPixmap(flagCodePath)
        self.ui.HomeFlag.setPixmap(Pixmap)
        ratingImage = ImageRatings + '/pilot_level%d.gif' % int(info[0][10])
        Pixmap = QPixmap(ratingImage)
        self.ui.rating_img.setPixmap(Pixmap)
        player_point = info[0][13], info[0][14]
        if city_orig_point is None or city_dest_point is None:
            self.ui.nauticalmiles.setText('Pending...')
            self.ui.progressBarTrack.setValue(0)
        if str(info[0][5]) == str(info[0][6]):
                self.ui.progressBarTrack.setValue(0)
                self.ui.nauticalmiles.setText('Local Flight')
                eta = '00:00:00.000000'
        else:
            try:
                total_miles = distance.distance(city_orig_point, city_dest_point).miles
                dist_traveled = distance.distance(city_orig_point, player_point).miles
                percent = float((dist_traveled / total_miles) * 100.0)
                eta = str(datetime.timedelta(hours=((total_miles - dist_traveled) / float(info[0][3]))))
            except:
                if city_orig_point or city_dest_point is None:
                    percent = 0.0
                eta = '00:00:00.000000'
            self.ui.nauticalmiles.setText('%.1f / %.1f miles - %.1f%%' % (float(dist_traveled), float(total_miles), float(percent)))
            self.ui.progressBarTrack.setValue(int(percent))
        status_plane = StatusFlight.status_flight(callsign)
        self.ui.FlightStatusDetail.setText(str(status_plane))
        self.ui.ETA_Arrive.setText(str(eta)[:-7])
        try:
            start_connected = datetime.datetime(int(str(info[0][18])[:4]), int(str(info[0][18])[4:6])
                                                , int(str(info[0][18])[6:8]), int(str(info[0][18])[8:10])
                                                , int(str(info[0][18])[10:12]), int(str(info[0][18])[12:14]))
            diff = datetime.datetime.utcnow() - start_connected
            self.ui.time_online_text.setText(str(diff)[:-7])
        except:
            self.ui.time_online_text.setText('Pending...')
コード例 #7
0
ファイル: Controllers.py プロジェクト: bbr1870/IVAO-status
 def status(self, callsign):
     self.callsign = callsign
     self.position_atc = {
         "0": "Observer",
         "1": "Flight Service Station",
         "2": "Clearance Delivery",
         "3": "Ground",
         "4": "Tower",
         "5": "Approach",
         "6": "Center",
         "7": "Departure"
     }
     Q_db = SQL_queries.sql_query('Get_Controller_data', (str(callsign), ))
     info = Q_db.fetchall()
     self.ui.VidText.setText(str(info[0][0]))
     self.ui.ControllerText.setText(str(info[0][1].encode('latin-1')))
     self.ui.SoftwareText.setText('%s %s' %
                                  (str(info[0][9]), str(info[0][10])))
     self.ui.ConnectedText.setText(str(info[0][2]))
     self.ui.ATISInfo.setText(
         str(info[0][7].encode('latin-1')).replace('^\xa7', '\n'))
     ImageFlags = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               '../flags')
     ImageRatings = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 '../ratings')
     try:
         Q_db = SQL_queries.sql_query('Get_Country_from_ICAO',
                                      (str(callsign[:4]), ))
         flagCodeOrig = Q_db.fetchone()
         if flagCodeOrig is None:
             if str(callsign[-4:]) == '_CTR':
                 Q_db = SQL_queries.sql_query('Get_Country_from_FIR',
                                              (str(callsign[:4]), ))
                 flagCodeOrig = Q_db.fetchone()
             else:
                 Q_db = SQL_queries.sql_query('Get_Country_by_Id',
                                              (str(callsign[:2]), ))
                 flagCodeOrig = Q_db.fetchone()
                 if flagCodeOrig is None:
                     Q_db = SQL_queries.sql_query('Get_Country_from_Prefix',
                                                  (str(callsign[:2]), ))
                     flagCodeOrig = Q_db.fetchone()
         flagCodePath_orig = (ImageFlags + '/%s.png') % flagCodeOrig
         Pixmap = QPixmap(flagCodePath_orig)
         self.ui.Flag.setPixmap(Pixmap)
         Q_db = SQL_queries.sql_query('Get_Airport_from_ICAO',
                                      (str(callsign[:4]), ))
         city_orig = Q_db.fetchone()
         if city_orig is None:
             if str(callsign[-4:]) == '_CTR':
                 Q_db = SQL_queries.sql_query('Get_FIR_from_ICAO',
                                              (str(callsign[:4]), ))
                 city_orig = Q_db.fetchone()
             else:
                 Q_db = SQL_queries.sql_query('Get_Country_by_Id',
                                              (str(callsign[:2]), ))
                 city_orig = Q_db.fetchone()
                 if city_orig is None:
                     Q_db = SQL_queries.sql_query('Get_Country_from_Prefix',
                                                  (str(callsign[:2]), ))
                     city_orig = Q_db.fetchone()
         self.ui.ControllingText.setText(str(
             city_orig[0].encode('latin-1')))
     except:
         self.ui.ControllingText.setText('Pending...')
     ratingImagePath = ImageRatings + '/atc_level%d.gif' % int(info[0][5])
     Pixmap = QPixmap(ratingImagePath)
     self.ui.rating_img.setPixmap(Pixmap)
     self.ui.facility_freq_Text.setText(
         str(self.position_atc[str(info[0][6])]) + ' ' + str(info[0][4]) +
         ' MHz')
     try:
         start_connected = datetime.datetime(int(str(info[0][8])[:4]),
                                             int(str(info[0][8])[4:6]),
                                             int(str(info[0][8])[6:8]),
                                             int(str(info[0][8])[8:10]),
                                             int(str(info[0][8])[10:12]),
                                             int(str(info[0][8])[12:14]))
         diff = datetime.datetime.utcnow() - start_connected
         self.ui.TimeOnLineText.setText('Time on line: ' + str(diff)[:-7])
     except:
         self.ui.TimeOnLineText.setText('Pending...')
コード例 #8
0
    def status(self, callsign):
        self.callsign = callsign
        Q_db = SQL_queries.sql_query('Get_Pilot_data', (str(callsign), ))
        info = Q_db.fetchall()
        ImageFlags = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                  '../flags')
        ImageAirlines = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), '../airlines')
        ImageRatings = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                    '../ratings')
        if info[0][19] == 'FOLME':
            pass
        else:
            try:
                Q_db = SQL_queries.sql_query('Get_Country_from_ICAO',
                                             (str(info[0][5]), ))
                flagCodeOrig = Q_db.fetchone()
                flagCodePath_orig = (ImageFlags + '/%s.png') % flagCodeOrig
                Pixmap = QPixmap(flagCodePath_orig)
                self.ui.DepartureImage.setPixmap(Pixmap)
                Q_db = SQL_queries.sql_query('Get_Airport_Location',
                                             (str(info[0][5]), ))
                city_orig = Q_db.fetchone()
                self.ui.DepartureText.setText(
                    str(city_orig[0].encode('latin-1')))
                city_orig_point = city_orig[1], city_orig[2]
            except:
                self.ui.DepartureText.setText('Pending...')
                city_orig_point = None

        try:
            Q_db = SQL_queries.sql_query('Get_Country_from_ICAO',
                                         (str(info[0][6]), ))
            flagCodeDest = Q_db.fetchone()
            flagCodePath_dest = (ImageFlags + '/%s.png') % flagCodeDest
            Pixmap = QPixmap(flagCodePath_dest)
            self.ui.DestinationImage.setPixmap(Pixmap)
            Q_db = SQL_queries.sql_query('Get_Airport_Location',
                                         (str(info[0][6]), ))
            city_dest = Q_db.fetchone()
            self.ui.DestinationText.setText(str(
                city_dest[0].encode('latin-1')))
            city_dest_point = city_dest[1], city_dest[2]
        except:
            self.ui.DestinationText.setText('Pending...')
            city_dest_point = None

        self.ui.vidText.setText(str(info[0][0]))
        try:
            code_airline = callsign[:3]
            airlineCodePath = (ImageAirlines + '/%s.gif') % code_airline
            if os.path.exists(airlineCodePath) is True:
                Pixmap = QPixmap(airlineCodePath)
                airline = QLabel(self)
                self.ui.airline_image.setPixmap(Pixmap)
            else:
                Q_db = SQL_queries.sql_query('Get_Airline', str(callsign[:3]))
                airline_code = Q_db.fetchone()
                self.ui.airline_image.setText(str(airline_code[0]))
        except:
            pass
        self.ui.callsign_text.setText(callsign)
        self.ui.PilotNameText.setText(str(info[0][1][:-4].encode('latin-1')))
        self.ui.RouteText.setText(str(info[0][9]))
        self.ui.GroundSpeedNumber.setText(str(info[0][3]))
        self.ui.AltitudeNumber.setText(str(info[0][2]))
        self.ui.PobText.setText(str(info[0][8]))
        self.ui.TransponderText.setText(str(info[0][11]))
        self.ui.GSFiledText.setText(str(info[0][17]))
        self.ui.FLText.setText(str(info[0][7]))
        Q_db = SQL_queries.sql_query('Get_Airport_from_ICAO',
                                     (str(info[0][15]), ))
        altern_city_1 = Q_db.fetchone()
        Q_db = SQL_queries.sql_query('Get_Airport_from_ICAO',
                                     (str(info[0][16]), ))
        altern_city_2 = Q_db.fetchone()
        if altern_city_1 is None:
            self.ui.Altern_Airport_Text.setText(str('-'))
        else:
            self.ui.Altern_Airport_Text.setText(str(altern_city_1[0]))
        if altern_city_2 is None:
            self.ui.Altern_Airport_Text_2.setText(str('-'))
        else:
            self.ui.Altern_Airport_Text_2.setText(str(altern_city_2[0]))
        try:
            if str(info[0][4]) != '':
                Q_db = SQL_queries.sql_query('Get_Model',
                                             ((info[0][4].split('/')[1]), ))
                data = Q_db.fetchall()
                self.ui.AirplaneText.setText('Model: %s Fabricant: %s Description: %s' \
                                             % (str(data[0][0]), str(data[0][1]), str(data[0][2])))
        except:
            self.ui.AirplaneText.setText('Pending...')
        Q_db = SQL_queries.sql_query('Get_Country_from_ICAO',
                                     (str(info[0][1][-4:]), ))
        flagCodeHome = Q_db.fetchone()
        flagCodePath = (ImageFlags + '/%s.png') % flagCodeHome
        Pixmap = QPixmap(flagCodePath)
        self.ui.HomeFlag.setPixmap(Pixmap)
        ratingImage = ImageRatings + '/pilot_level%d.gif' % int(info[0][10])
        Pixmap = QPixmap(ratingImage)
        self.ui.rating_img.setPixmap(Pixmap)
        player_point = info[0][13], info[0][14]
        if city_orig_point is None or city_dest_point is None:
            self.ui.nauticalmiles.setText('Pending...')
            self.ui.progressBarTrack.setValue(0)
        if str(info[0][5]) == str(info[0][6]):
            self.ui.progressBarTrack.setValue(0)
            self.ui.nauticalmiles.setText('Local Flight')
            eta = '00:00:00.000000'
        else:
            try:
                total_miles = distance.distance(city_orig_point,
                                                city_dest_point).miles
                dist_traveled = distance.distance(city_orig_point,
                                                  player_point).miles
                percent = float((dist_traveled / total_miles) * 100.0)
                eta = str(
                    datetime.timedelta(hours=((total_miles - dist_traveled) /
                                              float(info[0][3]))))
            except:
                if city_orig_point or city_dest_point is None:
                    percent = 0.0
                eta = '00:00:00.000000'
            self.ui.nauticalmiles.setText(
                '%.1f / %.1f miles - %.1f%%' %
                (float(dist_traveled), float(total_miles), float(percent)))
            self.ui.progressBarTrack.setValue(int(percent))
        status_plane = StatusFlight.status_flight(callsign)
        self.ui.FlightStatusDetail.setText(str(status_plane))
        self.ui.ETA_Arrive.setText(str(eta)[:-7])
        try:
            start_connected = datetime.datetime(int(str(info[0][18])[:4]),
                                                int(str(info[0][18])[4:6]),
                                                int(str(info[0][18])[6:8]),
                                                int(str(info[0][18])[8:10]),
                                                int(str(info[0][18])[10:12]),
                                                int(str(info[0][18])[12:14]))
            diff = datetime.datetime.utcnow() - start_connected
            self.ui.time_online_text.setText(str(diff)[:-7])
        except:
            self.ui.time_online_text.setText('Pending...')
コード例 #9
0
def status_flight(callsign):
    """This function is to get the action of the Pilot but for now I try to show using percent and
       some ground speeds of the track. I'm pretty sure with more check VARS can better this part"""
    Q_db = SQL_queries.sql_query('Get_Status', (str(callsign), ))
    get_status = Q_db.fetchone()
    status = '-'
    for row_pilot in get_status:
        try:
            Q_db = SQL_queries.sql_query('Get_City', (str(get_status[2]), ))
            city_orig = Q_db.fetchone()
            city_orig_point = float(city_orig[1]), float(city_orig[2])
            Q_db = SQL_queries.sql_query('Get_City', (str(get_status[3]), ))
            city_dest = Q_db.fetchone()
            city_dest_point = float(city_dest[1]), float(city_dest[2])
            pilot_position = get_status[8], get_status[9]
            total_miles = distance.distance(city_orig_point,
                                            city_dest_point).miles
            dist_traveled = distance.distance(city_orig_point,
                                              pilot_position).miles
            percent = (float(dist_traveled) / float(total_miles)) * 100.0

            if percent > 105:
                status = 'Diverted'
                return status
            else:
                if int(str(get_status[4])) == 0:
                    if (percent >= 0.0) and (percent <= 2.0):
                        status = 'Takeoff'
                    if (percent >= 2.0) and (percent <= 7.0):
                        status = 'Initial Climbing'
                    if (percent >= 7.0) and (percent <= 10.0):
                        status = 'Climbing'
                    if (percent >= 10.0) and (percent <= 80.0):
                        status = 'On Route'
                    if (percent >= 80.0) and (percent <= 90.0):
                        status = 'Descending'
                    if (percent >= 90.0) and (percent <= 97.0):
                        status = 'Initial Approach'
                    if (97.0 <= percent <= 105.0) and (360 >= get_status[6] >=
                                                       30):
                        status = 'Final Approach'
                    return status
                else:
                    if (0 < get_status[6] <= 30) and (percent < 1.0):
                        status = 'Departing'
                    if (get_status[6] > 30) and (get_status[6] <
                                                 150) and (percent < 1.0):
                        status = 'Takeoff'
                    if (97.0 <= percent <= 105.0) and (270 >= get_status[6] >=
                                                       30):
                        status = 'Landed'
                    if (get_status[6] < 30) and (percent > 99.0):
                        status = 'Taxing to Gate'
                    if (get_status[6] == 0) and (percent > 99.0):
                        status = 'On Blocks'
                    if (get_status[6] == 0) and (percent <= 1.0):
                        status = 'Boarding'
                    if (get_status[6] == 0) and (10.0 <= percent <= 90.0):
                        status = 'Altern Airport'
                    return status
        except:
            status = 'Fill Flight Plan'
            return status
コード例 #10
0
ファイル: Schedule.py プロジェクト: emper0r/IVAO-status
def Scheduling():
    """This part is a parse HTML from Schedule website from IVAO, because i can't access
       directly to IVAO database to download schedule, so I have to get by other way where users can
       see the schedule for controllers and pilots"""
    config = ConfigParser.RawConfigParser()
    config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../Config.cfg')
    config.read(config_file)
    SQL_queries.sql_query('Clear_Scheduling_tables')
    parser = etree.HTMLParser()
    qApp.processEvents()
    try:
        use_proxy = config.getint('Settings', 'use_proxy')
        auth = config.getint('Settings', 'auth')
        host = config.get('Settings', 'host')
        port = config.get('Settings', 'port')
        user = config.get('Settings', 'user')
        pswd = config.get('Settings', 'pass')
        if use_proxy == 2 and auth == 2:
            passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
            passmgr.add_password(None, 'http://' + host + ':' + port, user, pswd)
            authinfo = urllib2.ProxyBasicAuthHandler(passmgr)
            proxy_support = urllib2.ProxyHandler({"http" : "http://" + host + ':' + port})
            opener = urllib2.build_opener(proxy_support, authinfo)
            urllib2.install_opener(opener)
            QNetworkProxy.setApplicationProxy(QNetworkProxy(QNetworkProxy.HttpProxy, str(host), int(port), str(user), str(pswd)))
        if use_proxy == 2 and auth == 0:
            proxy_support = urllib2.ProxyHandler({"http" : "http://" + host + ':' + port})
            opener = urllib2.build_opener(proxy_support)
            urllib2.install_opener(opener)
            QNetworkProxy.setApplicationProxy(QNetworkProxy(QNetworkProxy.HttpProxy, str(host), int(port)))
        if use_proxy == 0 and auth == 0:
            pass

        """This lines set locales of enviroment at default "English" language to can parse with web"""
        save_locale = locale.getlocale()
        locale.setlocale(locale.LC_ALL, 'C')

        SchedATC_URL = urllib2.urlopen(config.get('Info', 'scheduling_atc')).read()
        tree = etree.parse(StringIO.StringIO(SchedATC_URL), parser)
        table_atc = tree.xpath("/html/body/div/center/table")[0]
        actual_today = datetime.datetime.today()

        for line_atc_table in table_atc[1:]:
            for day in range(actual_today.day, 31):
                if '%s %s' % (day, calendar.month_name[datetime.datetime.now().month]) in line_atc_table[4][0].text:
                    columns = [td[0].text for td in line_atc_table]
                    SQL_queries.sql_query('Add_Schedule_ATC', columns)
                    qApp.processEvents()

        SchedFlights_URL = urllib2.urlopen(config.get('Info', 'scheduling_flights')).read()
        tree = etree.parse(StringIO.StringIO(SchedFlights_URL), parser)
        table_flights = tree.xpath("/html/body/div/div/center/table")[0]

        for line_flights_table in table_flights[2:]:
            for day in range(actual_today.day, 31):
                if '%s %s' % (day, calendar.month_name[datetime.datetime.now().month]) in line_flights_table[7][0].text:
                    columns = [td[0].text for td in line_flights_table]
                    SQL_queries.sql_query('Add_Schedule_Flights', columns)
                    qApp.processEvents()

        """Restore locales"""
        locale.setlocale(locale.LC_ALL, save_locale)
        return True
    except IOError:
            return False