dosage/scripts/gocomics.py

61 lines
1.8 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
2016-04-12 22:52:16 +00:00
# Copyright (C) 2004-2005 Tristan Seligmann and Jonathan Jacobs
# Copyright (C) 2012-2014 Bastian Kleineidam
# Copyright (C) 2015-2016 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 __future__ import absolute_import, division, print_function
from scriptutil import ComicListUpdater
class GoComicsUpdater(ComicListUpdater):
# names of comics to exclude
excluded_comics = [
# "coming soon"
2016-04-17 16:40:09 +00:00
"AngryProgrammer",
"Guinness",
"Jabberwoncky",
2016-04-17 16:40:09 +00:00
"Pi",
"RandysRationale",
"SignsOfOurTimes",
"TheGagwriter",
"Yaoyao",
# duplicate
2016-04-17 16:40:09 +00:00
"Dilbert",
"SaturdayMorningBreakfastCereal",
2016-04-17 16:40:09 +00:00
# not available
2016-05-16 16:26:45 +00:00
"BillyAndCo",
2016-04-17 16:40:09 +00:00
"BuffaloChips",
"Crawdiddy",
]
def handle_url(self, url):
"""Parse one search result page."""
2016-04-14 22:26:14 +00:00
data = self.get_url(url, expand=False)
for comiclink in data.cssselect('a.alpha_list'):
link = comiclink.attrib['href']
name = comiclink.text
self.add_comic(name, link)
def collect_results(self):
"""Parse all listing pages."""
self.handle_url('http://www.gocomics.com/features')
self.handle_url('http://www.gocomics.com/explore/espanol')
self.handle_url('http://www.gocomics.com/explore/editorial_list')
self.handle_url('http://www.gocomics.com/explore/sherpa_list')
2016-05-22 20:55:06 +00:00
def get_entry(self, name, url):
langopt = ", 'es'" if 'espanol/' in url else ''
return u"cls('%s', '%s'%s)," % (name, url[1:], langopt)
if __name__ == '__main__':
GoComicsUpdater(__file__).run()