Merge from trunk

This commit is contained in:
Sengian 2011-01-31 21:06:05 +01:00
commit 44d8667ce8
4 changed files with 100 additions and 62 deletions

View File

@ -1,73 +1,92 @@
#!/usr/bin/env python
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008-2009, Darko Miletic <darko.miletic at gmail.com>' __copyright__ = '2008-2011, Darko Miletic <darko.miletic at gmail.com>'
''' '''
latimes.com www.latimes.com
''' '''
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
class LATimes(BasicNewsRecipe): class LATimes(BasicNewsRecipe):
title = u'The Los Angeles Times' title = 'Los Angeles Times'
__author__ = u'Darko Miletic and Sujata Raman' __author__ = 'Darko Miletic'
description = u'News from Los Angeles' description = 'The Los Angeles Times is a leading source of news on Southern California, entertainment, movies, television, music, politics, business, health, technology, travel, sports, environment, economics, autos, jobs, real estate and other topics affecting California'
oldest_article = 7 publisher = 'Tribune Company'
max_articles_per_feed = 100 category = 'news, politics, USA, Los Angeles, world'
language = 'en' oldest_article = 2
max_articles_per_feed = 200
no_stylesheets = True no_stylesheets = True
encoding = 'utf8'
use_embedded_content = False use_embedded_content = False
encoding = 'utf-8' language = 'en'
lang = 'en-US' remove_empty_feeds = True
publication_type = 'newspaper'
masthead_url = 'http://www.latimes.com/images/logo.png'
cover_url = 'http://www.latimes.com/includes/sectionfronts/A1.pdf'
extra_css = """
body{font-family: Georgia,"Times New Roman",Times,serif }
img{margin-bottom: 0.4em; margin-top: 0.8em; display:block}
h2{font-size: 1.1em}
.deckhead{font-size: small; text-transform: uppercase}
.small{color: gray; font-size: small}
.date,.time,.copyright{font-size: x-small; color:gray; font-style:italic;}
"""
conversion_options = { conversion_options = {
'comment' : description 'comment' : description
, 'language' : lang , 'tags' : category
} , 'publisher' : publisher
, 'language' : language
, 'linearize_tables' : 'Yes'
}
extra_css = ''' keep_only_tags = [
h1{font-family :Georgia,"Times New Roman",Times,serif; font-size:large; } dict(name='div', attrs={'class':'story'})
h2{font-family :Georgia,"Times New Roman",Times,serif; font-size:x-small;} ,dict(attrs={'class':['entry-header','time','entry-content']})
.story{font-family :Georgia,"Times New Roman",Times,serif; font-size: x-small;} ]
.entry-body{font-family :Georgia,"Times New Roman",Times,serif; font-size: x-small;} remove_tags_after=dict(name='p', attrs={'class':'copyright'})
.entry-more{font-family :Georgia,"Times New Roman",Times,serif; font-size: x-small;} remove_tags = [
.credit{color:#666666; font-family :Georgia,"Times New Roman",Times,serif; font-size: xx-small;} dict(name=['meta','link','iframe','object','embed'])
.small{color:#666666; font-family :Georgia,"Times New Roman",Times,serif; font-size: xx-small;} ,dict(attrs={'class':['toolSet','articlerail','googleAd','entry-footer-left','entry-footer-right','entry-footer-social','google-ad-story-bottom','sphereTools']})
.byline{font-family :Georgia,"Times New Roman",Times,serif; font-size: xx-small;} ,dict(attrs={'id':['article-promo','googleads','moduleArticleToolsContainer','gallery-subcontent']})
.date{font-family :Georgia,"Times New Roman",Times,serif; font-size: xx-small;color:#930000; font-style:italic;} ]
.time{font-family :Georgia,"Times New Roman",Times,serif; font-size: xx-small;color:#930000; font-style:italic;} remove_attributes=['lang','xmlns:fb','xmlns:og','border','xtags','i','article_body']
.copyright{font-family :Georgia,"Times New Roman",Times,serif; font-size: xx-small;color:#930000; }
.subhead{font-family :Georgia,"Times New Roman",Times,serif; font-size:x-small;}
'''
# recursions = 1
# match_regexps = [r'http://www.latimes.com/.*page=[2-9]']
keep_only_tags = [dict(name='div', attrs={'class':["story" ,"entry"] })]
remove_tags = [ dict(name='div', attrs={'class':['articlerail',"sphereTools","tools","toppaginate","entry-footer-left","entry-footer-right"]}), feeds = [
dict(name='div', attrs={'id':["moduleArticleToolsContainer",]}), (u'Top News' , u'http://feeds.latimes.com/latimes/news' )
dict(name='p', attrs={'class':["entry-footer",]}), ,(u'Local News' , u'http://feeds.latimes.com/latimes/news/local' )
dict(name='ul', attrs={'class':"article-nav clearfix"}), ,(u'National' , u'http://feeds.latimes.com/latimes/news/nationworld/nation' )
dict(name=['iframe']) ,(u'National Politics' , u'http://feeds.latimes.com/latimes/news/politics/' )
] ,(u'Business' , u'http://feeds.latimes.com/latimes/business' )
,(u'Education' , u'http://feeds.latimes.com/latimes/news/education' )
,(u'Environment' , u'http://feeds.latimes.com/latimes/news/science/environment' )
feeds = [(u'News', u'http://feeds.latimes.com/latimes/news') ,(u'Religion' , u'http://feeds.latimes.com/latimes/features/religion' )
,(u'Local','http://feeds.latimes.com/latimes/news/local') ,(u'Science' , u'http://feeds.latimes.com/latimes/news/science' )
,(u'MostEmailed','http://feeds.latimes.com/MostEmailed') ,(u'Technology' , u'http://feeds.latimes.com/latimes/technology' )
,(u'Politics','http://feeds.latimes.com/latimes/news/local/politics/cal/') ,(u'Africa' , u'http://feeds.latimes.com/latimes/africa' )
,('OrangeCounty','http://feeds.latimes.com/latimes/news/local/orange/') ,(u'Asia' , u'http://feeds.latimes.com/latimes/asia' )
,('National','http://feeds.latimes.com/latimes/news/nationworld/nation') ,(u'Europe' , u'http://feeds.latimes.com/latimes/europe' )
,('Politics','http://feeds.latimes.com/latimes/news/politics/') ,(u'Latin America' , u'http://feeds.latimes.com/latimes/latinamerica' )
,('Business','http://feeds.latimes.com/latimes/business') ,(u'Middle East' , u'http://feeds.latimes.com/latimes/middleeast' )
,('Sports','http://feeds.latimes.com/latimes/sports/') ,(u'Arts&Culture' , u'http://feeds.feedburner.com/latimes/entertainment/news/arts' )
,('Entertainment','http://feeds.latimes.com/latimes/entertainment/') ,(u'Entertainment News' , u'http://feeds.feedburner.com/latimes/entertainment/news/' )
] ,(u'Movie News' , u'http://feeds.feedburner.com/latimes/entertainment/news/movies/' )
,(u'Movie Reviews' , u'http://feeds.feedburner.com/movies/reviews/' )
,(u'Music News' , u'http://feeds.feedburner.com/latimes/entertainment/news/music/' )
,(u'Pop Album Reviews' , u'http://feeds.feedburner.com/latimes/pop-album-reviews' )
,(u'Restaurant Reviews' , u'http://feeds.feedburner.com/latimes/restaurant/reviews' )
,(u'Theatar and Dance' , u'http://feeds.feedburner.com/latimes/theaterdance' )
,(u'Autos' , u'http://feeds.latimes.com/latimes/classified/automotive/highway1/')
,(u'Books' , u'http://feeds.latimes.com/features/books' )
,(u'Food' , u'http://feeds.latimes.com/latimes/features/food/' )
,(u'Health' , u'http://feeds.latimes.com/latimes/features/health/' )
,(u'Real Estate' , u'http://feeds.latimes.com/latimes/classified/realestate/' )
,(u'Commentary' , u'http://feeds2.feedburner.com/latimes/news/opinion/commentary/' )
,(u'Sports' , u'http://feeds.latimes.com/latimes/sports/' )
]
def get_article_url(self, article): def get_article_url(self, article):
ans = article.get('feedburner_origlink').rpartition('?')[0] ans = BasicNewsRecipe.get_article_url(self, article).rpartition('?')[0]
try: try:
self.log('Looking for full story link in', ans) self.log('Looking for full story link in', ans)
@ -83,4 +102,22 @@ class LATimes(BasicNewsRecipe):
pass pass
return ans return ans
def preprocess_html(self, soup):
for item in soup.findAll(style=True):
del item['style']
for item in soup.findAll('img'):
if not item.has_key('alt'):
item['alt'] = 'image'
for item in soup.findAll('a'):
limg = item.find('img')
if item.string is not None:
str = item.string
item.replaceWith(str)
else:
if limg:
item.name ='div'
item.attrs =[]
else:
str = self.tag_to_string(item)
item.replaceWith(str)
return soup

