Ejemplo n.º 1
0
    def __init__(self, log):
        QNetworkProxyFactory.__init__(self)
        proxies = get_proxies()
        self.proxies = {}
        for scheme, proxy_string in proxies.iteritems():
            scheme = scheme.lower()
            info = get_proxy_info(scheme, proxy_string)
            if info is None:
                continue
            hn, port = info['hostname'], info['port']
            if not hn or not port:
                continue
            log.debug('JSBrowser using proxy:', pprint.pformat(info))
            pt = {
                'socks5': QNetworkProxy.Socks5Proxy
            }.get(scheme, QNetworkProxy.HttpProxy)
            proxy = QNetworkProxy(pt, hn, port)
            un, pw = info['username'], info['password']
            if un:
                proxy.setUser(un)
            if pw:
                proxy.setPassword(pw)
            self.proxies[scheme] = proxy

        self.default_proxy = QNetworkProxy(QNetworkProxy.DefaultProxy)
Ejemplo n.º 2
0
    def __init__(self, log):
        QNetworkProxyFactory.__init__(self)
        proxies = get_proxies()
        self.proxies = {}
        for scheme, proxy_string in proxies.iteritems():
            scheme = scheme.lower()
            info = get_proxy_info(scheme, proxy_string)
            if info is None: continue
            hn, port = info['hostname'], info['port']
            if not hn or not port: continue
            log.debug('JSBrowser using proxy:', pprint.pformat(info))
            pt = {'socks5':QNetworkProxy.Socks5Proxy}.get(scheme,
                    QNetworkProxy.HttpProxy)
            proxy = QNetworkProxy(pt, hn, port)
            un, pw = info['username'], info['password']
            if un:
                proxy.setUser(un)
            if pw:
                proxy.setPassword(pw)
            self.proxies[scheme] = proxy

        self.default_proxy = QNetworkProxy(QNetworkProxy.DefaultProxy)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def __init__(self, *args):
        QWebView.__init__(self, *args)
        self.gui = None
        self.tags = ''

        self._page = NPWebPage()
        self.setPage(self._page)
        self.cookie_jar = QNetworkCookieJar()
        self.page().networkAccessManager().setCookieJar(self.cookie_jar)

        http_proxy = get_proxies().get('http', None)
        if http_proxy:
            proxy_parts = urlparse(http_proxy)
            proxy = QNetworkProxy()
            proxy.setType(QNetworkProxy.HttpProxy)
            if proxy_parts.username:
                proxy.setUser(proxy_parts.username)
            if proxy_parts.password:
                proxy.setPassword(proxy_parts.password)
            if proxy_parts.hostname:
                proxy.setHostName(proxy_parts.hostname)
            if proxy_parts.port:
                proxy.setPort(proxy_parts.port)
            self.page().networkAccessManager().setProxy(proxy)

        self.page().setForwardUnsupportedContent(True)
        self.page().unsupportedContent.connect(self.start_download)
        self.page().downloadRequested.connect(self.start_download)
        self.page().networkAccessManager().sslErrors.connect(self.ignore_ssl_errors)
Ejemplo n.º 5
0
    def __init__(self, *args):
        QWebView.__init__(self, *args)
        self.gui = None
        self.tags = ''

        self.setPage(NPWebPage())
        self.page().networkAccessManager().setCookieJar(QNetworkCookieJar())

        http_proxy = get_proxies().get('http', None)
        if http_proxy:
            proxy_parts = urlparse(http_proxy)
            proxy = QNetworkProxy()
            proxy.setType(QNetworkProxy.HttpProxy)
            if proxy_parts.username:
                proxy.setUser(proxy_parts.username)
            if proxy_parts.password:
                proxy.setPassword(proxy_parts.password)
            if proxy_parts.hostname:
                proxy.setHostName(proxy_parts.hostname)
            if proxy_parts.port:
                proxy.setPort(proxy_parts.port)
            self.page().networkAccessManager().setProxy(proxy)

        self.page().setForwardUnsupportedContent(True)
        self.page().unsupportedContent.connect(self.start_download)
        self.page().downloadRequested.connect(self.start_download)
        self.page().networkAccessManager().sslErrors.connect(
            self.ignore_ssl_errors)
Ejemplo n.º 6
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