Debian Codegraph @

recipes/crikey.recipe

raw
1 #!/usr/bin/env python
2 __license__ = 'GPL v3'
3 __copyright__ = '2021, Alistair Francis [email protected]'
4 __docformat__ = 'restructuredtext en'
5
6 from urllib.parse import urlencode
7
8 from calibre.web.feeds.news import BasicNewsRecipe
9
10
11 def classes(classes):
12 q = frozenset(classes.split(' '))
13 return dict(attrs={'class': lambda x: x and frozenset(x.split()).intersection(q)})
14
15
16 class Crikey(BasicNewsRecipe):
17 title = 'Crikey'
18 description = 'Australian News'
19 __author__ = 'Alistair Francis'
20 language = 'en_AU'
21
22 use_embedded_content = True
23 needs_subscription = True
24
25 keep_only_tags = [
26 classes('article-body'),
27 ]
28
29 feeds = [
30 ('Politics', 'https://www.crikey.com.au/politics/feed'),
31 ('World', 'https://www.crikey.com.au/world/feed'),
32 ('Media', 'https://www.crikey.com.au/media/feed'),
33 ('Buisness', 'https://www.crikey.com.au/business/feed'),
34 ('Coronavirus', 'https://www.crikey.com.au/coronavirus/feed'),
35 ('Culture', 'https://www.crikey.com.au/life/feed'),
36 ]
37
38 def get_browser(self):
39 br = BasicNewsRecipe.get_browser(self)
40 br.open('https://www.crikey.com.au/')
41
42 if self.username is not None and self.password is not None:
43 postdata = urlencode({'username': self.username, 'password': self.password})
44 br.open('https://www.crikey.com.au', data=postdata, timeout=self.timeout)
45
46 br.set_handle_refresh(True)
47
48 return br