forked from FatGuyy/Image-data-to-csv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspare2.py
113 lines (96 loc) · 3.38 KB
/
spare2.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
113
from pandas import *
import csv
from itertools import groupby, count
def get_indices(colData, _sku, _name):
with open("sample inventory sheet(1).csv", "r") as file:
data = list(csv.reader(file))
data1 = data[0]
sku_indices = []
name_index = []
ret = []
app_list = []
col_H = colData[data1[7]].tolist() # type: ignore
col_I = colData[data1[8]].tolist()
for idx, value in enumerate(col_I): # type: ignore
if value == _sku:
sku_indices.append(idx)
for idx, value in enumerate(col_H):
if(value.lower() == _name.lower()):
name_index.append(idx)
match = list(set(sku_indices).intersection(name_index))
# sorts the start and end of data
c = count()
result = [list(g) for i, g in groupby(match, key=lambda x: x-next(c))]
for i in result:
ret.append([i[0],i[-1]])
print(ret)
for i in range(ret[-1][-1]+1):
app_list.append('')
for i in ret:
for j in i:
app_list[j] = 24
# sku_indices = []
# name_index = []
# app_list = []
# data1 = data[0]
# # col_G = colData[data1[6]].tolist().sort()
# # print(col_G)
# # test_list_for_G = range(col_G[0], col_G[-1])
# col_I = colData[data1[8]].head(max).tolist()
# col_H = colData[data1[7]].head(max).tolist()
# for idx, value in enumerate(col_I): # type: ignore
# if value == _sku:
# sku_indices.append(idx)
# for idx, value in enumerate(col_H):
# if(value.lower() == _name.lower()):
# name_index.append(idx)
# match = list(set(sku_indices).intersection(name_index))
# print(match)
# number_to_be_appended = None
# for i in range(len(col_G)):
# if test_list_for_G[i] == col_G[i]:
# continue
# else:
# number_to_be_appended = test_list_for_G[i]
return(app_list)
def col_f(colData, _sku, _name, max, inventory_csv_path):
with open(inventory_csv_path, "r") as file:
data = list(csv.reader(file))
data1 = data[0]
sku_indices = []
name_index = []
ret = []
app_list = []
col_I = colData[data1[8]].head(max).tolist()
col_H = colData[data1[7]].head(max).tolist()
for idx, value in enumerate(col_I): # type: ignore
if value == _sku:
sku_indices.append(idx)
for idx, value in enumerate(col_H):
if(value.lower() == _name.lower()):
name_index.append(idx)
match = list(set(sku_indices).intersection(name_index))
# sorts the start and end of data - of all matches.
c = count()
result = [list(g) for i, g in groupby(match, key=lambda x: x-next(c))]
for i in result:
ret.append([i[0],i[-1]])
for i in range(max):
app_list.append('')
for i in ret:
for j in i:
app_list[j] = 24
print(app_list)
return(app_list)
with open("sample inventory sheet(1).csv", "r") as file:
data = list(csv.reader(file))
data1 = data[0]
colData = read_csv("sample inventory sheet(1).csv")
sku_letters = "xxx"
Full_name = "Abby Cross"
col_h = colData[data1[7]].tolist() # type: ignore
col_i = colData[data1[8]].tolist()
# col_g = colData[data1[6]].to_list()
match_list = get_indices(colData, sku_letters, Full_name)
# col_f = col_f(Full_name, sku_letters, )
print(match_list)