Is there a way to include a copied image in Python/Tweepy, I can't seem to do it using Pillow

27 views Asked by At

The question may be a little weird, but let me explain and give where I'm at.

I've made a twitter bot using tweepy that posts a random page every hour (given some criteria)

Right now this is what I have:

def tweet_random_species():
    while True:
        url = "https://species.wikimedia.org/wiki/Special:Random"
        response = requests.get(url)
        soup = BeautifulSoup(response.content, 'html.parser')

        photo = soup.find('figure', class_='mw-default-size')
        taxonavigation = soup.find('span', class_='mw-headline', id='Taxonavigation')
        title_elem = soup.find('h1', class_='firstHeading')

        if photo and taxonavigation:
            title = title_elem.text.strip()
            print(f"Title: {title}")
            print(response.url)
            client.create_tweet(text=f"{title}\n{response.url}")
            break

What I'd really like to do though is instead of printing the URL, I want only the photo and the title to print. I've tried to use Pillow to paste the image, and I was able to get the image URL from Requests and BeautifulSoup4, but it tweets as text.

Is there anyway to copy and paste the image from the the random URL? I don't think I would need help if I had all the images already saved, but I don't want to save the photo, I just want to "copy image" and paste it into the tweet. Is there anyway I can do this?

0

There are 0 answers