Exemplo n.º 1
0
def get_imgur_image(text):
    client_id = os.environ.get('IMGUR_CLIENT_ID')
    client_secret = os.environ.get('IMGUR_CLIENT_SECRET')

    if client_id and client_secret:

        client = ImgurClient(client_id, client_secret)
        tag = tag_from_text(text)

        if tag:
            try:
                gallery = client.gallery_tag(tag)
                gallery = gallery.items
            except ImgurClientError:
                return 'Tag {} not found'.format(tag)
        else:

            gallery = client.gallery()

        return random_link_from_gallery_list(gallery)
Exemplo n.º 2
0
    def test_text_with_tag(self):
        text = 'imgur tag_name other text'

        self.assertEqual('tag_name', tag_from_text(text))
Exemplo n.º 3
0
    def test_text_with_tag(self):
        text = 'imgur tag_name other text'

        self.assertEqual(
            'tag_name', tag_from_text(text)
        )
Exemplo n.º 4
0
 def test_text_without_more_text(self):
     text = 'imgur'
     self.assertEqual(None, tag_from_text(text))
Exemplo n.º 5
0
 def test_text_without_more_text(self):
     text = 'imgur'
     self.assertEqual(None, tag_from_text(text))