| 1 |
from calibre.ebooks.BeautifulSoup import BeautifulSoup |
| 2 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 3 |
|
| 4 |
|
| 5 |
class Gram_pl(BasicNewsRecipe): |
| 6 |
title = 'Gram.pl' |
| 7 |
__author__ = 'fenuks' |
| 8 |
description = 'Serwis społecznościowy o grach: recenzje, newsy, zapowiedzi, encyklopedia gier, forum. Gry PC, PS3, X360, PS Vita, sprzęt dla graczy.' |
| 9 |
category = 'games' |
| 10 |
language = 'pl' |
| 11 |
oldest_article = 8 |
| 12 |
index = 'http://www.gram.pl' |
| 13 |
max_articles_per_feed = 100 |
| 14 |
ignore_duplicate_articles = {'title', 'url'} |
| 15 |
no_stylesheets = True |
| 16 |
remove_empty_feeds = True |
| 17 |
cover_url = 'http://www.gram.pl/www/01/img/grampl_zima.png' |
| 18 |
keep_only_tags = [dict(id='articleModule')] |
| 19 |
remove_tags = [dict(attrs={'class': ['breadCrump', 'dymek', 'articleFooter', 'twitter-share-button']}), dict(name='aside'), dict(id='metaColumn')] |
| 20 |
feeds = [('Informacje', 'http://www.gram.pl/feed_news.asp'), ('Publikacje', 'http://www.gram.pl/feed_news.asp?type=articles')] |
| 21 |
|
| 22 |
def parse_feeds(self): |
| 23 |
feeds = BasicNewsRecipe.parse_feeds(self) |
| 24 |
for feed in feeds: |
| 25 |
for article in feed.articles[:]: |
| 26 |
if 'REKLAMA SKLEP' in article.title.upper() or 'ARTYKUŁ:' in article.title.upper(): |
| 27 |
feed.articles.remove(article) |
| 28 |
return feeds |
| 29 |
|
| 30 |
def preprocess_html(self, soup): |
| 31 |
tag = soup.find(name='div', attrs={'class': 'summary'}) |
| 32 |
if tag: |
| 33 |
tag.find(attrs={'class': 'pros'}).insert(0, BeautifulSoup('<h2>Plusy:</h2>').h2) |
| 34 |
tag.find(attrs={'class': 'cons'}).insert(0, BeautifulSoup('<h2>Minusy:</h2>').h2) |
| 35 |
tag = soup.find(name='section', attrs={'class': 'cenzurka'}) |
| 36 |
if tag: |
| 37 |
rate = tag.p.img['data-ocena'] |
| 38 |
tag.p.img.extract() |
| 39 |
tag.p.insert(len(tag.p.contents) - 2, BeautifulSoup('<h2>Ocena: {0}</h2>'.format(rate)).h2) |
| 40 |
for a in soup.findAll('a', href=True): |
| 41 |
if 'http://' not in a['href'] and 'https://' not in a['href']: |
| 42 |
a['href'] = self.index + a['href'] |
| 43 |
tag = soup.find(name='span', attrs={'class': 'platforma'}) |
| 44 |
if tag: |
| 45 |
tag.name = 'p' |
| 46 |
return soup |