-
Notifications
You must be signed in to change notification settings - Fork 328
/
Copy pathfinding.py
133 lines (99 loc) · 3.75 KB
/
finding.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
'''
Copyright 2012-2019 eBay Inc.
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
import ebaysdk
from ebaysdk.finding import Connection as finding
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.")
parser.add_option("-n", "--domain",
dest="domain", default='svcs.ebay.com',
help="Specifies the eBay domain to use (e.g. svcs.sandbox.ebay.com).")
(opts, args) = parser.parse_args()
return opts, args
def run(opts):
try:
api = finding(debug=opts.debug, appid=opts.appid, domain=opts.domain,
config_file=opts.yaml, warnings=True)
api_request = {
#'keywords': u'niño',
'keywords': u'GRAMMY Foundation®',
'itemFilter': [
{'name': 'Condition',
'value': 'Used'},
{'name': 'LocatedIn',
'value': 'GB'},
],
'affiliate': {'trackingId': 1},
'sortOrder': 'CountryDescending',
}
response = api.execute('findItemsAdvanced', api_request)
dump(api)
except ConnectionError as e:
print(e)
print(e.response.dict())
def run_unicode(opts):
try:
api = finding(debug=opts.debug, appid=opts.appid, domain=opts.domain,
config_file=opts.yaml, warnings=True)
api_request = {
'keywords': u'Kościół',
}
response = api.execute('findItemsAdvanced', api_request)
for i in response.reply.searchResult.item:
if i.title.find(u'ś') >= 0:
print("Matched: %s" % i.title)
break
dump(api)
except ConnectionError as e:
print(e)
print(e.response.dict())
def run2(opts):
try:
api = finding(debug=opts.debug, appid=opts.appid, domain=opts.domain,
config_file=opts.yaml)
response = api.execute('findItemsByProduct',
'<productId type="ReferenceID">53039031</productId><paginationInput><entriesPerPage>1</entriesPerPage></paginationInput>')
dump(api)
except ConnectionError as e:
print(e)
print(e.response.dict())
def run_motors(opts):
api = finding(siteid='EBAY-MOTOR', debug=opts.debug, appid=opts.appid, config_file=opts.yaml,
domain=opts.domain, warnings=True)
api.execute('findItemsAdvanced', {
'keywords': 'tesla',
})
if api.error():
raise Exception(api.error())
if api.response_content():
print("Call Success: %s in length" % len(api.response_content()))
print("Response code: %s" % api.response_code())
print("Response DOM: %s" % api.response_dom())
dictstr = "%s" % api.response_dict()
print("Response dictionary: %s..." % dictstr[:250])
if __name__ == "__main__":
print("Finding samples for SDK version %s" % ebaysdk.get_version())
(opts, args) = init_options()
run(opts)
run2(opts)
run_motors(opts)
run_unicode(opts)