forked from timotheus/ebaysdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopping.py
More file actions
161 lines (115 loc) · 4.13 KB
/
Copy pathshopping.py
File metadata and controls
161 lines (115 loc) · 4.13 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# -*- 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
try:
input = raw_input
except NameError:
pass
sys.path.insert(0, '%s/../' % os.path.dirname(__file__))
from common import dump
import ebaysdk
from ebaysdk.exception import ConnectionError
from ebaysdk.shopping import Connection as Shopping
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):
api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml,
warnings=True)
print("Shopping samples for SDK version %s" % ebaysdk.get_version())
try:
response = api.execute('FindPopularItems', {'QueryKeywords': 'Python'})
dump(api)
print("Matching Titles:")
for item in response.reply.ItemArray.Item:
print(item.Title)
except ConnectionError as e:
print(e)
print(e.response.dict())
def popularSearches(opts):
api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml,
warnings=True)
choice = True
while choice:
choice = input('Search: ')
if choice == 'quit':
break
mySearch = {
"MaxKeywords": 10,
"QueryKeywords": choice,
}
try:
response = api.execute('FindPopularSearches', mySearch)
dump(api, full=False)
print("Related: %s" % response.reply.PopularSearchResult.RelatedSearches)
for term in response.reply.PopularSearchResult.AlternativeSearches.split(';')[:3]:
api.execute('FindPopularItems', {'QueryKeywords': term, 'MaxEntries': 3})
print("Term: %s" % term)
try:
for item in response.reply.ItemArray.Item:
print(item.Title)
except AttributeError:
pass
dump(api)
print("\n")
except ConnectionError as e:
print(e)
print(e.response.dict())
def categoryInfo(opts):
try:
api = Shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml,
warnings=True)
response = api.execute('GetCategoryInfo', {"CategoryID": 3410})
dump(api, full=False)
except ConnectionError as e:
print(e)
print(e.response.dict())
def with_affiliate_info(opts):
try:
api = Shopping(debug=opts.debug, appid=opts.appid,
config_file=opts.yaml, warnings=True,
trackingid=1234, trackingpartnercode=9)
mySearch = {
"MaxKeywords": 10,
"QueryKeywords": 'shirt',
}
response = api.execute('FindPopularSearches', mySearch)
dump(api, full=False)
except ConnectionError as e:
print(e)
print(e.response.dict())
def using_attributes(opts):
try:
api = Shopping(debug=opts.debug, appid=opts.appid,
config_file=opts.yaml, warnings=True)
response = api.execute('FindProducts', {
"ProductID": {'@attrs': {'type': 'ISBN'},
'#text': '0596154488'}})
dump(api, full=False)
except ConnectionError as e:
print(e)
print(e.response.dict())
if __name__ == "__main__":
(opts, args) = init_options()
run(opts)
popularSearches(opts)
categoryInfo(opts)
with_affiliate_info(opts)
using_attributes(opts)