1# -*- coding: utf-8 -*-
2'''
3Copyright 2012-2019 eBay Inc.
4Authored by: Tim Keefer
5Licensed under CDDL 1.0
6'''
7
8import os
9import sys
10from optparse import OptionParser
11
12sys.path.insert(0, '%s/../' % os.path.dirname(__file__))
13
14from common import dump
15from ebaysdk.finding import Connection as finding
16from ebaysdk.http import Connection as html
17from ebaysdk.parallel import Parallel
18from ebaysdk.exception import ConnectionError
19
20
21def init_options():
22    usage = "usage: %prog [options]"
23    parser = OptionParser(usage=usage)
24
25    parser.add_option("-d", "--debug",
26                      action="store_true", dest="debug", default=False,
27                      help="Enabled debugging [default: %default]")
28    parser.add_option("-y", "--yaml",
29                      dest="yaml", default='ebay.yaml',
30                      help="Specifies the name of the YAML defaults file. [default: %default]")
31    parser.add_option("-a", "--appid",
32                      dest="appid", default=None,
33                      help="Specifies the eBay application id to use.")
34    parser.add_option("-n", "--domain",
35                      dest="domain", default='svcs.ebay.com',
36                      help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).")
37    (opts, args) = parser.parse_args()
38    return opts, args
39
40
41def run(opts):
42
43    try:
44        p = Parallel()
45        apis = []
46
47        api1 = finding(parallel=p, debug=opts.debug, domain=opts.domain,
48                       appid=opts.appid, config_file=opts.yaml)
49        api1.execute('findItemsAdvanced', {'keywords': 'python'})
50        apis.append(api1)
51
52        api4 = html(parallel=p)
53        api4.execute('http://www.ebay.com/sch/i.html?_nkw=Shirt&_rss=1')
54        apis.append(api4)
55
56        api2 = finding(parallel=p, debug=opts.debug, domain=opts.domain,
57                       appid=opts.appid, config_file=opts.yaml)
58        api2.execute('findItemsAdvanced', {'keywords': 'perl'})
59        apis.append(api2)
60
61        api3 = finding(parallel=p, debug=opts.debug, domain=opts.domain,
62                       appid=opts.appid, config_file=opts.yaml)
63        api3.execute('findItemsAdvanced', {'keywords': 'php'})
64        apis.append(api3)
65
66        p.wait()
67
68        if p.error():
69            print(p.error())
70
71        for api in apis:
72            dump(api)
73
74    except ConnectionError as e:
75        print(e)
76        print(e.response.dict())
77
78if __name__ == "__main__":
79    (opts, args) = init_options()
80    run(opts)
81