This repository was archived by the owner on Jun 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (59 loc) · 1.84 KB
/
app.py
File metadata and controls
66 lines (59 loc) · 1.84 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
import os
from bottle import post, run, request
import requests
OPENFISCA_URL = "https://openfisca-aotearoa.herokuapp.com/calculate"
def get_rebate_amount(dependents, rates, income):
OF_QUERY = {
'persons': {
'person_one': {
'rates_rebates__combined_income': {
'2020': income
},
'rates_rebates__dependants': {
'2020': dependents
}
}
},
'titled_properties': {
'home': {
'rates_rebates__rates_total': {
'2020': rates
},
'rates_rebates__rebate': {
'2020': None
},
'owners': ['person_one']
}
},
}
of_response = requests.post(OPENFISCA_URL, json=OF_QUERY).json()
rebate = of_response['titled_properties']['home']['rates_rebates__rebate']['2020']
return rebate
@post('/calculate/rebate')
def rebate():
json_request = request.json
parameters = json_request['queryResult']['parameters']
dependents = parameters['dependents']
income = parameters['income']
rates = parameters['rates']
rebate = get_rebate_amount(dependents, rates, income)
reply = "You are eligible for {rebate} dollars".format(rebate=rebate)
return {
"fulfillmentText": reply,
"payload": {
"google": {
"expectUserResponse": False,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": reply
}
}
]
}
}
}
}
port = os.environ.get('PORT', 5000)
run(host='0.0.0.0', port=port)