Esempio n. 1
0
    def __init__(self):
        self.proxies = {}
        for type, url in getproxies().items():
            self.proxies[type] = self._get_proxy(url, type)

        if not self.proxies:
            raise NotConfigured
Esempio n. 2
0
    def __init__(self, require_log_in = True, write_to_log = True):
        self.session = requests.session()
        self.session.proxies = getproxies()
        self.headers = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
            "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
            "X-Robinhood-API-Version": "1.171.0",
            "Connection": "keep-alive",
            "User-Agent": "Robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)"
        }
        self.is_logged_in = False
        self.write_to_log = write_to_log
        self.session.headers = self.headers
        self.require_log_in = require_log_in
        if self.require_log_in:
            status = self.login_prompt()
            if status:
                self.is_logged_in = True
                print 'successfully logged in...'

        if os.path.exists(self.cur_path + '/../cache/instruments.json') == False:
            self._instrument_symbol()

        with open(self.cur_path + '/../cache/instruments.json', 'r') as fp:
            self.instruments_symbol = json.load(fp)
Esempio n. 3
0
def set_proxy(proxy, user=None, password=''):
    """
    Set the HTTP proxy for Python to download through.

    If ``proxy`` is None then tries to set proxy from environment or system
    settings.

    :param proxy: The HTTP proxy server to use. For example:
        'http://proxy.example.com:3128/'
    :param user: The username to authenticate with. Use None to disable
        authentication.
    :param password: The password to authenticate with.
    """
    from nltk import compat

    if proxy is None:
        # Try and find the system proxy settings
        try:
            proxy = getproxies()['http']
        except KeyError:
            raise ValueError('Could not detect default proxy settings')

    # Set up the proxy handler
    proxy_handler = ProxyHandler({'https': proxy, 'http': proxy})
    opener = build_opener(proxy_handler)

    if user is not None:
        # Set up basic proxy authentication if provided
        password_manager = HTTPPasswordMgrWithDefaultRealm()
        password_manager.add_password(realm=None, uri=proxy, user=user, passwd=password)
        opener.add_handler(ProxyBasicAuthHandler(password_manager))
        opener.add_handler(ProxyDigestAuthHandler(password_manager))

    # Overide the existing url opener
    install_opener(opener)
Esempio n. 4
0
def set_proxy(proxy, user=None, password=''):
    """
    Set the HTTP proxy for Python to download through.

    If ``proxy`` is None then tries to set proxy from environment or system
    settings.

    :param proxy: The HTTP proxy server to use. For example:
        'http://proxy.example.com:3128/'
    :param user: The username to authenticate with. Use None to disable
        authentication.
    :param password: The password to authenticate with.
    """
    from nltk import compat

    if proxy is None:
        # Try and find the system proxy settings
        try:
            proxy = getproxies()['http']
        except KeyError:
            raise ValueError('Could not detect default proxy settings')

    # Set up the proxy handler
    proxy_handler = ProxyHandler({'https': proxy, 'http': proxy})
    opener = build_opener(proxy_handler)

    if user is not None:
        # Set up basic proxy authentication if provided
        password_manager = HTTPPasswordMgrWithDefaultRealm()
        password_manager.add_password(realm=None, uri=proxy, user=user, passwd=password)
        opener.add_handler(ProxyBasicAuthHandler(password_manager))
        opener.add_handler(ProxyDigestAuthHandler(password_manager))

    # Overide the existing url opener
    install_opener(opener)
 def __init__(self, auth_encoding='latin-1', host=None):
     super(RandomProxyMiddleware, self).__init__()
     self.auth_encoding = auth_encoding
     self.proxies = {}
     self.host = host
     for type, url in getproxies().items():
         self.proxies[type] = self._get_proxy(url, type)
Esempio n. 6
0
    def __init__(self):
        self.proxies = {}
        for type, url in getproxies().items():
            self.proxies[type] = self._get_proxy(url, type)

        if not self.proxies:
            raise NotConfigured
Esempio n. 7
0
    def __init__(self, auth_encoding='latin-1'):
        self.auth_encoding = auth_encoding
        self.proxies = {}
        for type, url in getproxies().items():
            self.proxies[type] = self._get_proxy(url, type)

        if not self.proxies:
            raise NotConfigured
Esempio n. 8
0
    def __init__(self, auth_encoding='latin-1'):
        self.auth_encoding = auth_encoding
        self.proxies = {}
        for type, url in getproxies().items():
            self.proxies[type] = self._get_proxy(url, type)

        if not self.proxies:
            raise NotConfigured
Esempio n. 9
0
 def _update_proxies(self):
     self.proxies = [[None, None]]
     # skip system proxy
     for type, url in getproxies().items():
         creds, proxy_url = self._get_proxy(url, type)
         if type in ('http', 'https'):               
             self.proxies.append([creds, proxy_url])
     for url in get_http_proxies():
         self.proxies.append([None, url])
     logger.debug('Update proxy list {0}'.format(self.proxies))
