-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_flexbubble.py
More file actions
135 lines (127 loc) · 3.79 KB
/
create_flexbubble.py
File metadata and controls
135 lines (127 loc) · 3.79 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
import os
import json
import psycopg2
DATABASE_URL = os.popen('heroku config:get DATABASE_URL -a YOUR-PROJECT-NAME').read()[:-1]
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cursor = conn.cursor()
search_query = """SELECT * FROM YOUR-TABLE"""
cursor.execute(search_query)
user_data = cursor.fetchall()
#print(user_data)
template_bubble = {
"type": "bubble",
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "Brown Cafe", #店名['body']['contents'][0]['text']
"weight": "bold",
"size": "xl"
},
{
"type": "box",
"layout": "vertical",
"margin": "lg",
"spacing": "sm",
"contents": [ #['body']['contents'][1]['contents']
{
"type": "box",
"layout": "baseline",
"spacing": "sm",
"contents": [
{
"type": "text",
"text": "Place", #['body']['contents'][1]['contents'][0]['contents'][0]['text']
"color": "#aaaaaa",
"size": "sm",
"flex": 1
},
{
"type": "text",
"text": "Miraina Tower, 4-1-6 Shinjuku, Tokyo", #['body']['contents'][1]['contents'][0]['contents'][1]['text']
"wrap": True,
"color": "#666666",
"size": "sm",
"flex": 5
}
]
},
{
"type": "box",
"layout": "baseline",
"spacing": "sm",
"contents": [
{
"type": "text",
"text": "Time", #['body']['contents'][1]['contents'][1]['contents'][0]['text']
"color": "#aaaaaa",
"size": "sm",
"flex": 1
},
{
"type": "text",
"text": "10:00 - 23:00", #['body']['contents'][1]['contents'][1]['contents'][1]['text']
"wrap": True,
"color": "#666666",
"size": "sm",
"flex": 5
}
]
},
{
"type": "box",
"layout": "baseline",
"spacing": "sm",
"contents": [
{
"type": "text",
"text": "Type", #['body']['contents'][1]['contents'][2]['contents'][0]['text']
"color": "#aaaaaa",
"size": "sm",
"flex": 1
},
{
"type": "text",
"text": "10:00 - 23:00", #['body']['contents'][1]['contents'][2]['contents'][1]['text']
"wrap": True,
"color": "#666666",
"size": "sm",
"flex": 5
}
]
}
]
}
]
},
}
# template_type = {
# "type": "flex",
# "contents": template_bubble
#}
path = './material/'
for shop in user_data[:-1]:
name = shop[0]
eatordrink = shop[1]
holiday = shop[2]
price = shop[3]
location = shop[4]
opentime = shop[5]
menu = shop[6]
foodtype = shop[7]
template_bubble['body']['contents'][0]['text'] = name
template_bubble['body']['contents'][1]['contents'][0]['contents'][1]['text'] = location
template_bubble['body']['contents'][1]['contents'][1]['contents'][1]['text'] = opentime
template_bubble['body']['contents'][1]['contents'][2]['contents'][1]['text'] = foodtype
print('template updated!')
try:
os.mkdir(path + name)
print('建立資料夾')
except:
print('資料夾已經存在')
with open(path+name+'/reply.json', 'w') as f:
json.dump(template_bubble, f)
print('資料已上傳')
print('-' * 20)