File: creators.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 (44 lines) | stat: -rwxr-xr-x 1,351 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
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: © 2012 Bastian Kleineidam
# SPDX-FileCopyrightText: © 2015 Tobias Gruetzmacher
"""
Script to get a list of creators.com comics and save the info in a JSON file
for further processing.
"""

import scriptutil


class CreatorsUpdater(scriptutil.ComicListUpdater):
    dup_templates = ('GoComics/%s',)

    # names of comics to exclude
    excluded_comics = (
        # no images
        'Doodles',
    )

    def handle_url(self, url):
        """Parse one listing page."""
        data = self.get_url(url)

        for comicdiv in self.xpath(data, '//ul[d:class("all-test")]/li'):
            comiclink = self.xpath(comicdiv, './a')[0]
            comicurl = comiclink.attrib['href']
            name = self.xpath(comicdiv, './/p/strong')[0].text

            self.add_comic(name, comicurl.rsplit('/', 1)[1])

    def collect_results(self):
        """Parse all search result pages."""
        self.handle_url('https://www.creators.com/categories/comics/all')
        self.handle_url('https://www.creators.com/categories/cartoons/all')

    def get_entry(self, name, path):
        langopt = ", 'es'" if name.lower().endswith('spanish') else ''
        return u"cls('%s', '%s'%s)," % (name, path, langopt)


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