2012-11-28 17:15:12 +00:00
|
|
|
#!/usr/bin/env python
|
2016-04-11 22:36:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-10-28 22:21:41 +00:00
|
|
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
2016-04-12 22:52:16 +00:00
|
|
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
2017-01-11 01:21:05 +00:00
|
|
|
# Copyright (C) 2015-2017 Tobias Gruetzmacher
|
2012-11-28 17:15:12 +00:00
|
|
|
"""
|
2016-04-12 22:52:16 +00:00
|
|
|
Script to get a list of gocomics and save the info in a JSON file for further
|
|
|
|
processing.
|
2012-11-28 17:15:12 +00:00
|
|
|
"""
|
2016-04-11 22:36:33 +00:00
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
2016-04-14 20:22:37 +00:00
|
|
|
from scriptutil import ComicListUpdater
|
|
|
|
|
|
|
|
|
|
|
|
class GoComicsUpdater(ComicListUpdater):
|
|
|
|
# names of comics to exclude
|
2016-11-01 01:51:00 +00:00
|
|
|
excluded_comics = (
|
2017-01-11 01:21:05 +00:00
|
|
|
# too short
|
|
|
|
'LukeyMcGarrysTLDR',
|
2016-11-01 01:51:00 +00:00
|
|
|
)
|
2016-04-14 20:22:37 +00:00
|
|
|
|
2017-01-11 01:21:05 +00:00
|
|
|
def handle_gocomics(self, url, outercss='a.amu-media-item-link', lang=None):
|
|
|
|
"""Parse one GoComics alphabetic page."""
|
2016-04-14 22:26:14 +00:00
|
|
|
data = self.get_url(url, expand=False)
|
2016-04-14 20:22:37 +00:00
|
|
|
|
2017-01-11 01:21:05 +00:00
|
|
|
for comiclink in data.cssselect(outercss):
|
2016-04-14 20:22:37 +00:00
|
|
|
link = comiclink.attrib['href']
|
2017-01-11 01:21:05 +00:00
|
|
|
name = comiclink.cssselect('h4')[0].text
|
|
|
|
self.add_comic(name, (link, lang))
|
2016-04-14 20:22:37 +00:00
|
|
|
|
|
|
|
def collect_results(self):
|
|
|
|
"""Parse all listing pages."""
|
2017-01-11 01:21:05 +00:00
|
|
|
for part in ('a-b', 'c-e', 'f-i', 'j-n', 'o-r', 's-t', 'u-%23'):
|
|
|
|
self.handle_gocomics('http://www.gocomics.com/comics/a-to-z?page=' + part)
|
|
|
|
self.handle_gocomics('http://www.gocomics.com/comics/espanol', 'a.gc-card-item', 'es')
|
2016-04-14 20:22:37 +00:00
|
|
|
|
2017-01-11 01:21:05 +00:00
|
|
|
def get_entry(self, name, data):
|
|
|
|
url, lang = data
|
|
|
|
langopt = ", '%s'" % lang if lang else ''
|
2016-05-22 22:01:10 +00:00
|
|
|
return u"cls('%s', '%s'%s)," % (name, url[1:], langopt)
|
2012-11-28 17:15:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-04-14 20:22:37 +00:00
|
|
|
GoComicsUpdater(__file__).run()
|