View File

@ -323,4 +323,4 @@ class RTFInput(InputFormatPlugin):
#ebook-convert "bad.rtf" test.epub -v -d "D:\Mes eBooks\Developpement\debug" #ebook-convert "bad.rtf" test.epub -v -d "D:\Mes eBooks\Developpement\debug"
# os.makedirs('D:\\Mes eBooks\\Developpement\\rtfdebug') # os.makedirs('D:\\Mes eBooks\\Developpement\\rtfdebug')
# debug_dir = 'D:\\Mes eBooks\\Developpement\\rtfdebug' # debug_dir = 'D:\\Mes eBooks\\Developpement\\rtfdebug'

View File

@ -191,7 +191,7 @@ class Tokenize:
#read #read
with open(self.__file, 'r') as read_obj: with open(self.__file, 'r') as read_obj:
input_file = read_obj.read() input_file = read_obj.read()
#process simple replacements and split giving us a correct list #process simple replacements and split giving us a correct list
#remove '' and \n in the process #remove '' and \n in the process
tokens = self.__sub_reg_split(input_file) tokens = self.__sub_reg_split(input_file)
@ -201,7 +201,7 @@ class Tokenize:
tokens = filter(lambda x: len(x) > 0, tokens) tokens = filter(lambda x: len(x) > 0, tokens)
#handles bothersome cases #handles bothersome cases
tokens = map(self.__correct_spliting, tokens) tokens = map(self.__correct_spliting, tokens)
#write #write
with open(self.__write_to, 'wb') as write_obj: with open(self.__write_to, 'wb') as write_obj:
write_obj.write('\n'.join(tokens)) write_obj.write('\n'.join(tokens))
@ -211,7 +211,7 @@ class Tokenize:
copy_obj.copy_file(self.__write_to, "tokenize.data") copy_obj.copy_file(self.__write_to, "tokenize.data")
copy_obj.rename(self.__write_to, self.__file) copy_obj.rename(self.__write_to, self.__file)
os.remove(self.__write_to) os.remove(self.__write_to)
#self.__special_tokens = [ '_', '~', "'", '{', '}' ] #self.__special_tokens = [ '_', '~', "'", '{', '}' ]
# import sys # import sys
@ -227,4 +227,4 @@ class Tokenize:
# if __name__ == '__main__': # if __name__ == '__main__':
# sys.exit(main()) # sys.exit(main())

View File

@ -379,7 +379,7 @@ class BIBTEX(CatalogPlugin): # {{{
if calibre_files: if calibre_files:
files = [u':%s:%s' % (format, format.rpartition('.')[2].upper())\ files = [u':%s:%s' % (format, format.rpartition('.')[2].upper())\
for format in item] for format in item]
bibtex_entry.append(u'files = "%s"' % u', '.join(files)) bibtex_entry.append(u'file = "%s"' % u', '.join(files))
elif field == 'series_index' : elif field == 'series_index' :
bibtex_entry.append(u'volume = "%s"' % int(item)) bibtex_entry.append(u'volume = "%s"' % int(item))
@ -551,6 +551,7 @@ class BIBTEX(CatalogPlugin): # {{{
as outfile: as outfile:
#File header #File header
nb_entries = len(data) nb_entries = len(data)
#check in book strict if all is ok else throw a warning into log #check in book strict if all is ok else throw a warning into log
if bib_entry == 'book' : if bib_entry == 'book' :
nb_books = len(filter(check_entry_book_valid, data)) nb_books = len(filter(check_entry_book_valid, data))