Esempio n. 10
0
def get_proxies():
    """Get available proxies to use with requests library."""
    proxies = getproxies()
    filtered_proxies = {}
    for key, value in iteritems(proxies):
        if key.startswith('http://'):
            if not value.startswith('http://'):
                filtered_proxies[key] = 'http://{0}'.format(value)
            else:
                filtered_proxies[key] = value
    return filtered_proxies
Esempio n. 11
0
def get_proxies():
    """Get available proxies to use with requests library."""
    proxies = getproxies()
    filtered_proxies = {}
    for key, value in proxies.items():
        if key.startswith("http://"):
            if not value.startswith("http://"):
                filtered_proxies[key] = "http://{0}".format(value)
            else:
                filtered_proxies[key] = value
    return filtered_proxies
    def __init__(self, auth_encoding='latin-1'):
        self.auth_encoding = auth_encoding
        self.proxies = {
            "http":
            ("http://218.64.147.170:4275", "http://218.64.147.170:4275")
        }
        for type, url in getproxies().items():
            self.proxies[type] = self._get_proxy(url, type)

        if not self.proxies:
            raise NotConfigured
Esempio n. 13
0
 def __init__(self):
     self.session = requests.session()
     self.session.proxies = getproxies()
     self.headers = {
         "Accept": "*/*",
         "Accept-Encoding": "gzip, deflate",
         "Accept-Language": "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
         "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
         "X-robinhood-API-Version": "1.0.0",
         "Connection": "keep-alive",
         "User-Agent": "robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)"
     }
     self.session.headers = self.headers
Esempio n. 14
0
 def __init__(self):
     self.session = requests.session()
     self.session.proxies = getproxies()
     self.headers = {
         "Accept": "*/*",
         "Accept-Encoding": "gzip, deflate",
         "Accept-Language": "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
         "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
         "X-Robinhood-API-Version": "1.0.0",
         "Connection": "keep-alive",
         "User-Agent": "Robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)"
     }
     self.session.headers = self.headers
Esempio n. 15
0
def get_proxy_url(url):
    proxies = getproxies()
    url_parts = parse_url_config(url)

    proxy_keys = [
        url_parts['scheme'] + '://' + url_parts['netloc'], url_parts['scheme'],
        'all://' + url_parts['netloc'], 'all'
    ]

    for key in proxy_keys:
        if key in proxies:
            return proxies[key]

    return None
Esempio n. 16
0
    def __init__(self):
        self.session = requests.session()
        self.session.proxies = getproxies()

        self.headers = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "en;q=1",
            "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
            "X-Robinhood-API-Version": "1.0.0",
            "Connection": "keep-alive",
            "User-Agent": "Robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)",
            "Origin": "https://robinhood.com"
        }
        self.session.headers = self.headers
Esempio n. 17
0
 def __init__(self):
     self.session = requests.session()
     self.session.proxies = getproxies()
     self.headers = {
         "Accept":
         "*/*",
         "Accept-Encoding":
         "gzip, deflate",
         "Accept-Language":
         "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
         "Content-Type":
         "application/x-www-form-urlencoded; charset=utf-8",
         "Connection":
         "keep-alive",
         "User-Agent":
         "Robinhood/6.28.0 (com.robinhood.release.Robinhood; build:5771; iOS 11.4.1) Alamofire/4.5.1"
     }
     self.session.headers = self.headers
     self.auth_method = self.login_prompt
Esempio n. 18
0
    def __init__(self, username=None, password=None):
        self._crypto_trader = CryptoTrader(self)
        self.auth_token = None
        self.session = requests.session()
        self.session.proxies = getproxies()
        self.refresh_token = None
        self.session.headers = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
            "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
            "X-robinhood-API-Version": "1.265.0",
            "Connection": "keep-alive",
            "User-Agent": "robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)"
        }

        if password:
            assert username
        if username:
            self.login(username, password)
Esempio n. 19
0
 def __init__(self, auth_encoding='latin-1'):
     self.auth_encoding = auth_encoding
     self.proxies = {}
     for type_, url in getproxies().items():
         self.proxies[type_] = self._get_proxy(url, type_)
Esempio n. 20
0
def get_proxy():
    return request.getproxies().get('http')
Esempio n. 21
0
 def __init__(self, verbose):
     super(MainWindow, self).__init__()
     self.setWindowTitle(self.tr("Photini photo metadata editor"))
     self.setWindowIcon(QtGui.QIcon(os.path.join(data_dir, 'icon_48.png')))
     self.selection = list()
     # logger window
     self.loggerwindow = LoggerWindow(verbose)
     self.logger = logging.getLogger(self.__class__.__name__)
     # config store
     self.config_store = ConfigStore('editor')
     # set network proxy
     proxies = getproxies()
     if 'http' in proxies:
         parsed = urlparse(proxies['http'])
         QNetworkProxy.setApplicationProxy(
             QNetworkProxy(QNetworkProxy.HttpProxy, parsed.hostname,
                           parsed.port))
     # restore size
     size = self.width(), self.height()
     self.resize(
         *eval(self.config_store.get('main_window', 'size', str(size))))
     # image selector
     self.image_list = ImageList(self.config_store)
     self.image_list.selection_changed.connect(self.new_selection)
     self.image_list.new_metadata.connect(self.new_metadata)
     # spelling manager
     self.spelling_manager = SpellingManager(self.config_store)
     # prepare list of tabs and associated stuff
     self.tab_list = (
         {
             'name': self.tr('&Descriptive metadata'),
             'key': 'descriptive_metadata',
             'class': Descriptive
         },
         {
             'name': self.tr('&Technical metadata'),
             'key': 'technical_metadata',
             'class': Technical
         },
         {
             'name': self.tr('Map (&Google)'),
             'key': 'map_google',
             'class': GoogleMap
         },
         {
             'name': self.tr('Map (&Bing)'),
             'key': 'map_bing',
             'class': BingMap
         },
         {
             'name': self.tr('Map (&OSM)'),
             'key': 'map_osm',
             'class': OpenStreetMap
         },
         {
             'name': self.tr('&Flickr upload'),
             'key': 'flickr_upload',
             'class': FlickrUploader
         },
         {
             'name': self.tr('&Picasa upload'),
             'key': 'picasa_upload',
             'class': PicasaUploader
         },
         {
             'name': self.tr('&Import photos'),
             'key': 'import_photos',
             'class': Importer
         },
     )
     for tab in self.tab_list:
         if tab['class']:
             tab['object'] = tab['class'](self.config_store,
                                          self.image_list)
         else:
             tab['object'] = None
     # file menu
     file_menu = self.menuBar().addMenu(self.tr('File'))
     open_action = QtWidgets.QAction(self.tr('Open images'), self)
     open_action.setShortcuts(QtGui.QKeySequence.Open)
     open_action.triggered.connect(self.image_list.open_files)
     file_menu.addAction(open_action)
     self.save_action = QtWidgets.QAction(
         self.tr('Save images with new data'), self)
     self.save_action.setShortcuts(QtGui.QKeySequence.Save)
     self.save_action.setEnabled(False)
     self.save_action.triggered.connect(self.image_list.save_files)
     file_menu.addAction(self.save_action)
     self.close_action = QtWidgets.QAction(self.tr('Close selected images'),
                                           self)
     self.close_action.setEnabled(False)
     self.close_action.triggered.connect(self.close_files)
     file_menu.addAction(self.close_action)
     close_all_action = QtWidgets.QAction(self.tr('Close all images'), self)
     close_all_action.triggered.connect(self.close_all_files)
     file_menu.addAction(close_all_action)
     file_menu.addSeparator()
     quit_action = QtWidgets.QAction(self.tr('Quit'), self)
     quit_action.setShortcuts(
         [QtGui.QKeySequence.Quit, QtGui.QKeySequence.Close])
     quit_action.triggered.connect(
         QtWidgets.QApplication.instance().closeAllWindows)
     file_menu.addAction(quit_action)
     # options menu
     options_menu = self.menuBar().addMenu(self.tr('Options'))
     settings_action = QtWidgets.QAction(self.tr('Settings'), self)
     settings_action.triggered.connect(self.edit_settings)
     options_menu.addAction(settings_action)
     options_menu.addSeparator()
     for tab in self.tab_list:
         name = tab['name'].replace('&', '')
         tab['action'] = QtWidgets.QAction(name, self)
         tab['action'].setCheckable(True)
         if tab['class']:
             tab['action'].setChecked(
                 eval(self.config_store.get('tabs', tab['key'], 'True')))
         else:
             tab['action'].setEnabled(False)
         tab['action'].triggered.connect(self.add_tabs)
         options_menu.addAction(tab['action'])
     # spelling menu
     languages = self.spelling_manager.available_languages()
     spelling_menu = self.menuBar().addMenu(self.tr('Spelling'))
     enable_action = QtWidgets.QAction(self.tr('Enable spell check'), self)
     enable_action.setEnabled(bool(languages))
     enable_action.setCheckable(True)
     enable_action.setChecked(self.spelling_manager.enabled())
     enable_action.toggled.connect(self.spelling_manager.enable)
     spelling_menu.addAction(enable_action)
     language_menu = QtWidgets.QMenu(self.tr('Choose language'), self)
     language_menu.setEnabled(bool(languages))
     language_group = QtWidgets.QActionGroup(self)
     current_language = self.spelling_manager.current_language()
     for tag in languages:
         language_action = QtWidgets.QAction(tag, self)
         language_action.setCheckable(True)
         language_action.setChecked(tag == current_language)
         language_action.setActionGroup(language_group)
         language_menu.addAction(language_action)
     language_group.triggered.connect(self.spelling_manager.set_language)
     spelling_menu.addMenu(language_menu)
     # help menu
     help_menu = self.menuBar().addMenu(self.tr('Help'))
     about_action = QtWidgets.QAction(self.tr('About Photini'), self)
     about_action.triggered.connect(self.about)
     help_menu.addAction(about_action)
     help_menu.addSeparator()
     help_action = QtWidgets.QAction(self.tr('Photini documentation'), self)
     help_action.triggered.connect(self.open_docs)
     help_menu.addAction(help_action)
     # main application area
     self.central_widget = QtWidgets.QSplitter()
     self.central_widget.setOrientation(Qt.Vertical)
     self.central_widget.setChildrenCollapsible(False)
     self.tabs = QtWidgets.QTabWidget()
     self.tabs.currentChanged.connect(self.new_tab)
     self.add_tabs()
     self.central_widget.addWidget(self.tabs)
     self.central_widget.addWidget(self.image_list)
     size = self.central_widget.sizes()
     self.central_widget.setSizes(
         eval(self.config_store.get('main_window', 'split', str(size))))
     self.central_widget.splitterMoved.connect(self.new_split)
     self.setCentralWidget(self.central_widget)
