json_sort.py
4.74 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import json
from operator import itemgetter
'''
with open('coffee_temp.json', 'r', encoding='utf-8') as read_file:
temp_dict = json.load(read_file)
'''
'''
a = ['맥심', 'CP20', '동서', '롯데', '㉢맥심', '노브랜드', '동서식품', '코카콜라', 'FE)', '롯데칠성', '식품', 'OnlyPrice', '㉢', 'HACCP인증']
coffee = []
coffee = temp_dict['product']
for i in range(len(커피)):
for j in range(len(a)):
if coffee[i]['name'].find(a[j]) != -1:
coffee[i]['name'] = coffee[i]['name'].replace(a[j], '')
coffee_dict = {}
coffee_dict['product'] = coffee
with open('coffee_temp.json', 'w', encoding='utf-8') as make_file:
json.dump(coffee_dict, make_file, ensure_ascii=False, indent='\t')
'''
'''
coffee = []
coffee = temp_dict['product']
emart_list = []
homeplus_list = []
lottemart_list = []
new_list = []
for i in range(len(커피)):
if coffee[i]['name'] == '' or coffee[i]['price'] == '' or coffee[i]['unit'] == '' or coffee[i]['img'] == '':
continue
if coffee[i]['mart'] == 'emart':
if coffee[i]['name'] not in emart_list:
emart_list.append(coffee[i]['name'])
new_list.append(coffee[i])
elif coffee[i]['mart'] == 'homeplus':
if coffee[i]['name'] not in homeplus_list:
homeplus_list.append(coffee[i]['name'])
new_list.append(coffee[i])
elif coffee[i]['mart'] == 'lottemart':
if coffee[i]['name'] not in lottemart_list:
lottemart_list.append(coffee[i]['name'])
new_list.append(coffee[i])
new_list = sorted(new_list, key=itemgetter('name'))
coffee_dict = {}
coffee_dict['product'] = new_list
with open('coffee.json', 'w', encoding='utf-8') as make_file:
json.dump(coffee_dict, make_file, ensure_ascii=False, indent='\t')
'''
'''
coffee_sort = sorted(coffee, key=itemgetter('name'))
print(coffee_sort)
'''
'''
with open('json/snack.json', 'r', encoding='utf-8') as read_file:
temp_dict = json.load(read_file)
snack_keyword = ['(오리지널)', '농심', '롯데', '오리온', '노브랜드', '해태', '삼양', 'UP)', '(지퍼/대)', '삼양', 'CJ',
'MISURA', '삼진', '★리뉴얼런칭특가★', '(통)', '서광농협', '제주', '(안복자한과)', '@', 'V)', '2입',
'31', '동서식품', '동서', '12P', '15곡+2견과', '청우식품청우)', 'P)해태NEW', '5P', '(신)', 'H)', '4번들',
'청우식품', '15+', '동원', 'CJ', 'NEW', 'P)', '빙그레', 'GD)', 'simplus', 'V)', '한진식품', '6팩', '오뚜기', '90g*2',
'270g', '30입', '머거본 ', '한진', '12입', '3번들', '삼진', 'ACTⅡ', 'OnlyPrice', ' ', 'Hav′eat', '1P']
snack = []
snack = temp_dict['product']
for i in range(len(snack)):
for j in range(len(snack_keyword)):
if snack[i]['name'].find(snack_keyword[j]) != -1:
snack[i]['name'] = snack[i]['name'].replace(snack_keyword[j], '')
snack_dict = {}
snack_dict['product'] = snack
with open('snack_temp.json', 'w', encoding='utf-8') as make_file:
json.dump(snack_dict, make_file, ensure_ascii=False, indent='\t')
'''
with open('snack_temp.json', 'r', encoding='utf-8') as read_file:
temp_dict = json.load(read_file)
emart_list = []
homeplus_list = []
lottemart_list = []
snack = []
snack = temp_dict['product']
new_list = []
for i in range(len(snack)):
if snack[i]['name'].find('G') != -1:
temp = snack[i]['name'].find('G')
for j in range(temp-1, 0, -1):
if ord(snack[i]['name'][j]) < 48 or ord(snack[i]['name'][j]) > 57:
snack[i]['name'] = snack[i]['name'][:j+1]
break
if snack[i]['name'].find('g') != -1:
temp = snack[i]['name'].find('g')
for j in range(temp-1, 0, -1):
if ord(snack[i]['name'][j]) < 48 or ord(snack[i]['name'][j]) > 57:
snack[i]['name'] = snack[i]['name'][:j+1]
break
if snack[i]['name'] == '' or snack[i]['price'] == '' or snack[i]['unit'] == '' or snack[i]['img'] == '':
continue
if snack[i]['mart'] == 'emart':
if snack[i]['name'] not in emart_list:
emart_list.append(snack[i]['name'])
new_list.append(snack[i])
elif snack[i]['mart'] == 'homeplus':
if snack[i]['name'] not in homeplus_list:
homeplus_list.append(snack[i]['name'])
new_list.append(snack[i])
elif snack[i]['mart'] == 'lottemart':
if snack[i]['name'] not in lottemart_list:
lottemart_list.append(snack[i]['name'])
new_list.append(snack[i])
new_list = sorted(new_list, key=itemgetter('name'))
snack_dict = {}
snack_dict['product'] = new_list
with open('snack.json', 'w', encoding='utf-8') as make_file:
json.dump(snack_dict, make_file, ensure_ascii=False, indent='\t')