Skip to content

Instantly share code, notes, and snippets.

@rmporsch
Created August 16, 2015 13:52
Show Gist options
  • Save rmporsch/a1c631355dfd97def065 to your computer and use it in GitHub Desktop.
Save rmporsch/a1c631355dfd97def065 to your computer and use it in GitHub Desktop.
Episode Crawler
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
from bs4 import BeautifulSoup
import ConfigParser
configFile = '~/.episodeSearch.config'
config = ConfigParser.RawConfigParser()
config.readfp(open(configFile))
series = config.sections()
series.remove('User')
mail = config.get("User", "mailaddress")
password = config.get("User", "password")
smptserver = config.get("User", "smptserver")
smptuser = config.get("User", "smptuser")
sendername = config.get("User", "sender")
sendermail = config.get("User", "sendermail")
new_episodes = []
for item in series:
url = config.get(item, "url")
latest_in_file = config.get(item, "latest")
response = urllib2.urlopen(url)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
latest = soup.find('div', 'latest-episode')
latest = BeautifulSoup(str(latest))
latest = latest.a.string
latest = latest.encode('utf8')
if latest != latest_in_file:
config.set(item, "latest", latest)
latest = item + ": " + latest
new_episodes.append(latest)
# write new latest to file
if len(new_episodes) >= 1:
with open(configFile, 'wb') as newconfigfile:
config.write(newconfigfile)
if len(new_episodes) >= 1:
# this invokes the secure SMTP protocol (port 465, uses SSL)
# from smtplib import SMTP_SSL as SMTP
from smtplib import SMTP # use this for standard SMTP
# protocol (port 25, no encryption)
from email.MIMEText import MIMEText
import sys
try:
content = '\n'.join(new_episodes)
subject = "NEW EPISODES AVAILABLE"
msg = MIMEText(content, 'plain')
msg['subject'] = subject
msg['From'] = sendername
conn = SMTP(smptserver)
conn.set_debuglevel(False)
conn.login(smptuser, password)
try:
conn.sendmail(sendermail, mail, msg.as_string())
finally:
conn.close()
except Exception, exc:
sys.exit("mail failed; %s" % str(exc)) # give a error message
@rmporsch
Copy link
Author

Checks if a new episode is available on watchseries.com

the config file will need to include the mail setting section called "User".
To include new series just add another section in the config file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment