How to use the micawber.exceptions.ProviderNotFoundException 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 armadillica / dillo / dillo / api / posts / hooks.py View on Github external
def generate_oembed(item):
    # Generate embed code for links.
    try:
        content = item['properties']['content']
    except KeyError:
        # TODO investigate under which circumstances this is allowed
        item['properties']['content_html'] = ''
    else:
        try:
            oembed = current_dillo.oembed_registry.request(content)
            content_html = oembed['html']
        except (ProviderNotFoundException, ProviderException):
            # If the link is not an OEmbed provider, content_html is empty
            content_html = None
        item['properties']['content_html'] = content_html
github aldryn / aldryn-video / aldryn_video / utils.py View on Github external
def get_embed_code(**kwargs):
    try:
        data = providers.request(**kwargs)
    except (ProviderNotFoundException, ProviderException) as e:
        raise Exception(e.message)
    else:
        return data
github armadillica / dillo / dillo / application / modules / posts / __init__.py View on Github external
category=category,
                        uuid=uuid,
                        slug=post.slug))

    oembed = None
    # If the content is a link, we try to pass it through micawber to do
    # some nice embedding
    if post.post_type_id == 1:
        try:
            oembed = registry.request(post.content)
            # Keep in mind that oembed can be of different types:
            # - photo
            # - video
            # - link
            # - etc
        except (ProviderNotFoundException, ProviderException):
            # If the link is not an OEmbed provider, we move on
            pass
        else:
            # For any other error (e.g. video was unpublished) we also pass
            pass

    form = CommentForm()
    if current_user.is_anonymous():
        current_user.is_owner = False
    elif current_user.is_authenticated() and post.user.id == current_user.id:
        current_user.is_owner = True
    return render_template('posts/view.html',
                           title='view',
                           post=post,
                           oembed=oembed,
                           form=form,
github armadillica / dillo / dillo / web / posts / routes.py View on Github external
# If the URL is relative
        if not urlparse(icon_link_href).netloc:
            icon_link_href = urljoin(url_no_query, icon_link_href)
        parsed_page['favicon'] = icon_link_href

    parsed_page['images'] = []

    # Look for oembed
    try:
        oembed = current_dillo.oembed_registry.request(r.url)
        parsed_page['oembed'] = oembed['html']
        if 'thumbnail_url' in oembed:
            validate_append_image(oembed['thumbnail_url'], url_no_query, parsed_page['images'])
            log.debug('Appending image %s and returning' % oembed['thumbnail_url'])
            return jsonify(parsed_page)
    except (ProviderNotFoundException, ProviderException):
        log.debug('No Oembed thumbnail found')

    # Get meta Open Graph
    images_og = soup.find_all('meta', attrs={'property': 'og:image'})
    for image_og in images_og:
        validate_append_image(image_og['content'], url_no_query, parsed_page['images'])

    # Get meta Twitter, only if Open Graph is not available
    image_tw = soup.find('meta', attrs={'name': 'twitter:image'})
    if image_tw and not images_og:
        validate_append_image(image_tw['content'], url_no_query, parsed_page['images'])

    # Get all images
    images = soup.find_all('img', attrs={'src': compile('.')})
    log.debug('Found %i images' % len(images))
    for image in images:
github django-fluent / django-fluent-contents / fluent_contents / plugins / oembeditem / management / commands / debug_oembed.py View on Github external
def handle(self, *args, **options):
        if not args:
            raise CommandError("Missing URL parameter")

        for url in args:
            try:
                data = get_oembed_data(url)
            except ProviderNotFoundException:
                self.stderr.write("* No OEmbed provider found for '{0}'!\n".format(url))
            except ProviderException as e:
                # Real urllib2 exception is sadly hidden by micawber.
                self.stderr.write("* {0}\n".format(e))
            else:
                self.stdout.write("* OEmbed data for '{0}':\n".format(url))

                for key in sorted(data.keys()):
                    self.stdout.write("  - {0}: {1}\n".format(key, pformat(data[key])))
github coleifer / micawber / micawber / providers.py View on Github external
def request(self, url, **params):
        provider = self.provider_for_url(url)
        if provider:
            return provider.request(url, **params)
        raise ProviderNotFoundException('Provider not found for "%s"' % url)
github divio / djangocms-oembed / djangocms_oembed / models.py View on Github external
def clean(self):
        extra = {}
        if self.width:
            extra['maxwidth'] = self.width
        if self.height:
            extra['maxheight'] = self.height
        extra['autoplay'] = self.autoplay
        extra['rel'] = self.show_related
        extra['loop'] = self.loop
        extra['title'] = False  # Vimeo
        extra['byline'] = False  # Vimeo
        extra['portrait'] = False  # Vimeo
        try:
            data = providers.request(self.oembed_url, **extra)
        except ProviderNotFoundException, e:
            raise ValidationError(e.message)
        except ProviderException, e:
            raise ValidationError(e.message)
        if not data['type'] == 'video':
            raise ValidationError('This must be an url for a video. The "%(type)s" type is not supported.' % {'type': data['type']},)
        self.type = data.get('type', '')
        self.provider = data.get('provider_name', '')
        html = data.get('html', '')
        if 'provider_name' in data and self.provider in ['YouTube', 'Vimeo']:
            # dirty special handling of youtube and vimeo.
            # they ignore these parameters over oembed... so we use our own template to render them.
            iframe_html = PyQuery(html)
            url = iframe_html.attr('src')
            params = {
                'autoplay': int(self.autoplay),
                'loop': int(self.loop),