Skip to content

Commit 2976406

Browse files
committed
Add alternative data source.
1 parent 3f2fb16 commit 2976406

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Currency Exchange.alfredworkflow

92 Bytes
Binary file not shown.

convert.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ def main(wf):
3838
if len(fr) != 3 or len(to) != 3:
3939
wait()
4040

41-
value = amount * get_rate(fr, to)
41+
rate = get_rate(fr, to)
42+
43+
if not rate:
44+
rate = get_rate_alt(fr, to)
45+
46+
value = amount * rate
47+
4248
formatted = "{:.2f}".format(value)
4349

4450
# Add an item to Alfred feedback
@@ -67,8 +73,16 @@ def wait():
6773
def get_rate(fr, to):
6874
data = web.get('http://apilayer.net/api/live?access_key=c938bcf13e0aff152614745f41414ed4&currencies=%s,%s' % (fr, to)).json()
6975

70-
try:
76+
if data['success']:
7177
return (1 / data['quotes']['USD%s' % fr]) * data['quotes']['USD%s' % to]
78+
else:
79+
return None
80+
81+
def get_rate_alt(fr, to):
82+
data = web.get('http://free.currencyconverterapi.com/api/v3/convert?q=%s_%s&compact=ultra' % (fr, to)).json()
83+
84+
try:
85+
return data['%s_%s' % (fr, to)]
7286
except:
7387
wait()
7488

0 commit comments

Comments
 (0)