-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.py
41 lines (32 loc) · 1.15 KB
/
target.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
import requests
import json
import sys
def target(item):
try:
item
except NameError:
print "item not defined. Reverting to default query."
item = "item"
item = item.replace(" ", "+")
url = "http://redsky.target.com/v1/plp/search?keyword="+item+"&count=24&offset=0&sort_by=relevance"
r = requests.get(url)
j = json.loads(r.text)
master = []
for i in range(len(j['search_response']['items']['Item'])):
master.append([])
master[i].append(j['search_response']['items']['Item'][i]['title'])
if j['search_response']['items']['Item'][i]['list_price']['price'] == 0.0:
master[i].append("----")
else:
master[i].append(str(j['search_response']['items']['Item'][i]['list_price']['price']))
master[i].append("https://www.target.com" + j['search_response']['items']['Item'][i]['url'])
for x in master:
if x[1] == '0.0':
print "Found a zero'd price"
x[1] = '0.00'
return master
#print target("item")
# for i in target("item"):
# print i[0]
# print i[1]
# print i[2]