Skip to content

Instantly share code, notes, and snippets.

@DrBeta
Last active May 31, 2020 03:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrBeta/3d1233510fde10da7a91dd55e8d78404 to your computer and use it in GitHub Desktop.
Save DrBeta/3d1233510fde10da7a91dd55e8d78404 to your computer and use it in GitHub Desktop.
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