-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
60 lines (43 loc) · 1.28 KB
/
test.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
#importing my lib
import resultASIN
import threading
import numpy as np
#opening list of UPC's and reading into list
my_file = open("upc.txt", "r")
upcList = my_file.readlines()
upcList = [s.replace("\n", "") for s in upcList]
#tracking percentages
amntDone = 0
amntToDo = len(upcList)
def getASINS(upcListSplit):
global amntToDo
global amntDone
#open text file
text_file = open("asinUPC.txt", "a")
for i in upcListSplit:
url = 'https://www.amazon.com/s?k='+str(i)
#asin getting retirns list
asinList = resultASIN.getASIN(url)
if len(asinList) == 1:
#write to text file
text_file.write(str(asinList[0])+' '+str(i)+"\n")
amntDone += 1
elif len(asinList) > 1:
for x in asinList:
text_file.write(str(x)+' '+str(i)+"\n")
amntDone += 1
elif len(asinList) == 0:
pass
amntDone += 1
else:
print("Fatal Error")
amntDone += 1
#printing percentage left
print("{:.2%}".format(amntDone/amntToDo))
text_file.close()
#num of lists to split into
n = 6
#list splilts
splits = np.array_split(upcList, n)
for array in splits:
threading.Thread(target=getASINS, args=(list(array),)).start()