-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmask.py
103 lines (93 loc) Β· 3.96 KB
/
mask.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import requests
from datetime import datetime
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/mask", methods=['POST'])
def mask():
payload = {'lat': '37.6445243', 'lng':'127.034310', 'm': '500'}
res = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/storesByGeo/json?', params=payload)
status_dict = {'break': "π€", 'empty': "π€", 'few': "β€", 'some': "π", 'plenty': "π"}
mask_vendors = []
cards = []
if res.status_code == 200:
data = res.json()
origin_created_at = data['stores'][0]['created_at']
origin_created_at_object = datetime.strptime(origin_created_at, '%Y/%m/%d %H:%M:%S')
created_at = origin_created_at_object.strftime('%m/%d %H:%M')
time_info = "π " + created_at + "\n"
for i in range(len(data['stores'])):
try:
name = data['stores'][i]['name']
remain_status = status_dict.get(data['stores'][i]['remain_stat'])
origin_stock_at = data['stores'][i]['stock_at']
origin_stock_at_object = datetime.strptime(origin_stock_at, '%Y/%m/%d %H:%M:%S')
stock_at = origin_stock_at_object.strftime('%m/%d %H:%M')
address = data['stores'][i]['addr'].replace("μμΈνΉλ³μ", '')
mask_message = str(i+1) + ". " + name + remain_status + "\nβ° : " + stock_at + "\nπ : " + address + "\n"
mask_vendors.append(mask_message)
except TypeError:
remain_status = "(μ 보μμ)"
stock_at = "μ 보μμ"
mask_message = str(i+1) + ". " + name + remain_status + "\nβ° : " + stock_at + "\nπ : " + address + "\n"
mask_vendors.append(mask_message)
for j in range(0, len(mask_vendors), 2):
try:
cards.append(mask_vendors[j] + mask_vendors[j+1])
except IndexError:
cards.append(mask_vendors[j])
mask_response = {
"version": "2.0",
"template": {
"outputs": [
{
"carousel": {
"type": "basicCard",
"items": [
{
"description": time_info + cards[0]
},
{
"description": cards[1]
},
{
"description": cards[2]
},
{
"description": cards[3]
},
{
"description": cards[4]
},
{
"description": cards[5]
},
{
"description": cards[6]
},
{
"description": cards[7]
},
{
"description": cards[8]
}
]
}
}
],
"quickReplies": [
{
"action": "message",
"label": "λμλ§",
"messageText": "λμλ§"
},
{
"action": "message",
"label": "κ°μμ΄ λ¨Ήκ³ μΆμ΄μπͺ",
"messageText": "κ°μ?"
}
]
}
}
return jsonify(mask_response)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=3100)