Skip to content

Instantly share code, notes, and snippets.

@DrBeta

DrBeta/Dilbert.py

Last active May 31, 2020
Embed
What would you like to do?
Dilbert.py

Dilbert.py

This is a little python script to scrape the Dilbert of today and displays it. To install dependencies, use $ pip install requests BeautifulSoup4 Pillow

import requests
import urllib.request
import time
from bs4 import BeautifulSoup
import io
import datetime
import urllib
from PIL import Image
def DilbertURL(dateToFetch):
formatted_date = '{0}-{1}-{2}'.format(dateToFetch.year, dateToFetch.month, dateToFetch.day)
todays_page = 'http://dilbert.com/strip/{0}/'.format(formatted_date)
response = requests.get(todays_page)
dilbert_page_source = BeautifulSoup(response.text, 'html.parser')
link = dilbert_page_source.find("img", class_='img-comic')['src']
return "https:" + str(link)
print(DilbertURL(datetime.datetime.now()))
response = requests.get(DilbertURL(datetime.datetime.now()))
dilbert = Image.open(io.BytesIO(response.content))
dilbert.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment