How to use the micawber.ProviderException function in micawber

To help you get started, we’ve selected a few micawber 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 fin / memorial-page / submissions / models.py View on Github external
def save(self, *args, **kwargs):
        providers = micawber.bootstrap_basic()
        try:
            self.embed = providers.request(self.link)['html']
        except micawber.ProviderException,e:
            self.embed = None
        super(Link,self).save(*args, **kwargs)
github coleifer / micawber / examples / python_ex / example.py View on Github external
def main():
    print('Please wait, loading providers from oembed.com')
    providers = bootstrap_oembed()

    while 1:
        url = read_input('Enter a url (or q to quit): ')
        if url.lower().strip() == 'q':
            break

        try:
            result = providers.request(url)
        except ProviderException:
            print('No provider found for that url :/')
        else:
            print('Data for %s\n====================================================' % url)
            pprint.pprint(result)
github django-fluent / django-fluent-contents / fluent_contents / plugins / oembeditem / models.py View on Github external
def clean(self):
        # Avoid getting server errors when the URL is not valid.
        try:
            self.update_oembed_data()
        except ProviderException as e:
            raise ValidationError(str(e))
github onepercentclub / onepercentclub-site / apps / media / models.py View on Github external
def clean(self):
        """ Get OEmbed metadata on save. """

        # load up rules for some default providers, such as youtube and flickr
        providers = micawber.bootstrap_basic()

        # Get the data
        try:
            oembed_data = providers.request(self.url)
        except micawber.ProviderException as e:
            msg = _(u"Could not find metadata for object: %s" % e.message)
            raise ValidationError(msg)

        logger.debug(u'Found OEmbed data on %s for %s',self.url, self)

        for (key, value) in oembed_data.iteritems():
            try:
                if not getattr(self, key):
                    logger.debug(u'Setting field %s on %s to %s', key, self, value)
                    setattr(self, key, value)
            except AttributeError:
                pass
github ic-labs / django-icekit / icekit / templatetags / icekit_tags.py View on Github external
Render an OEmbed-compatible link as an embedded item.


    :param url: A URL of an OEmbed provider.
    :return: The OEMbed ```` code.
    """
    # Note: this method isn't currently very efficient - the data isn't
    # cached or stored.
    kwargs = dict(urlparse.parse_qsl(params))

    try:
        return mark_safe(get_oembed_data(
            url,
            **kwargs
        )['html'])
    except (KeyError, ProviderException):
        if settings.DEBUG:
            return "No OEmbed data returned"
        return ""