-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_search.py
85 lines (45 loc) · 2.06 KB
/
product_search.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
from amazon.api import AmazonAPI
#WILL NOT WORK WITH OUT OS.ENVIRON CREDENTIALS FROM AWS AMAZON ETC
class Itemsearch(object):
def __init__(self, product):
self.product = product
def prod_search(self):
#insert amazon web services credentials
#associate TAG must be updated every 180 days, make new amazon associates account to get new tag
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
products_found = amazon.search_n(1,Keywords= self.product, SearchIndex= "All")
try:
return products_found[0].title
except IndexError:
return 'No such item available'
def prod_asin(self):
#insert amazon web services credentials
AMAZON_ACCESS_KEY = 'AKIAJGEKFL3UEU6QMCPQ'
AMAZON_SECRET_KEY = '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'
#associate TAG must be updated every 180 days, make new amazon associates account to get new tag
AMAZON_ASSOC_TAG = 'ignacio0ba-20'
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
products_found = amazon.search_n(1,Keywords= self.product, SearchIndex= "All")
try:
return products_found[0].asin
except IndexError:
return 'No product available'
def prod_price(self, product_asin):
#insert amazon web services credentials
AMAZON_ACCESS_KEY = 'AKIAJGEKFL3UEU6QMCPQ'
AMAZON_SECRET_KEY = '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'
#associate TAG must be updated every 180 days, make new amazon associates account to get new tag
AMAZON_ASSOC_TAG = 'ignacio0ba-20'
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)
the_product = amazon.lookup(ItemId='' + product_asin + '')
found_product_price = the_product.price_and_currency
# customer_product = Itemsearch(product)
customer_product = Itemsearch('arsenal shirt')
product_name = customer_product.prod_search()
print product_name
product_asin = customer_product.prod_asin()
print product_asin
product_price_and_currency = customer_product.prod_price(product_asin)
print product_price_and_currency
#class Item_asin_search(Itemsearch):
#adding item to cart