Fix LWN Weekly

This commit is contained in:
Kovid Goyal 2012-01-07 07:45:35 +05:30
parent 500619dde2
commit deef06d0d5

View File

@ -7,6 +7,7 @@ lwn.net
''' '''
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import BeautifulSoup
import re import re
class WeeklyLWN(BasicNewsRecipe): class WeeklyLWN(BasicNewsRecipe):
@ -14,8 +15,11 @@ class WeeklyLWN(BasicNewsRecipe):
description = 'Weekly summary of what has happened in the free software world.' description = 'Weekly summary of what has happened in the free software world.'
__author__ = 'Davide Cavalca' __author__ = 'Davide Cavalca'
language = 'en' language = 'en'
site_url = 'http://lwn.net'
cover_url = 'http://lwn.net/images/lcorner.png' extra_css = 'pre,code,samp,kbd,tt { font-size: 80% }\nblockquote {margin-left:0 }\n* { color: black }\n'
cover_url = site_url + '/images/lcorner.png'
#masthead_url = 'http://lwn.net/images/lcorner.png' #masthead_url = 'http://lwn.net/images/lcorner.png'
publication_type = 'magazine' publication_type = 'magazine'
@ -43,32 +47,51 @@ class WeeklyLWN(BasicNewsRecipe):
br.submit() br.submit()
return br return br
def print_version(self, url):
# Strip off anchor
url = url.split('#')[0]
# Prepend site_url
if url[0:len(self.site_url)] != self.site_url:
url = self.site_url + url
# Append printable URL parameter
print_param = '?format=printable'
if url[-len(print_param):] != print_param:
url += print_param
#import sys
#print >>sys.stderr, "*** print_version(url):", url
return url
def parse_index(self): def parse_index(self):
if self.username is not None and self.password is not None: if self.username is not None and self.password is not None:
index_url = 'http://lwn.net/current/bigpage?format=printable' index_url = self.print_version('/current/bigpage')
else: else:
index_url = 'http://lwn.net/free/bigpage?format=printable' index_url = self.print_version('/free/bigpage')
soup = self.index_to_soup(index_url) soup = self.index_to_soup(index_url)
body = soup.body body = soup.body
articles = {} articles = {}
ans = [] ans = []
old_section = None
url_re = re.compile('^/Articles/') url_re = re.compile('^/Articles/')
while True: while True:
tag_title = body.findNext(name='p', attrs={'class':'SummaryHL'}) tag_title = body.findNext(attrs={'class':'SummaryHL'})
if tag_title == None: if tag_title == None:
break break
tag_section = tag_title.findPrevious(name='p', attrs={'class':'Cat1HL'}) tag_section = tag_title.findPrevious(attrs={'class':'Cat1HL'})
if tag_section == None: if tag_section == None:
section = 'Front Page' section = 'Front Page'
else: else:
section = tag_section.string section = tag_section.string
tag_section2 = tag_title.findPrevious(name='p', attrs={'class':'Cat2HL'}) tag_section2 = tag_title.findPrevious(attrs={'class':'Cat2HL'})
if tag_section2 != None: if tag_section2 != None:
if tag_section2.findPrevious(name='p', attrs={'class':'Cat1HL'}) == tag_section: if tag_section2.findPrevious(attrs={'class':'Cat1HL'}) == tag_section:
section = "%s: %s" %(section, tag_section2.string) section = "%s: %s" %(section, tag_section2.string)
if section not in articles.keys(): if section not in articles.keys():
@ -94,9 +117,10 @@ class WeeklyLWN(BasicNewsRecipe):
if tag_url == None: if tag_url == None:
break break
article = dict( article = dict(
title=self.tag_to_string(tag_title), title=self.tag_to_string(tag_title),
url= 'http://lwn.net' + tag_url['href'].split('#')[0] + '?format=printable', url=tag_url['href'],
description='', content='', date='') description='', content='', date='')
articles[section].append(article) articles[section].append(article)