-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct_generator.py
88 lines (74 loc) · 2.81 KB
/
product_generator.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
"""
PRODUCTS ARE NOT PREPARED CHARACTERS
TO CREATE CHARACTERS USE character_creator.py
"""
import json
from category_builder import objects_lists_creator as olc
from additional_func import product_result
def additional_filter(precooked_characters):
""" Remove forbidden products as additional layer of filtration """
pointer = 0
while True:
character = precooked_characters[pointer]
if 'lid_3_hat60x' in character and 'base_sup' in character:
precooked_characters.remove(character)
elif 'lid_6_up' in character and 'base_sup' in character:
precooked_characters.remove(character)
elif 'lid_3_hat60x' in character and 'base_stair' in character:
precooked_characters.remove(character)
else:
pointer += 1
if pointer == len(precooked_characters):
break
return precooked_characters
def additional_filter_2(precooked_characters):
""" Get only special products with "cream_6_3pics", "top_berries", "top_decoration" """
pointer = 0
bingo = 0
while True:
character = precooked_characters[pointer]
if 'cream_6_3pics' in character:
bingo += 1
if 'top_berries' in character:
bingo += 1
if 'top_decoration' in character:
bingo += 1
if bingo == 0:
precooked_characters.remove(character)
else:
bingo = 0
pointer += 1
if pointer == len(precooked_characters):
break
return precooked_characters
def body_parts_extractor(part, body_parts):
"""EXTRACT NESTED LISTS AND FILL body_parts"""
if isinstance(part, list):
for nested_object in part:
body_parts.append(nested_object)
else:
body_parts.append(part)
def generate_products():
"""GENERATE PRODUCTS W/O OPTIONALS"""
objects_list = olc() # objects_lists_creator()
precooked_products = product_result(objects_list[0],
objects_list[1],
objects_list[2],
objects_list[3],
objects_list[4])
precooked_characters = []
for character in precooked_products:
generated_products = []
for part in character:
body_parts_extractor(part, generated_products)
precooked_characters.append(generated_products)
additional_filter(precooked_characters)
# additional_filter_2(precooked_characters)
return precooked_characters
def result_to_json(result):
"""SAVE result IN precooked_products.json FILE"""
with open('json/precooked_products.json', 'w+') as file:
json_db = json.dumps(result)
file.write(json_db)
if __name__ == "__main__":
result_to_json(generate_products())