| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
__license__ = 'GPL v3' |
| 4 |
__copyright__ = '2010, Derek Liang <Derek.liang.ca @@@at@@@ gmail.com>' |
| 5 |
''' |
| 6 |
wenxuecity.com |
| 7 |
''' |
| 8 |
import re |
| 9 |
|
| 10 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 11 |
|
| 12 |
|
| 13 |
class TheCND(BasicNewsRecipe): |
| 14 |
title = 'wenxuecity - znjy' |
| 15 |
__author__ = 'Derek Liang' |
| 16 |
description = '' |
| 17 |
INDEX = 'http://bbs.wenxuecity.com/znjy/?elite=1' |
| 18 |
language = 'zh' |
| 19 |
conversion_options = {'linearize_tables': True} |
| 20 |
|
| 21 |
remove_tags_before = dict(name='div', id='message') |
| 22 |
remove_tags_after = dict(name='div', id='message') |
| 23 |
remove_tags = [dict(name='div', id='postmeta'), dict(name='div', id='footer')] |
| 24 |
no_stylesheets = True |
| 25 |
|
| 26 |
preprocess_regexps = [(re.compile(r'<!--.*?-->', re.DOTALL), lambda m: '')] |
| 27 |
|
| 28 |
def print_version(self, url): |
| 29 |
return url + '?print' |
| 30 |
|
| 31 |
def parse_index(self): |
| 32 |
soup = self.index_to_soup(self.INDEX) |
| 33 |
|
| 34 |
feeds = [] |
| 35 |
articles = {} |
| 36 |
|
| 37 |
for a in soup.findAll('a', attrs={'class': 'post'}): |
| 38 |
url = a['href'] |
| 39 |
if url.startswith('/'): |
| 40 |
url = 'http://bbs.wenxuecity.com' + url |
| 41 |
title = self.tag_to_string(a) |
| 42 |
self.log('\tFound article: ', title, ' at:', url) |
| 43 |
dateReg = re.search(r'(\d\d?)/(\d\d?)/(\d\d)', self.tag_to_string(a.parent)) |
| 44 |
date = '%(y)s/%(m)02d/%(d)02d' % {'y': dateReg.group(3), 'm': int(dateReg.group(1)), 'd': int(dateReg.group(2))} |
| 45 |
if date not in articles: |
| 46 |
articles[date] = [] |
| 47 |
articles[date].append({'title': title, 'url': url, 'description': '', 'date': ''}) |
| 48 |
self.log('\t\tAppend to : ', date) |
| 49 |
|
| 50 |
self.log('log articles', articles) |
| 51 |
mostCurrent = sorted(articles).pop() |
| 52 |
self.title = '文学城 - 子女教育 - ' + mostCurrent |
| 53 |
|
| 54 |
feeds.append((self.title, articles[mostCurrent])) |
| 55 |
|
| 56 |
return feeds |
| 57 |
|
| 58 |
def populate_article_metadata(self, article, soup, first): |
| 59 |
header = soup.find('h3') |
| 60 |
self.log('header: ' + self.tag_to_string(header)) |