Make subscription optional for ESPN

This commit is contained in:
Kovid Goyal 2012-01-18 10:54:18 +05:30
parent f5ba57a0fe
commit d38d282489

View File

@ -20,7 +20,7 @@ class ESPN(BasicNewsRecipe):
use_embedded_content = False use_embedded_content = False
remove_javascript = True remove_javascript = True
needs_subscription = True needs_subscription = 'optional'
encoding= 'ISO-8859-1' encoding= 'ISO-8859-1'
remove_tags_before = dict(name='font', attrs={'class':'date'}) remove_tags_before = dict(name='font', attrs={'class':'date'})
@ -75,32 +75,30 @@ class ESPN(BasicNewsRecipe):
return soup return soup
def get_browser(self): def get_browser(self):
br = BasicNewsRecipe.get_browser() br = BasicNewsRecipe.get_browser()
br.set_handle_refresh(False) if self.username and self.password:
url = ('https://r.espn.go.com/members/v3_1/login') br.set_handle_refresh(False)
raw = br.open(url).read() url = ('https://r.espn.go.com/members/v3_1/login')
raw = re.sub(r'(?s)<form>.*?id="regsigninbtn".*?</form>', '', raw) raw = br.open(url).read()
with TemporaryFile(suffix='.htm') as fname: raw = re.sub(r'(?s)<form>.*?id="regsigninbtn".*?</form>', '', raw)
with open(fname, 'wb') as f: with TemporaryFile(suffix='.htm') as fname:
f.write(raw) with open(fname, 'wb') as f:
br.open_local_file(fname) f.write(raw)
br.open_local_file(fname)
br.form = br.forms().next() br.form = br.forms().next()
br.form.find_control(name='username', type='text').value = self.username br.form.find_control(name='username', type='text').value = self.username
br.form['password'] = self.password br.form['password'] = self.password
br.submit().read() br.submit().read()
br.open('http://espn.go.com').read() br.open('http://espn.go.com').read()
br.set_handle_refresh(True) br.set_handle_refresh(True)
return br return br
def get_article_url(self, article): def get_article_url(self, article):
return article.get('guid', None) return article.get('guid', None)
def print_version(self, url): def print_version(self, url):
if 'eticket' in url: if 'eticket' in url:
return url.partition('&')[0].replace('story?', 'print?') return url.partition('&')[0].replace('story?', 'print?')
match = re.search(r'story\?(id=\d+)', url) match = re.search(r'story\?(id=\d+)', url)