Esempio n. 22
0
 def __init__(self, options, initial_files):
     super(MainWindow, self).__init__()
     self.setWindowTitle(self.tr("Photini photo metadata editor"))
     pixmap = QtGui.QPixmap()
     pixmap.loadFromData(pkg_resources.resource_string(
         'photini', 'data/icons/48/photini.png'))
     icon = QtGui.QIcon(pixmap)
     self.setWindowIcon(icon)
     self.selection = list()
     # logger window
     self.loggerwindow = LoggerWindow(options.verbose)
     self.loggerwindow.setWindowIcon(icon)
     # set network proxy
     proxies = getproxies()
     if 'http' in proxies:
         parsed = urlparse(proxies['http'])
         QNetworkProxy.setApplicationProxy(QNetworkProxy(
             QNetworkProxy.HttpProxy, parsed.hostname, parsed.port))
     # create shared global objects
     self.app = QtWidgets.QApplication.instance()
     self.app.config_store = ConfigStore('editor', parent=self)
     self.app.spell_check = SpellCheck(parent=self)
     self.app.test_mode = options.test
     # restore size
     size = self.width(), self.height()
     self.resize(*eval(
         self.app.config_store.get('main_window', 'size', str(size))))
     # image selector
     self.image_list = ImageList()
     self.image_list.selection_changed.connect(self.new_selection)
     self.image_list.new_metadata.connect(self.new_metadata)
     # update config file
     if self.app.config_store.config.has_section('tabs'):
         conv = {
             'descriptive_metadata': 'photini.descriptive',
             'technical_metadata'  : 'photini.technical',
             'map_google'          : 'photini.googlemap',
             'map_bing'            : 'photini.bingmap',
             'map_mapbox'          : 'photini.mapboxmap',
             'map_osm'             : 'photini.openstreetmap',
             'flickr_upload'       : 'photini.flickr',
             'import_photos'       : 'photini.importer',
             }
         for key in self.app.config_store.config.options('tabs'):
             if key in conv:
                 self.app.config_store.set(
                     'tabs', conv[key],
                     self.app.config_store.get('tabs', key))
                 self.app.config_store.config.remove_option('tabs', key)
     # prepare list of tabs and associated stuff
     self.tab_list = []
     modules = ('photini.descriptive', 'photini.technical',
                'photini.googlemap',   'photini.bingmap',
                'photini.mapboxmap',   'photini.openstreetmap',
                'photini.flickr',      'photini.googlephotos',
                'photini.importer')
     modules = eval(self.app.config_store.get(
         'tabs', 'modules', pprint.pformat(modules)))
     for module in modules:
         tab = {'module': module}
         try:
             mod = importlib.import_module(tab['module'])
             tab['class'] = mod.TabWidget
             tab['name'] = tab['class'].tab_name()
         except ImportError as ex:
             print(str(ex))
             tab['class'] = None
         self.tab_list.append(tab)
     # file menu
     file_menu = self.menuBar().addMenu(self.tr('File'))
     open_action = QtWidgets.QAction(self.tr('Open images'), self)
     open_action.setShortcuts(QtGui.QKeySequence.Open)
     open_action.triggered.connect(self.image_list.open_files)
     file_menu.addAction(open_action)
     self.save_action = QtWidgets.QAction(
         self.tr('Save images with new data'), self)
     self.save_action.setShortcuts(QtGui.QKeySequence.Save)
     self.save_action.setEnabled(False)
     self.save_action.triggered.connect(self.image_list.save_files)
     file_menu.addAction(self.save_action)
     self.close_action = QtWidgets.QAction(
         self.tr('Close selected images'), self)
     self.close_action.setEnabled(False)
     self.close_action.triggered.connect(self.close_files)
     file_menu.addAction(self.close_action)
     close_all_action = QtWidgets.QAction(self.tr('Close all images'), self)
     close_all_action.triggered.connect(self.close_all_files)
     file_menu.addAction(close_all_action)
     if GpxImporter:
         file_menu.addSeparator()
         self.import_gpx_action = QtWidgets.QAction(
             self.tr('Import GPX file'), self)
         self.import_gpx_action.triggered.connect(self.import_pgx_file)
         file_menu.addAction(self.import_gpx_action)
     else:
         self.import_gpx_action = None
     file_menu.addSeparator()
     quit_action = QtWidgets.QAction(self.tr('Quit'), self)
     quit_action.setShortcuts(
         [QtGui.QKeySequence.Quit, QtGui.QKeySequence.Close])
     quit_action.triggered.connect(
         QtWidgets.QApplication.instance().closeAllWindows)
     file_menu.addAction(quit_action)
     # options menu
     options_menu = self.menuBar().addMenu(self.tr('Options'))
     settings_action = QtWidgets.QAction(self.tr('Settings'), self)
     settings_action.triggered.connect(self.edit_settings)
     options_menu.addAction(settings_action)
     options_menu.addSeparator()
     for tab in self.tab_list:
         if tab['class']:
             name = tab['name'].replace('&', '')
         else:
             name = tab['module']
         tab['action'] = QtWidgets.QAction(name, self)
         tab['action'].setCheckable(True)
         if tab['class']:
             tab['action'].setChecked(eval(
                 self.app.config_store.get('tabs', tab['module'], 'True')))
         else:
             tab['action'].setEnabled(False)
         tab['action'].triggered.connect(self.add_tabs)
         options_menu.addAction(tab['action'])
     # spelling menu
     languages = self.app.spell_check.available_languages()
     spelling_menu = self.menuBar().addMenu(self.tr('Spelling'))
     enable_action = QtWidgets.QAction(self.tr('Enable spell check'), self)
     enable_action.setEnabled(languages is not None)
     enable_action.setCheckable(True)
     enable_action.setChecked(self.app.spell_check.enabled)
     enable_action.toggled.connect(self.app.spell_check.enable)
     spelling_menu.addAction(enable_action)
     language_menu = QtWidgets.QMenu(self.tr('Choose language'), self)
     language_menu.setEnabled(languages is not None)
     current_language = self.app.spell_check.current_language()
     if languages:
         language_group = QtWidgets.QActionGroup(self)
         for name, code in languages:
             if name != code:
                 name = code + ': ' + name
             language_action = QtWidgets.QAction(name, self)
             language_action.setCheckable(True)
             language_action.setChecked(code == current_language)
             language_action.setData(code)
             language_action.setActionGroup(language_group)
             language_menu.addAction(language_action)
         language_group.triggered.connect(self.set_language)
     else:
         language_action = QtWidgets.QAction(
             self.tr('No dictionary installed'), self)
         language_action.setEnabled(False)
         language_menu.addAction(language_action)
     spelling_menu.addMenu(language_menu)
     # help menu
     help_menu = self.menuBar().addMenu(self.tr('Help'))
     about_action = QtWidgets.QAction(self.tr('About Photini'), self)
     about_action.triggered.connect(self.about)
     help_menu.addAction(about_action)
     help_menu.addSeparator()
     help_action = QtWidgets.QAction(self.tr('Photini documentation'), self)
     help_action.triggered.connect(self.open_docs)
     help_menu.addAction(help_action)
     # main application area
     self.central_widget = QtWidgets.QSplitter()
     self.central_widget.setOrientation(Qt.Vertical)
     self.central_widget.setChildrenCollapsible(False)
     self.tabs = QtWidgets.QTabWidget()
     self.tabs.setTabBar(QTabBar())
     self.tabs.setElideMode(Qt.ElideRight)
     self.tabs.currentChanged.connect(self.new_tab)
     self.add_tabs(False)
     self.central_widget.addWidget(self.tabs)
     self.central_widget.addWidget(self.image_list)
     size = self.central_widget.sizes()
     self.central_widget.setSizes(eval(
         self.app.config_store.get('main_window', 'split', str(size))))
     self.central_widget.splitterMoved.connect(self.new_split)
     self.setCentralWidget(self.central_widget)
     # open files given on command line, after GUI is displayed
     self.initial_files = initial_files
     if self.initial_files:
         QtCore.QTimer.singleShot(0, self.open_initial_files)
