1from calibre import strftime
2from calibre.web.feeds.recipes import BasicNewsRecipe
3
4
5class NYTimes(BasicNewsRecipe):
6
7    appURL = 'https://www.framabag.org'
8    title = 'wallabag'
9    __author__ = 'Xavier Detant'
10    description = 'Get your wallabag from your framabag account. wallabag is a self hosted read it later platform'
11    needs_subscription = True
12    remove_tags_before = dict(id='article')
13    remove_tags_after = dict(id='article')
14
15    def get_browser(self):
16        br = BasicNewsRecipe.get_browser(self)
17        if self.username is not None and self.password is not None:
18            br.open(self.appURL + '/u/' + self.username)
19            br.select_form(name='loginform')
20            br['login'] = self.username
21            br['password'] = self.password
22            br.submit()
23        return br
24
25    def parse_index(self):
26        baseURL = self.appURL + '/u/' + self.username + '/'
27        soup = self.index_to_soup(baseURL + 'index.php')
28        articles = {}
29        key = None
30        ans = []
31
32        for div in soup.findAll(True, attrs={'class': ['entrie']}):
33
34            a = div.find('a', href=True)
35            if not a:
36                continue
37            key = self.tag_to_string(
38                div.find('a', attrs={'class': ['reading-time']}))
39            url = baseURL + a['href']
40            title = self.tag_to_string(a, use_alt=False)
41            description = ''
42            pubdate = strftime('%a, %d %b')
43            summary = div.find('p')
44            if summary:
45                description = self.tag_to_string(summary, use_alt=False)
46
47            feed = key if key is not None else 'Uncategorized'
48            if feed not in articles:
49                articles[feed] = []
50            articles[feed].append(
51                dict(title=title, url=url, date=pubdate, description=description, content=''))
52        ans = [(keyl, articles[keyl]) for keyl in articles.keys()]
53        return ans
54