-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_page.py
63 lines (57 loc) · 1.69 KB
/
edit_page.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
import markdown_to_json as mdj
import requests
def md_to_json():
with open("home.md", "r") as f:
content = f.read()
data = mdj.dictify(content)
title =data['Main']['Hero']['Title'][0]
description = data['Main']['Hero']['Description'][0]
button = data['Main']['Hero']['Button'][0]
hero = {
'title': title,
'description': description,
'button': button,
'id': 1
}
about = {
'title': 'About Us',
'description': data['About']['About']['About'][0],
'highlight_text': data['About']['About']['Highlight'][0],
'year': data['About']['About']['Year'][0],
'mission_text': data['About']['About']['Mission'][0],
'vision_text': data['About']['About']['Vision'][0],
'values_text': 'N/A',
'id': 1
}
data = {
'hero': hero,
'about': about
}
return data
def send_request(data):
url = "http://localhost:8000/api/v1/edit-page/"
payload = {
'data' : data
}
response = requests.put(url, json=payload)
if response.status_code == 200:
print("Updated successfully.")
else:
print("An error occurred.")
# def test():
# with open("services.md", "r") as f:
# content = f.read()
# data = mdj.dictify(content)
# services = {[]}
# for key in data:
# # print(key)
# services.append(data[key])
# print(data[key])
# print("\n")
# # print(data)
def main():
data = md_to_json()
send_request(data)
# test()
if __name__ == "__main__":
main()