Debian Codegraph @

recipes/observatorul_cultural.recipe

raw
1 from __future__ import print_function
2
3 import re
4
5 from calibre.web.feeds.news import BasicNewsRecipe
6
7 coverpage = None
8
9
10 class ObservatorulCultural(BasicNewsRecipe):
11 title = 'Observatorul cultural'
12 __author__ = 'song2' # prelucrat dupa un script de http://www.thenowhereman.com
13 encoding = 'utf-8'
14 language = 'ro'
15 publication_type = 'magazine'
16 description = 'Spiritul critic in acÅĢiune\n'
17 no_stylesheets = True
18 remove_javascript = True
19 masthead_url = 'http://www.observatorcultural.ro/userfiles/article/sigla%20Observator%20cultural_02231058.JPG'
20 keep_only_tags = [dict(name='div', attrs={'class': 'detaliuArticol'})]
21 remove_tags = [
22 dict(name='div', attrs={'class': 'comentariiArticol'}),
23 dict(name='div', attrs={'class': 'postComment'}),
24 dict(name='div', attrs={'class': 'utileArticol'}),
25 dict(name='p', attrs={'class': 'butonComenteaza'}),
26 dict(name='h5'),
27 dict(name='div', attrs={'style': 'margin-top: 0px; padding-top: 0px;'}),
28 ]
29
30 def parse_index(self):
31 soup = self.index_to_soup('http://www.observatorcultural.ro/Arhiva*-archive.html')
32 issueTag = soup.find('a', href=re.compile(r'observatorcultural.ro/Numarul'))
33 issueURL = issueTag['href']
34 print(issueURL)
35 issueSoup = self.index_to_soup(issueURL)
36 feeds = []
37 stories = []
38 for categorie in issueSoup.findAll('dl', attrs={'class': 'continutArhive'}):
39 categ = self.tag_to_string(categorie.find('dt'))
40 for story in categorie.findAll('dd'):
41 title = []
42 for bucatele in story.findAll('a'):
43 title.append(bucatele)
44 if len(title) == 1: # daca articolul nu are autor
45 stories.append({'title': self.tag_to_string(title[0]), 'url': title[0]['href'], 'date': '', 'author': ''})
46 else: # daca articolul are autor len(title)=2
47 stories.append({'title': self.tag_to_string(title[1]), 'url': title[1]['href'], 'date': '', 'author': self.tag_to_string(title[0])})
48 print(self.tag_to_string(title[0]))
49 if 'Editorial' in categ:
50 global coverpage
51 # am luat link-ul spre editorial
52 coverpage = title[1]['href']
53 feeds.append((categ, stories))
54 stories = []
55 print(feeds)
56 return feeds
57
58 # procedura de luat coperta
59
60 def get_cover_url(self):
61 soup = self.index_to_soup(coverpage)
62 # caut imaginea textului
63 link_item = soup.find('a', attrs={'rel': 'lightbox'})
64 a = ''
65 cover_url = a.join(link_item.img['src'].split('_details_'))
66 return cover_url