-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
117 lines (87 loc) · 3.5 KB
/
main.py
File metadata and controls
117 lines (87 loc) · 3.5 KB
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
114
115
116
117
import qnot
import csv
def generate_csv(data):
headers = ["name", "colors", "style", "shipping_information", "brand_information",
"order_information", "wholesale", "sugg_retail", "total", "size", "quantity"]
with open("output.csv", "w", newline="") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=headers)
writer.writeheader()
for product in data:
colors = product["colors"]
size = product["size"]
total = product["total"]
if len(colors) > 1:
for i in range(len(colors)):
for key, value in size.items():
row = {
"name": product["name"],
"colors": colors[i],
"style": product["style"],
"shipping_information": product["shipping_information"],
"brand_information": product["brand_information"],
"order_information": product["order_information"],
"wholesale": product["wholesale"],
"sugg_retail": product["sugg_retail"],
"total": total[i],
"size": key,
"quantity": value[i]
}
writer.writerow(row)
else:
for key, value in size.items():
row = {
"name": product["name"],
"colors": colors[0],
"style": product["style"],
"shipping_information": product["shipping_information"],
"brand_information": product["brand_information"],
"order_information": product["order_information"],
"wholesale": product["wholesale"],
"sugg_retail": product["sugg_retail"],
"total": total,
"size": key,
"quantity": value
}
writer.writerow(row)
print("CSV generated sucessfully....")
def get_structure(data, indent=0):
structure = ""
if isinstance(data, list):
structure += "{\n"
for item in data:
structure += " " * (indent + 2)
structure += get_structure(item, indent + 2)
structure += " " * indent + "}\n"
elif isinstance(data, dict):
structure += "{\n"
for key, value in data.items():
structure += " " * (indent + 2)
structure += key + ": "
structure += get_structure(value, indent + 2)
structure += " " * indent + "}\n"
else:
structure += str(data) + "\n"
return structure
def collect_size_keys(array):
size_keys = set()
for sub_array in array:
for dictionary in sub_array:
data_dict = list(dictionary["size"].keys())
for i in data_dict:
size_keys.add(i)
return list(size_keys)
pdf_path = "/home/guatam/Desktop/fiverr/pdf_data_extract/inp_pdf/ORDER_Lauren-Manoogian_2023-10-06_13769226.pdf"
qnot.remove_last_page(pdf_path)
p = qnot.annotate_blocks_with_rectangles("modified.pdf")
temp = []
for i in p:
for j in i:
# print()
# print(j)
# print("="*50)
# print()
temp.append(j)
generate_csv(temp)
x = get_structure(p)
with open("data.json", "w") as f:
f.write(x)