Esempio n. 23
0
 def create_session(self):
     self.session = requests.session()
     self.session.proxies = getproxies()
     self.session.headers = {'Connection': 'keep-alive'}
Esempio n. 24
0
 def __init__(self, options, initial_files):
     super(MainWindow, self).__init__()
     self.setWindowTitle(self.tr("Photini photo metadata editor"))
     pixmap = QtGui.QPixmap()
     pixmap.loadFromData(
         pkg_resources.resource_string('photini',
                                       'data/icons/48/photini.png'))
     icon = QtGui.QIcon(pixmap)
     self.setWindowIcon(icon)
     self.selection = list()
     # logger window
     self.loggerwindow = LoggerWindow(options.verbose)
     self.loggerwindow.setWindowIcon(icon)
     self.logger = logging.getLogger(self.__class__.__name__)
     # set network proxy
     proxies = getproxies()
     if 'http' in proxies:
         parsed = urlparse(proxies['http'])
         QNetworkProxy.setApplicationProxy(
             QNetworkProxy(QNetworkProxy.HttpProxy, parsed.hostname,
                           parsed.port))
     # create shared global objects
     self.app = QtWidgets.QApplication.instance()
     self.app.config_store = ConfigStore('editor', parent=self)
     self.app.spell_check = SpellCheck(parent=self)
     self.app.test_mode = options.test
     # set debug mode
     if self.app.test_mode:
         debug_metadata()
     # restore size
     size = self.width(), self.height()
     self.resize(
         *eval(self.app.config_store.get('main_window', 'size', str(size))))
     # image selector
     self.image_list = ImageList()
     self.image_list.selection_changed.connect(self.new_selection)
     self.image_list.new_metadata.connect(self.new_metadata)
     # prepare list of tabs and associated stuff
     self.tab_list = (
         {
             'name': self.tr('&Descriptive metadata'),
             'key': 'descriptive_metadata',
             'class': Descriptive
         },
         {
             'name': self.tr('&Technical metadata'),
             'key': 'technical_metadata',
             'class': Technical
         },
         {
             'name': self.tr('Map (&Google)'),
             'key': 'map_google',
             'class': GoogleMap
         },
         {
             'name': self.tr('Map (&Bing)'),
             'key': 'map_bing',
             'class': BingMap
         },
         {
             'name': self.tr('Map (&OSM)'),
             'key': 'map_osm',
             'class': OpenStreetMap
         },
         {
             'name': self.tr('&Flickr upload'),
             'key': 'flickr_upload',
             'class': FlickrUploader
         },
         {
             'name': self.tr('Google &Photos upload'),
             'key': 'picasa_upload',
             'class': PicasaUploader
         },
         {
             'name': self.tr('Faceboo&k upload'),
             'key': 'facebook_upload',
             'class': FacebookUploader
         },
         {
             'name': self.tr('&Import photos'),
             'key': 'import_photos',
             'class': Importer
         },
     )
     # file menu
     file_menu = self.menuBar().addMenu(self.tr('File'))
     open_action = QtWidgets.QAction(self.tr('Open images'), self)
     open_action.setShortcuts(QtGui.QKeySequence.Open)
     open_action.triggered.connect(self.image_list.open_files)
     file_menu.addAction(open_action)
     self.save_action = QtWidgets.QAction(
         self.tr('Save images with new data'), self)
     self.save_action.setShortcuts(QtGui.QKeySequence.Save)
     self.save_action.setEnabled(False)
     self.save_action.triggered.connect(self.image_list.save_files)
     file_menu.addAction(self.save_action)
     self.close_action = QtWidgets.QAction(self.tr('Close selected images'),
                                           self)
     self.close_action.setEnabled(False)
     self.close_action.triggered.connect(self.close_files)
     file_menu.addAction(self.close_action)
     close_all_action = QtWidgets.QAction(self.tr('Close all images'), self)
     close_all_action.triggered.connect(self.close_all_files)
     file_menu.addAction(close_all_action)
     file_menu.addSeparator()
     quit_action = QtWidgets.QAction(self.tr('Quit'), self)
     quit_action.setShortcuts(
         [QtGui.QKeySequence.Quit, QtGui.QKeySequence.Close])
     quit_action.triggered.connect(
         QtWidgets.QApplication.instance().closeAllWindows)
     file_menu.addAction(quit_action)
     # options menu
     options_menu = self.menuBar().addMenu(self.tr('Options'))
     settings_action = QtWidgets.QAction(self.tr('Settings'), self)
     settings_action.triggered.connect(self.edit_settings)
     options_menu.addAction(settings_action)
     options_menu.addSeparator()
     for tab in self.tab_list:
         name = tab['name'].replace('&', '')
         tab['action'] = QtWidgets.QAction(name, self)
         tab['action'].setCheckable(True)
         if tab['class']:
             tab['action'].setChecked(
                 eval(self.app.config_store.get('tabs', tab['key'],
                                                'True')))
         else:
             tab['action'].setEnabled(False)
         tab['action'].triggered.connect(self.add_tabs)
         options_menu.addAction(tab['action'])
     # spelling menu
     languages = self.app.spell_check.available_languages()
     spelling_menu = self.menuBar().addMenu(self.tr('Spelling'))
     enable_action = QtWidgets.QAction(self.tr('Enable spell check'), self)
     enable_action.setEnabled(bool(languages))
     enable_action.setCheckable(True)
     enable_action.setChecked(self.app.spell_check.enabled)
     enable_action.toggled.connect(self.app.spell_check.enable)
     spelling_menu.addAction(enable_action)
     language_menu = QtWidgets.QMenu(self.tr('Choose language'), self)
     language_menu.setEnabled(bool(languages))
     language_group = QtWidgets.QActionGroup(self)
     current_language = self.app.spell_check.current_language()
     for tag in languages:
         language_action = QtWidgets.QAction(tag, self)
         language_action.setCheckable(True)
         language_action.setChecked(tag == current_language)
         language_action.setActionGroup(language_group)
         language_menu.addAction(language_action)
     language_group.triggered.connect(self.app.spell_check.set_language)
     spelling_menu.addMenu(language_menu)
     # help menu
     help_menu = self.menuBar().addMenu(self.tr('Help'))
     about_action = QtWidgets.QAction(self.tr('About Photini'), self)
     about_action.triggered.connect(self.about)
     help_menu.addAction(about_action)
     help_menu.addSeparator()
     help_action = QtWidgets.QAction(self.tr('Photini documentation'), self)
     help_action.triggered.connect(self.open_docs)
     help_menu.addAction(help_action)
     # main application area
     self.central_widget = QtWidgets.QSplitter()
     self.central_widget.setOrientation(Qt.Vertical)
     self.central_widget.setChildrenCollapsible(False)
     self.tabs = QtWidgets.QTabWidget()
     self.tabs.setTabBar(QTabBar())
     self.tabs.setElideMode(Qt.ElideRight)
     self.tabs.currentChanged.connect(self.new_tab)
     self.add_tabs()
     self.central_widget.addWidget(self.tabs)
     self.central_widget.addWidget(self.image_list)
     size = self.central_widget.sizes()
     self.central_widget.setSizes(
         eval(self.app.config_store.get('main_window', 'split', str(size))))
     self.central_widget.splitterMoved.connect(self.new_split)
     self.setCentralWidget(self.central_widget)
     # open files given on command line, after GUI is displayed
     self.initial_files = initial_files
     if self.initial_files:
         QtCore.QTimer.singleShot(0, self.open_initial_files)
