-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathmindicador.py
More file actions
84 lines (60 loc) · 2.23 KB
/
mindicador.py
File metadata and controls
84 lines (60 loc) · 2.23 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
''''
This is an helper class to the Chilean economic indicator http://mindicador.cl/
using the awesome requests library you can get uf, ivp, dolar, etc.
a simple example:
>> m = Mindicador()
>> m = m.get_uf()
>> uf
{'fecha': '2017-07-23T04:00:00.000Z', 'nombre': 'Unidad de fomento (UF)', 'codigo': 'uf',
'unidad_medida': 'Pesos', 'valor': 26624.85}
The above response is returned as a json ready object; you can use the object the following way:
>> for ufs in uf:
print(ufs, ':', uf.get(ufs))
fecha : 2017-07-23T04:00:00.000Z
nombre : Unidad de fomento (UF)
codigo : uf
unidad_medida : Pesos
valor : 26624.85
Note: Some if not most of the words in the responses are in Spanish(Chilean).
'''
import requests
class Mindicador():
def __init__(self):
if requests.get('http://mindicador.cl/api').status_code == requests.codes.ok:
self.api_url = requests.get('http://mindicador.cl/api')
else:
self.bad_r = requests.get('http://mindicador.cl/api')
return self.bad_r.raise_for_status()
def get_uf(self):
api_url = self.api_url.json()
return api_url.get('uf')
def get_ivp(self):
self.api_url = self.api_url.json()
return self.api_url.get('ivp')
def get_dolar(self):
self.api_url = self.api_url.json()
return self.api_url.get('dolar')
def get_dolar_intercambio(self):
self.api_url = self.api_url.json()
return self.api_url.get('dolar_intercambio')
def get_euro(self):
self.api_url = self.api_url.json()
return self.api_url.get('euro')
def get_ipc(self):
self.api_url = self.api_url.json()
return self.api_url.get('ipc')
def get_utm(self):
self.api_url = self.api_url.json()
return self.api_url.get('utm')
def get_imacec(self):
self.api_url = self.api_url.json()
return self.api_url.get('imacec')
def get_tpm(self):
self.api_url = self.api_url.json()
return self.api_url.get('tpm')
def get_libra_cobre(self):
self.api_url = self.api_url.json()
return self.api_url.get('libra_cobre')
def get_tasa_desempleo(self):
self.api_url = self.api_url.json()
return self.api_url.get('tasa_desempleo')