Skip to content

Instantly share code, notes, and snippets.

@gazpachoking
Created February 8, 2012 21:46
Show Gist options
  • Save gazpachoking/1774150 to your computer and use it in GitHub Desktop.
Save gazpachoking/1774150 to your computer and use it in GitHub Desktop.
import logging
from BeautifulSoup import BeautifulSoup
from flexget.utils import requests
from flexget.entry import Entry
from flexget import plugin
from flexget.utils.cached_input import cached
log = logging.getLogger('pogdesign')
class InputPogDesign(object):
def validator(self):
from flexget import validator
config = validator.factory('dict')
config.accept('text', key='username', required=True)
config.accept('text', key='password', required=True)
return config
name_map = {'The Tonight Show [Leno]': 'The Tonight Show With Jay Leno',
'Late Show [Letterman]': 'David Letterman'}
@cached('pogdesign', persist='2 hours')
def on_feed_input(self, feed, config):
try:
r = requests.post('http://www.pogdesign.co.uk/cat/', data={'username': config['username'], 'password': config['password'], 'sub_login': 'Account Login'}, allow_redirects=True)
page = requests.get('http://www.pogdesign.co.uk/cat/showselect.php', cookies=r.cookies)
except requests.RequestException, e:
raise plugin.PluginError('Error retrieving source: %s' % e)
soup = BeautifulSoup(page.text, convertEntities=BeautifulSoup.HTML_ENTITIES)
entries = []
for row in soup.findAll('label', {'class': 'label_check' }):
if row.find(attrs={'checked': 'checked'}):
t = row.text
# Move 'the' to the begining
if t.endswith('[The]'):
t = 'The ' + t[:-6]
# Make certain names friendlier
if t in self.name_map:
t = self.name_map[t]
e = Entry()
e['title'] = t
#TODO: All entries need a url, we should probably use this one:
# http://www.pogdesign.co.uk/cat/show/368/The-Daily-Show
e['url'] = 'blah'
entries.append(e)
return entries
plugin.register_plugin(InputPogDesign, 'pogdesign', api_ver=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment