-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
71 lines (57 loc) · 2.79 KB
/
app.py
File metadata and controls
71 lines (57 loc) · 2.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
from bottle import run, response, route
import os
import json
from extended_libs import airtable
from extended_libs import s3_integration as S3
#from extended_libs import dash_plot
from extended_libs import dash_central
from extended_libs import zim_weather
def generate_slack_message(graph_url):
slack_attachment = []
vote_data, current_ratio = airtable.save_to_airtable()
text = "*Yes Votes:* {} \n *No Votes:* {} \n *Abstain Votes:* {} \n *Current Ratio* {}/10%".format(vote_data[0],
vote_data[1],
vote_data[2],
current_ratio)
slack_attachment.append({
"pretext": "*Voting Update*",
"color": "{}".format('#fcc118'),
"text": text,
"footer": "Vote Updater",
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
"mrkdwn_in": ["pretext"],
"title": "{}".format("Vote Graph"),
"image_url": "{}".format(graph_url)
})
package = {"response_type": "in_channel", "text": "Latest Charts", "attachments": json.dumps(slack_attachment)}
return package
@route('/votegraph', method="post")
def gen_graph():
plot_url = dash_plot.gen_plot_n_upload()
package = generate_slack_message(plot_url)
response.content_type = 'application/json'
return package
@route('/votecheck', method="post")
def gen_proposal_data():
proposal_data = dash_central.poll_dash_central()
airtable.save_to_airtable(proposal_data)
weather_data = zim_weather.weather_check()
temp_f = zim_weather.kelvin_to_fahrenheit(weather_data['main']['temp'])
weather_info = weather_data['weather'][0]['main']
package = {"response_type": "in_channel", "text":
"*Yes Votes:* {} \n".format(proposal_data['yes']) +
"*No Votes:* {} \n".format(proposal_data['no']) +
"*Abstain Votes:* {} \n".format(proposal_data['abstain']) +
"*Current Ratio:* {}/10% \n".format(proposal_data['current_ratio']) +
"*Votes Until Funding:* {} \n".format(proposal_data['remaining_yes_votes_until_funding']) +
"*Number of Comments:* {} \n".format(proposal_data['comment_amount']) +
"*Voting Deadline:* {} \n".format(proposal_data['voting_deadline_human']) +
"*Link:* {}".format(proposal_data['url']) +
"\n \n" +
"*Zim Weather:* - {}, {} Degrees F".format(weather_info, temp_f)
}
response.content_type = 'application/json'
return package
if __name__ == '__main__':
port_config = int(os.getenv('PORT', 5000))
run(host='0.0.0.0', port=port_config)