dosage/scripts/gocomics.py

52 lines
1.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
2024-02-14 22:39:08 +00:00
# SPDX-FileCopyrightText: © 2004 Tristan Seligmann and Jonathan Jacobs
# SPDX-FileCopyrightText: © 2012 Bastian Kleineidam
# SPDX-FileCopyrightText: © 2015 Tobias Gruetzmacher
"""
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.
"""
from scriptutil import ComicListUpdater
class GoComicsUpdater(ComicListUpdater):
dup_templates = (
"ComicsKingdom/%s",
)
# names of comics to exclude
2016-11-01 01:51:00 +00:00
excluded_comics = (
# too short
'LukeyMcGarrysTLDR',
2024-02-14 22:39:08 +00:00
# Has its own module
'Widdershins',
2016-11-01 01:51:00 +00:00
)
2020-04-19 23:03:30 +00:00
def handle_gocomics(self, url, outercss='a.gc-blended-link', lang=None):
"""Parse one GoComics alphabetic page."""
2016-04-14 22:26:14 +00:00
data = self.get_url(url, expand=False)
for comiclink in data.cssselect(outercss):
link = comiclink.attrib['href'].split('/')[1].strip()
name = comiclink.cssselect('h4')[0].text
self.add_comic(name, (link, lang))
def collect_results(self):
"""Parse all listing pages."""
2022-06-05 18:23:56 +00:00
# We add the spanish comics first since they are now also listed on the list of all
# comics... (Expect duplicate warnings for all spanish comics)
self.handle_gocomics('https://www.gocomics.com/comics/espanol', lang='es')
self.handle_gocomics('https://www.gocomics.com/comics/espanol?page=2', lang='es')
self.handle_gocomics('https://www.gocomics.com/comics/a-to-z')
2022-06-05 18:23:56 +00:00
def get_entry(self, name: str, data: tuple[str, str]):
url, lang = data
langopt = ", '%s'" % lang if lang else ''
2020-04-19 23:03:30 +00:00
return u"cls('%s', '%s'%s)," % (name, url, langopt)
if __name__ == '__main__':
GoComicsUpdater(__file__).run()