@@ -46,17 +46,8 @@ def main(wf):
4646 if rate :
4747 rates .append (rate )
4848
49- value = amount * rate
50-
51- formatted = "{:.2f}" .format (value )
52- formatted_amount = "{:.2f}" .format (amount )
53- wf .add_item ('%s %s = %s %s' % (formatted_amount , fr , formatted , cur ), valid = True ,
54- subtitle = 'Press enter to copy to clipboard' , copytext = formatted , arg = formatted )
55- value = amount / rate
56- formatted = "{:.2f}" .format (value )
57-
58- wf .add_item ('%s %s = %s %s' % (formatted_amount , cur , formatted , fr ), valid = True ,
59- subtitle = 'Press enter to copy to clipboard' , copytext = formatted , arg = formatted )
49+ add_item (amount , fr , amount * rate , cur )
50+ add_item (amount , cur , amount / rate , fr )
6051
6152 if len (rates ) == 0 :
6253 wait ()
@@ -65,6 +56,12 @@ def main(wf):
6556 wf .send_feedback ()
6657
6758
59+ def add_item (amount , fr , value , to ):
60+ formatted = '%g' % (value )
61+ wf .add_item ('%g %s = %s %s' % (amount , fr , formatted , to ), valid = True ,
62+ subtitle = 'Press enter to copy to clipboard' , copytext = formatted , arg = formatted )
63+
64+
6865def check_settings (wf ):
6966 if not 'defaults' in wf .settings :
7067 wf .settings ['defaults' ] = {'fr' : 'USD' , 'to' : ['EUR' ]}
@@ -113,14 +110,13 @@ def get_rate(fr, to):
113110 else :
114111 return get_rate_alt (fr , to )
115112
116- return res
117-
118113
119114def get_rate_alt (fr , to ):
120115 try :
121116 data = web .get (
122- 'http://free.currencyconverterapi.com/api/v3/convert?q=%s_%s&compact=ultra' % (fr , to )).json ()
123- return data ['%s_%s' % (fr , to )]
117+ 'http://free.currencyconverterapi.com/api/v3/convert?q=%s_%s&compact=ultra^&apiKey=5b0607fcc1fe232a0178' % (fr , to )).json ()
118+
119+ return data ['results' ]['%s_%s' % (fr , to )]['val' ]
124120 except :
125121 return None
126122
0 commit comments