Esempio n. 25
0
 def __init__(self, options, initial_files):
     super(MainWindow, self).__init__()
     self.setWindowTitle(self.tr("Photini photo metadata editor"))
     pixmap = QtGui.QPixmap()
     pixmap.loadFromData(pkg_resources.resource_string(
         'photini', 'data/icons/48/photini.png'))
     icon = QtGui.QIcon(pixmap)
     self.setWindowIcon(icon)
     self.selection = list()
     # logger window
     self.loggerwindow = LoggerWindow(options.verbose)
     self.loggerwindow.setWindowIcon(icon)
     self.logger = logging.getLogger(self.__class__.__name__)
     # set network proxy
     proxies = getproxies()
     if 'http' in proxies:
         parsed = urlparse(proxies['http'])
         QNetworkProxy.setApplicationProxy(QNetworkProxy(
             QNetworkProxy.HttpProxy, parsed.hostname, parsed.port))
     # create shared global objects
     self.app = QtWidgets.QApplication.instance()
     self.app.config_store = ConfigStore('editor', parent=self)
     self.app.spell_check = SpellCheck(parent=self)
     self.app.test_mode = options.test
     # restore size
     size = self.width(), self.height()
     self.resize(*eval(
         self.app.config_store.get('main_window', 'size', str(size))))
     # image selector
     self.image_list = ImageList()
     self.image_list.selection_changed.connect(self.new_selection)
     self.image_list.new_metadata.connect(self.new_metadata)
     # prepare list of tabs and associated stuff
     self.tab_list = (
         {'name'  : self.tr('&Descriptive metadata'),
          'key'   : 'descriptive_metadata',
          'class' : Descriptive},
         {'name'  : self.tr('&Technical metadata'),
          'key'   : 'technical_metadata',
          'class' : Technical},
         {'name'  : self.tr('Map (&Google)'),
          'key'   : 'map_google',
          'class' : GoogleMap},
         {'name'  : self.tr('Map (&Bing)'),
          'key'   : 'map_bing',
          'class' : BingMap},
         {'name'  : self.tr('Map (&OSM)'),
          'key'   : 'map_osm',
          'class' : OpenStreetMap},
         {'name'  : self.tr('&Flickr upload'),
          'key'   : 'flickr_upload',
          'class' : FlickrUploader},
         {'name'  : self.tr('Google &Photos upload'),
          'key'   : 'picasa_upload',
          'class' : PicasaUploader},
         {'name'  : self.tr('Faceboo&k upload'),
          'key'   : 'facebook_upload',
          'class' : FacebookUploader},
         {'name'  : self.tr('&Import photos'),
          'key'   : 'import_photos',
          'class' : Importer},
         )
     for tab in self.tab_list:
         if tab['class']:
             tab['object'] = tab['class'](self.image_list)
         else:
             tab['object'] = None
     # file menu
     file_menu = self.menuBar().addMenu(self.tr('File'))
     open_action = QtWidgets.QAction(self.tr('Open images'), self)
     open_action.setShortcuts(QtGui.QKeySequence.Open)
     open_action.triggered.connect(self.image_list.open_files)
     file_menu.addAction(open_action)
     self.save_action = QtWidgets.QAction(
         self.tr('Save images with new data'), self)
     self.save_action.setShortcuts(QtGui.QKeySequence.Save)
     self.save_action.setEnabled(False)
     self.save_action.triggered.connect(self.image_list.save_files)
     file_menu.addAction(self.save_action)
     self.close_action = QtWidgets.QAction(
         self.tr('Close selected images'), self)
     self.close_action.setEnabled(False)
     self.close_action.triggered.connect(self.close_files)
     file_menu.addAction(self.close_action)
     close_all_action = QtWidgets.QAction(self.tr('Close all images'), self)
     close_all_action.triggered.connect(self.close_all_files)
     file_menu.addAction(close_all_action)
     file_menu.addSeparator()
     quit_action = QtWidgets.QAction(self.tr('Quit'), self)
     quit_action.setShortcuts(
         [QtGui.QKeySequence.Quit, QtGui.QKeySequence.Close])
     quit_action.triggered.connect(
         QtWidgets.QApplication.instance().closeAllWindows)
     file_menu.addAction(quit_action)
     # options menu
     options_menu = self.menuBar().addMenu(self.tr('Options'))
     settings_action = QtWidgets.QAction(self.tr('Settings'), self)
     settings_action.triggered.connect(self.edit_settings)
     options_menu.addAction(settings_action)
     options_menu.addSeparator()
     for tab in self.tab_list:
         name = tab['name'].replace('&', '')
         tab['action'] = QtWidgets.QAction(name, self)
         tab['action'].setCheckable(True)
         if tab['class']:
             tab['action'].setChecked(
                 eval(self.app.config_store.get('tabs', tab['key'], 'True')))
         else:
             tab['action'].setEnabled(False)
         tab['action'].triggered.connect(self.add_tabs)
         options_menu.addAction(tab['action'])
     # spelling menu
     languages = self.app.spell_check.available_languages()
     spelling_menu = self.menuBar().addMenu(self.tr('Spelling'))
     enable_action = QtWidgets.QAction(self.tr('Enable spell check'), self)
     enable_action.setEnabled(bool(languages))
     enable_action.setCheckable(True)
     enable_action.setChecked(self.app.spell_check.enabled)
     enable_action.toggled.connect(self.app.spell_check.enable)
     spelling_menu.addAction(enable_action)
     language_menu = QtWidgets.QMenu(self.tr('Choose language'), self)
     language_menu.setEnabled(bool(languages))
     language_group = QtWidgets.QActionGroup(self)
     current_language = self.app.spell_check.current_language()
     for tag in languages:
         language_action = QtWidgets.QAction(tag, self)
         language_action.setCheckable(True)
         language_action.setChecked(tag == current_language)
         language_action.setActionGroup(language_group)
         language_menu.addAction(language_action)
     language_group.triggered.connect(self.app.spell_check.set_language)
     spelling_menu.addMenu(language_menu)
     # help menu
     help_menu = self.menuBar().addMenu(self.tr('Help'))
     about_action = QtWidgets.QAction(self.tr('About Photini'), self)
     about_action.triggered.connect(self.about)
     help_menu.addAction(about_action)
     help_menu.addSeparator()
     help_action = QtWidgets.QAction(self.tr('Photini documentation'), self)
     help_action.triggered.connect(self.open_docs)
     help_menu.addAction(help_action)
     # main application area
     self.central_widget = QtWidgets.QSplitter()
     self.central_widget.setOrientation(Qt.Vertical)
     self.central_widget.setChildrenCollapsible(False)
     self.tabs = QtWidgets.QTabWidget()
     self.tabs.setTabBar(QTabBar())
     self.tabs.setElideMode(Qt.ElideRight)
     self.tabs.currentChanged.connect(self.new_tab)
     self.add_tabs()
     self.central_widget.addWidget(self.tabs)
     self.central_widget.addWidget(self.image_list)
     size = self.central_widget.sizes()
     self.central_widget.setSizes(eval(
         self.app.config_store.get('main_window', 'split', str(size))))
     self.central_widget.splitterMoved.connect(self.new_split)
     self.setCentralWidget(self.central_widget)
     # open files given on command line, after GUI is displayed
     self.initial_files = initial_files
     if self.initial_files:
         QtCore.QTimer.singleShot(0, self.open_initial_files)
Esempio n. 26
0
 def open_spider(self, spider):
     logger.info('%s for httpproxy is used.',
                 self.settings['HTTPPROXY_STORAGE'])
     for type_, url in getproxies().items():
         self[type_] = get_proxy(url, type_, self.auth_encoding)