-
Notifications
You must be signed in to change notification settings - Fork 3
/
Amazon_Product_Search.py
112 lines (107 loc) · 4.86 KB
/
Amazon_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
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
from amazon.api import AmazonAPI
import csv
import json
amazon = AmazonAPI('AKIAIEOGZE3ZYS64PKVQ',
'bOvagh6eyGG8sVvI8ZipAdrs4qOk5d93BVfKr39A',
'abcd12340eb-21',
MaxQPS=0.9,
Region='US')
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\Scraped_Data.json', 'r') as f:
datastore = json.load(f)
for data in datastore['friends']['data']:
try:
print(data['name'])
Name = data['name']
counter = 0
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\{0}\\favorite_books_desc.csv'.format(Name), 'r') as f:
reader= csv.reader(f, delimiter='|')
for row in reader:
try:
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\{0}\\probable_gifts.csv'.format(Name), 'a', newline='') as csvfile:
writer= csv.writer(csvfile, delimiter='|')
products = amazon.search(Keywords=row[1], SearchIndex='Books')
for i, product in enumerate(products):
print(product)
writer.writerow([product])
counter += 1
break
if counter == 3:
break
except Exception as e:
print(e)
continue
except Exception as e:
print(e)
continue
for data in datastore['friends']['data']:
try:
print(data['name'])
Name = data['name']
counter = 0
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\{0}\\favorite_similar_movies.csv'.format(Name), 'r') as f:
reader= csv.reader(f, delimiter='|')
for row in reader:
try:
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\{0}\\probable_gifts.csv'.format(Name), 'a', newline='') as csvfile:
writer= csv.writer(csvfile, delimiter='|')
products = amazon.search(Keywords=row[0], SearchIndex='Movies')
for i, product in enumerate(products):
print(product)
writer.writerow([product])
counter += 1
break
if counter == 3:
break
except Exception as e:
print(e)
continue
except Exception as e:
print(e)
continue
for data in datastore['friends']['data']:
try:
print(data['name'])
Name = data['name']
counter = 0
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\{0}\\favorite_music_albums.csv'.format(Name), 'r') as f:
reader= csv.reader(f, delimiter='|')
for row in reader:
try:
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\{0}\\probable_gifts.csv'.format(Name), 'a', newline='') as csvfile:
writer= csv.writer(csvfile, delimiter='|')
products = amazon.search(Keywords=row[1], SearchIndex='Music')
for i, product in enumerate(products):
print(row[1], product)
writer.writerow([product])
counter += 1
break
if counter == 3:
break
except Exception as e:
print(e)
continue
except Exception as e:
print(e)
continue
for data in datastore['friends']['data']:
try:
print(data['name'])
Name = data['name']
counter = 0
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\{0}\\likes_desc.csv'.format(Name), 'r') as f:
reader= csv.reader(f, delimiter='|')
for row in reader:
try:
with open('C:\\Users\\AshwinAmbal\\Desktop\\SDL Lab\\{0}\\probable_gifts.csv'.format(Name), 'a', newline='') as csvfile:
writer= csv.writer(csvfile, delimiter='|')
products = amazon.search(Keywords=row[0], SearchIndex='All')
for i, product in enumerate(products):
print(row[1], product)
writer.writerow([product])
break
except Exception as e:
print(e)
continue
except Exception as e:
print(e)
continue