File: tapas.py

package info (click to toggle)
dosage 3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,400 kB
  • sloc: python: 12,703; sh: 55; makefile: 6
file content (35 lines) | stat: -rwxr-xr-x 1,235 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: © 2019 Tobias Gruetzmacher
# SPDX-FileCopyrightText: © 2019 Daniel Ring
"""
Script to get a list of Tapastic comics and save the info in a
JSON file for further processing.
"""
from urllib import parse

from scriptutil import ComicListUpdater


class TapasUpdater(ComicListUpdater):
    def collect_results(self):
        # Retrieve the first 10 top comics list pages
        url = 'https://tapas.io/comics?browse=ALL&sort_type=LIKE&pageNumber='
        count = 10

        data = [self.get_url(url + str(i), robot=False) for i in range(0, count)]
        for page in data:
            for comiclink in page.xpath('//a[@class="preferred title"]'):
                comicurl = comiclink.attrib['href']
                name = comiclink.text
                self.add_comic(name, comicurl)

    def get_entry(self, name, url):
        shortName = name.replace(' ', '').replace('\'', '')
        titleNum = int(parse.parse_qs(parse.urlsplit(url).query)['title_no'][0])
        url = url.rsplit('/', 1)[0].replace('/series/', '')
        return u"cls('%s', '%s', %d)," % (shortName, url, titleNum)


if __name__ == '__main__':
    TapasUpdater(__file__).run()