How to use the zdict.exceptions.APIKeyError function in zdict

To help you get started, we’ve selected a few zdict examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zdict / zdict / zdict / dictionaries / oxford.py View on Github external
app_id,app_key

        .. note:: request limit
            request limit: per minute is 60, per month is 3000.
        """
        if not os.path.exists(self.KEY_FILE):
            self.color.print('You can get an API key by the following steps:',
                             'yellow')
            print('1. Register a developer account at '
                  'https://developer.oxforddictionaries.com/')
            print('2. Get the application id & keys in the `credentials` page')
            print('3. Paste the API key at `{key_file}` in the foramt:'.format(
                key_file=self.KEY_FILE
            ))
            print('     app_id, app_key')
            raise APIKeyError('Oxford: API key not found')

        with open(self.KEY_FILE) as fp:
            keys = fp.read()

        keys = re.sub(r'\s', '', keys).split(',')
        if len(keys) != 2:
            print('The API key should be placed in the format:')
            print('     app_id, app_key')
            raise APIKeyError('Oxford: API key file format not correct.')

        return keys
github zdict / zdict / zdict / dictionaries / oxford.py View on Github external
'https://developer.oxforddictionaries.com/')
            print('2. Get the application id & keys in the `credentials` page')
            print('3. Paste the API key at `{key_file}` in the foramt:'.format(
                key_file=self.KEY_FILE
            ))
            print('     app_id, app_key')
            raise APIKeyError('Oxford: API key not found')

        with open(self.KEY_FILE) as fp:
            keys = fp.read()

        keys = re.sub(r'\s', '', keys).split(',')
        if len(keys) != 2:
            print('The API key should be placed in the format:')
            print('     app_id, app_key')
            raise APIKeyError('Oxford: API key file format not correct.')

        return keys
github zdict / zdict / zdict / dictionary.py View on Github external
if not self.args.disable_db_cache:
            record = self.query_db_cache(word)

            if record:
                self.show(record)
                return

        try:
            record = self.query(word)
        except exceptions.NoNetworkError as e:
            self.color.print(e, 'red')
            print()
        except exceptions.TimeoutError as e:
            self.color.print(e, 'red')
            print()
        except exceptions.APIKeyError as e:
            self.color.print(e, 'red')
            print()
        except exceptions.NotFoundError as e:
            self.color.print(e, 'yellow')
            print()
        except Exception:
            import traceback
            traceback.print_exc()
            url = "https://github.com/zdict/zdict/issues"
            print()
            print("We have problem for this word 😢")
            print("Please report this word to {}".format(url))
            print("Dictionary: {}".format(self.title))
            print("Word: '{}'".format(word))
            import sys
            sys.exit(1)