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