~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/lrf/web/profiles/barrons.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##
2
 
##    web2lrf profile to download articles from Barrons.com 
3
 
##    can download subscriber-only content if username and  
4
 
##    password are supplied.
5
 
##
6
 
''' 
7
 
''' 
8
 
 
9
 
import re 
10
 
 
11
 
from calibre.ebooks.lrf.web.profiles import DefaultProfile  
12
 
         
13
 
class Barrons(DefaultProfile): 
14
 
    
15
 
        title = 'Barron\'s' 
16
 
        max_recursions = 3
17
 
        max_articles_per_feed = 50
18
 
        needs_subscription    = True
19
 
        timefmt  = ' [%a, %b %d, %Y]' 
20
 
        html_description = True 
21
 
        no_stylesheets = False
22
 
        match_regexps = ['http://online.barrons.com/.*?html\?mod=.*?|file:.*']
23
 
        html2lrf_options = [('--ignore-tables'),('--base-font-size=10')]
24
 
        ##delay = 1
25
 
        
26
 
        ## Don't grab articles more than 7 days old 
27
 
        oldest_article = 7 
28
 
 
29
 
 
30
 
        preprocess_regexps = [(re.compile(i[0], re.IGNORECASE | re.DOTALL), i[1]) for i in  
31
 
                [ 
32
 
                ## Remove anything before the body of the article. 
33
 
                (r'<body.*?<!-- article start', lambda match: '<body><!-- article start'), 
34
 
 
35
 
                ## Remove any insets from the body of the article. 
36
 
                (r'<div id="inset".*?</div>.?</div>.?<p', lambda match : '<p'), 
37
 
 
38
 
                ## Remove any reprint info from the body of the article. 
39
 
                (r'<hr size.*?<p', lambda match : '<p'), 
40
 
 
41
 
                ## Remove anything after the end of the article. 
42
 
                (r'<!-- article end.*?</body>', lambda match : '</body>'), 
43
 
                ] 
44
 
        ] 
45
 
 
46
 
        def get_browser(self): 
47
 
            br = DefaultProfile.get_browser() 
48
 
            if self.username is not None and self.password is not None: 
49
 
                br.open('http://commerce.barrons.com/auth/login') 
50
 
                br.select_form(name='login_form') 
51
 
                br['user']   = self.username 
52
 
                br['password'] = self.password 
53
 
                br.submit() 
54
 
            return br 
55
 
 
56
 
## Use the print version of a page when available. 
57
 
 
58
 
        def print_version(self, url): 
59
 
                return url.replace('/article/', '/article_print/') 
60
 
 
61
 
## Comment out the feeds you don't want retrieved. 
62
 
## Because these feeds are sorted alphabetically when converted to LRF, you may want to number them to put them in the order you desire 
63
 
 
64
 
        def get_feeds(self): 
65
 
                return  [ 
66
 
                ('This Week\'s Magazine', 'http://online.barrons.com/xml/rss/3_7510.xml'), 
67
 
                ('Online Exclusives', 'http://online.barrons.com/xml/rss/3_7515.xml'), 
68
 
                ('Companies', 'http://online.barrons.com/xml/rss/3_7516.xml'), 
69
 
                ('Markets', 'http://online.barrons.com/xml/rss/3_7517.xml'), 
70
 
                ('Technology', 'http://online.barrons.com/xml/rss/3_7518.xml'), 
71
 
                ('Funds/Q&A', 'http://online.barrons.com/xml/rss/3_7519.xml'), 
72
 
                ]
73
 
 
74
 
        ## Logout of website
75
 
        ## NOT CURRENTLY WORKING
76
 
        # def cleanup(self):
77
 
            # try:
78
 
                # self.browser.set_debug_responses(True)
79
 
                # import sys, logging
80
 
                # logger = logging.getLogger("mechanize")
81
 
                # logger.addHandler(logging.StreamHandler(sys.stdout))
82
 
                # logger.setLevel(logging.INFO)
83
 
 
84
 
                # res = self.browser.open('http://online.barrons.com/logout')
85
 
            # except:
86
 
                # import traceback
87
 
                # traceback.print_exc()
88
 
 
89
 
 
90