|
3 | 3 | import sys |
4 | 4 | import imageresolver |
5 | 5 | import logging |
| 6 | +import time |
6 | 7 | from optparse import OptionParser |
7 | 8 |
|
8 | 9 | logger = logging.getLogger('ImageResolver') |
|
14 | 15 | opts.add_option("-r","--max-read", dest="max_read",help="Set the max read size") |
15 | 16 | opts.add_option("-c","--chunk-size",dest="chunk_size",help="Chunk size to read on each pass") |
16 | 17 | opts.add_option("-a","--read-all",dest="read_all",help="Read the entire image before checking size. Useful for some JPGs. Overrides --max-read") |
| 18 | +opts.add_option("--no-adblock", action="store_true",dest="use_adblock_filters",help="Do not use whitelist.txt or blacklist.txt adblock filters") |
| 19 | +opts.add_option("--no-ruleset", action="store_true",dest="use_js_ruleset",help="Do not use a custom ruleset for scoring.") |
| 20 | +opts.add_option("--benchmark", action="store_true",dest="benchmark",help="Benchmark the total time it takes for the script to return an image") |
| 21 | +opts.add_option("-l","--load-images", action="store_true",dest="load_images",help="Load images") |
| 22 | +opts.add_option("-p","--parser", dest="parser",help="Choose a parser to use") |
17 | 23 |
|
18 | 24 | (options,args) = opts.parse_args() |
19 | 25 |
|
|
26 | 32 | if options.chunk_size: |
27 | 33 | kw_options['chunk_size'] = int(options.chunk_size) |
28 | 34 |
|
| 35 | +if options.use_adblock_filters: |
| 36 | + kw_options['use_adblock_filters'] = False |
| 37 | + |
| 38 | +if options.use_js_ruleset: |
| 39 | + kw_options['use_js_ruleset'] = False |
| 40 | + |
| 41 | +if options.parser: |
| 42 | + kw_options['parser'] = options.parser |
| 43 | + |
29 | 44 | kw_options['debug'] = options.debug |
| 45 | +kw_options['load_images'] = options.load_images |
30 | 46 |
|
31 | 47 | try: |
32 | 48 | url = args[0] |
|
39 | 55 | print "URL required. Please use the url option or pass a url as the first argument" |
40 | 56 | sys.exit(-1) |
41 | 57 |
|
| 58 | + |
| 59 | +if options.benchmark: |
| 60 | + t1 = time.time() |
| 61 | + |
42 | 62 | i = imageresolver.ImageResolver(**kw_options) |
43 | 63 | i.register(imageresolver.FileExtensionResolver()) |
44 | 64 | i.register(imageresolver.PluginResolver()) |
45 | | -i.register(imageresolver.WebpageResolver(load_images=True, parser='lxml')) |
| 65 | +i.register(imageresolver.WebpageResolver(**kw_options)) |
46 | 66 |
|
47 | 67 | print i.resolve(url) |
48 | 68 |
|
| 69 | +if options.benchmark: |
| 70 | + print 'TOTAL TIME', time.time() - t1 |
| 71 | + |
0 commit comments