-
Notifications
You must be signed in to change notification settings - Fork 0
/
syrup.py
67 lines (58 loc) · 2.19 KB
/
syrup.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
from ebaysdk.finding import Connection as Finding
from ebaysdk.exception import ConnectionError
def findOne(d, fh):
try:
api = Finding(appid="EdisonLi-syrup-PRD-c8e35c535-b071148d", config_file=None)
response = api.execute('findItemsAdvanced', {
'keywords' : d['keywords'],
'itemFilter' : d['itemFilter'],
'paginationInput' : {
'entriesPerPage' : '25',
'pageNumber' : '1'
},
'sortOrder' : 'PricePlusShippingLowest'
})
fh.write('<h3> Keywords: ' + d['keywords'] + '</h3>\n')
fh.write('<table border="1">\n')
for item in response.reply.searchResult.item:
fh.write("<tr><th>%s</th><th>%s %s</th><th>%s</th><th><a href=%s>click</a></th>\n" % (
item.itemId,
item.sellingStatus.currentPrice.value,
item.sellingStatus.currentPrice._currencyId,
item.title,
item.viewItemURL))
fh.write('</table>\n')
except ConnectionError as e:
print(e)
print(e.response.dict())
if __name__ == '__main__':
# gather input search targets from input.txt
targets = []
with open('input.txt', 'r') as ip:
for line in ip:
line = line.strip()
# ignore empty lines
if not line:
continue
# ignore lines that starts with '#'
if line[0] == '#':
continue
# use fancy python thingy to strip each item
parts = [a.strip() for a in line.split(',')]
if len(parts) < 3:
continue
# construct my local search target
d = {
'keywords': parts[0],
'itemFilter': [
{'name': 'Condition', 'value': 'Used'},
{'name': 'MinPrice', 'value': parts[1]},
{'name': 'MaxPrice', 'value': parts[2]},
]
}
# append to target list
targets.append(d)
# execute search and print to html
with open('syrup.html', 'w') as fh:
for d in targets:
findOne(d, fh)