~dosage-dev/dosage/bunch-of-comics

« back to all changes in this revision

Viewing changes to dosage/scraper.py

  • Committer: ns
  • Date: 2009-12-01 07:07:18 UTC
  • Revision ID: ns@ww1aviationlinks.cjb.net-20091201070718-3xoj70sz52zsq09v
Y plugin added YAFGC

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
from twisted.plugin import getPlugins
 
4
 
 
5
import dosage.plugins
 
6
from dosage.idosage import IScraper
 
7
 
 
8
 
 
9
DISABLED_FILES = ['/etc/dosage/disabled',
 
10
                  '~/.dosage/disabled']
 
11
 
 
12
disabled = []
 
13
for filename in DISABLED_FILES:
 
14
    filename = os.path.expanduser(filename)
 
15
    if os.path.exists(filename):
 
16
        disabled.extend([line.rstrip('\n') for line in open(filename)])
 
17
 
 
18
 
 
19
class DisabledComicError(ValueError):
 
20
    pass
 
21
 
 
22
 
 
23
def get(comicName):
 
24
    """Returns a comic module object."""
 
25
 
 
26
    scrapers = getPlugins(IScraper, dosage.plugins)
 
27
    for scraper in scrapers:
 
28
        if scraper.name == comicName:
 
29
            return scraper
 
30
 
 
31
    raise ValueError('Comic %r not found.' % (comicName,))
 
32
 
 
33
 
 
34
def items():
 
35
    scrapers = getPlugins(IScraper, dosage.plugins)
 
36
    return sorted(scrapers, key=lambda s: s.name)