Skip to content

Instantly share code, notes, and snippets.

@henull
Last active August 3, 2017 08:30
Show Gist options
  • Save henull/1823a8c2b381715117caf1de2d216ff0 to your computer and use it in GitHub Desktop.
Save henull/1823a8c2b381715117caf1de2d216ff0 to your computer and use it in GitHub Desktop.
Dilbert getter
"""
Gets today's Dilbert comic strip, and opens default browser directly to the image.
"""
import datetime
import requests
import webbrowser
BASEURL = "http://dilbert.com/strip/"
DATEPART = datetime.datetime.now().date()
URL = BASEURL+str(DATEPART)
source_code = requests.get(URL)
STRIP_URL = "http://dilbert.com"
for line in source_code.content.split('\n'):
if "data-image=" in line:
items = line.split(' ')
for item in items:
if 'data-image=' in item:
i = item.split('=')
STRIP_URL = i[1].strip('"')
webbrowser.open(STRIP_URL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment