forked from flechajm/BluePy
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
134 lines (100 loc) · 3.9 KB
/
index.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
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
import os
import tiempo_financiero
import monitor_dolar_venezuela
from flask import Flask, send_from_directory, jsonify
from flask_caching import Cache
VERSION = "1.2"
CACHE_TIMEOUT_SECONDS = os.getenv('CACHE_TIMEOUT', 3600)
GIT_REPO_URL = 'https://github.com/guidospadavecchia/BluePy'
app = Flask(__name__)
app.config['JSON_SORT_KEYS'] = False
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
@ app.route("/favicon.ico")
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico')
@ app.route("/")
def getRoot():
html = f"""<head>
<title>BluePy API v{VERSION}</title>
<head>
<body>
BluePy API <b>v{VERSION}</b> - <b><a href={GIT_REPO_URL} style="text-decoration: none;">GitHub</a></b>
</body>"""
return html
@ app.route("/api/ping")
def ping():
return 'pong'
@ app.route("/api/dolar/oficial")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getDolarOficial():
dolarValues = tiempo_financiero.getDolarOficial()
dolarOficial = tiempo_financiero.formatResponse(dolarValues)
return jsonify(dolarOficial)
@ app.route("/api/dolar/blue")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getDolarBlue():
dolarValues = tiempo_financiero.getDolarBlue()
dolarBlue = tiempo_financiero.formatResponse(dolarValues)
return jsonify(dolarBlue)
@ app.route("/api/dolar/turista")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getDolarTurista():
dolarValues = tiempo_financiero.getDolarTurista()
dolarTurista = tiempo_financiero.formatResponse(dolarValues)
return jsonify(dolarTurista)
@ app.route("/api/dolar/mep")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getDolarMep():
dolarValues = tiempo_financiero.getDolarMep()
dolarMep = tiempo_financiero.formatResponse(dolarValues)
return jsonify(dolarMep)
@ app.route("/api/dolar/ccl")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getDolarCcl():
dolarValues = tiempo_financiero.getDolarCcl()
dolarCcl = tiempo_financiero.formatResponse(dolarValues)
return jsonify(dolarCcl)
@ app.route("/api/euro/oficial")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getEuroOficial():
euroValues = tiempo_financiero.getEuroOficial()
euroOficial = tiempo_financiero.formatResponse(euroValues)
return jsonify(euroOficial)
@ app.route("/api/euro/blue")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getEuroBlue():
euroValues = tiempo_financiero.getEuroBlue()
euroBlue = tiempo_financiero.formatResponse(euroValues)
return jsonify(euroBlue)
@ app.route("/api/euro/tarjeta")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getEuroTarjeta():
euroValues = tiempo_financiero.getEuroTarjeta()
euroTarjeta = tiempo_financiero.formatResponse(euroValues)
return jsonify(euroTarjeta)
@ app.route("/api/real/oficial")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getRealOficial():
realValues = tiempo_financiero.getRealOficial()
realOficial = tiempo_financiero.formatResponse(realValues)
return jsonify(realOficial)
@ app.route("/api/real/blue")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getRealBlue():
realValues = tiempo_financiero.getRealBlue()
realBlue = tiempo_financiero.formatResponse(realValues)
return jsonify(realBlue)
@ app.route("/api/venezuela/dolar/oficial")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getVenezuelaOficialRate():
valueOficial = monitor_dolar_venezuela.getOficial()
response = monitor_dolar_venezuela.formatResponse(valueOficial)
return jsonify(response)
@ app.route("/api/venezuela/dolar/paralelo")
@ cache.cached(timeout=CACHE_TIMEOUT_SECONDS)
def getVenezuelaParaleloRate():
valueParalelo = monitor_dolar_venezuela.getParalelo()
response = monitor_dolar_venezuela.formatResponse(valueParalelo)
return jsonify(response)
if __name__ == '__main__':
app.run(debug=False, port=os.getenv('PORT', 5000))