root/projects/Twisted-Goodies/trunk/pat2pdf

Revision 2, 2.5 kB (checked in by edsuom, 1 year ago)

Import of trunk from old repo

  • Property svn:executable set to *
Line 
1 #!/usr/bin/python
2 # -*- mode:python; -*-
3 #
4 # Twisted Goodies:
5 # Miscellaneous add-ons and improvements to the separately maintained and
6 # licensed Twisted (TM) asynchronous framework. Permission to use the name was
7 # graciously granted by Twisted Matrix Laboratories, http://twistedmatrix.com.
8 #
9 # Copyright (C) 2006 by Edwin A. Suominen, http://www.eepatents.com
10 #
11 # This program is free software; you can redistribute it and/or modify it under
12 # the terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # This program is distributed in the hope that it will be useful, but WITHOUT
17 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 # FOR A PARTICULAR PURPOSE.  See the file COPYING for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # this program; if not, write to the Free Software Foundation, Inc., 51
22 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23
24
25 import os, os.path
26 from optparse import OptionParser
27 from twisted.internet import reactor, defer
28 from twisted_goodies.webfetch import patents
29
30
31 class Fetcher(object):
32     def __init__(self, dir):
33         self.patents = patents.PatentFetcher(dir)
34         self.apps = patents.AppFetcher(dir)
35
36     def fetchAll(self, pubNumbers):
37         dList = []
38         for pubNumber in pubNumbers:
39             for fetcher in (self.apps, self.patents):
40                 validated = fetcher.parsePubNumber(pubNumber)
41                 if validated:
42                     break
43             else:
44                 continue
45             print "Fetching US%d ->" % validated
46             if fetcher.filePath(validated) is None:
47                 d = fetcher.fetch(validated)
48                 d.addCallback(self._fetched)
49                 dList.append(d)
50         self.d = defer.DeferredList(dList)
51         self.d.addCallback(self._done)
52    
53     def _fetched(self, filePath):
54         print " -> %s" % os.path.basename(filePath)
55
56     def _done(self, null):
57         print "%s\nAll Done" % ('-'*70,)
58         reactor.stop()
59
60
61 # Parse the command line arguments
62 p = OptionParser()
63 p.add_option(
64     "-f", "--front",
65     dest="front", action="store_true",
66     help="Front page(s) only")
67 p.add_option(
68     "-d", "--dir",
69     dest="dir", action="store",
70     help="Destination directory")
71 p.set_defaults(
72     front=False,
73     dir=os.getcwd())
74 opts, args = p.parse_args()
75
76 # Run the desired operation
77 fetcher = Fetcher(opts.dir)
78 reactor.callWhenRunning(fetcher.fetchAll, args)
79 reactor.run()
Note: See TracBrowser for help on using the browser.