def media_in_content(self, content): """ check if the content contains and url of an image for the moment, check twitter media url could be elaborate with other service when needed :param content: :return: """ local_file = '' if 'https://t.co' in content: content = re.sub(r'https://t.co/(\w+)', '', content) if 'https://pbs.twimg.com/media/' in content: m = re.search('https://pbs.twimg.com/media/([\w\-_]+).jpg', content) # NOQA url = 'https://pbs.twimg.com/media/{}.jpg'.format(m.group(1)) local_file = download_image(url) content = re.sub(r'https://pbs.twimg.com/media/([\w\-_]+).jpg', '', # NOQA content) return content, local_file return content, local_file
def test_download_image(self): url = 'https://foxmask.net/static/ouaf.jpg' local_filename = download_image(url) self.assertTrue(type(str), local_filename)