-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateProposal
executable file
·79 lines (70 loc) · 1.98 KB
/
generateProposal
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
#!/usr/bin/python3
import sys
import json
def data():
dta = open("result.txt")
d = dta.readline()
return d
def json_file(d):
file = "fleury_michon/fleury_michon.json"
all = []
with open(file) as read_file:
data = json.load(read_file)
for p in data['fleury']:
produit = []
if p['type'] == d:
# print('Name: ' + p['name'])
img = "/"+p['type']+"/"+p['image']
# print('Image: ' + img)
# print('Type: ' + p['type'])
produit.append(p['name'])
produit.append(img)
produit.append(p['web'])
produit.append(p['type'])
all.append(produit)
read_file.close()
return all
def create_new_json(data):
file = "result.json"
try:
a_file = open(file, "r+")
except:
print("No file")
json_object = json.load(a_file)
i = 0
for p in json_object['fleury']:
print(data[i][0])
p['name'] = data[i][0]
p['image'] = data[i][1]
p['web'] = data[i][2]
p['type'] = data[i][3]
a_file.write(json.dumps(p))
i+=1
a_file.close()
def updateJsonFile(data):
jsonFile = open("result.json", "r") # Open the JSON file for reading
dataJson = json.load(jsonFile) # Read the JSON into the buffer
jsonFile.close() # Close the JSON file
## Working with buffered content
i = 0
for p in dataJson['fleury']:
# tmp = p["location"]
print(data[i][0])
p['name'] = data[i][0]
p['image'] = data[i][1]
p['web'] = data[i][2]
p['type'] = data[i][3]
i += 1
## Save our changes to JSON file
jsonFile = open("result.json", "w+")
jsonFile.write(json.dumps(dataJson))
jsonFile.close()
def main():
d = data()
d = d.replace('\n', '')
all = json_file(d)
# create_new_json(all)
updateJsonFile(all)
exit(0)
if __name__ == "__main__":
main()