From 109561c69495ba6fa4eabcd0a52c64dc28cd7521 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Mon, 9 May 2016 11:57:07 +0100 Subject: [PATCH 1/2] Refactor to work with fixer.io Mild rewrite to get the currency converter working and a lot more compatible with the language used in google to get ccy conversions. --- Currency Converter.alfredworkflow | Bin 33229 -> 33451 bytes README.md | 39 ++++++++------ src/.DS_Store | Bin 6148 -> 0 bytes src/currency.php | 23 +++++--- src/info.plist | 85 ------------------------------ 5 files changed, 40 insertions(+), 107 deletions(-) delete mode 100644 src/.DS_Store delete mode 100644 src/info.plist diff --git a/Currency Converter.alfredworkflow b/Currency Converter.alfredworkflow index f95f0a911f439b5ea94e30f084819c041617b6f6..9b080a26c63448f8f2392dc0d7b8c6ee49d3b0db 100644 GIT binary patch delta 2514 zcmaKuc{tQ-8^?cRZ^#xQTZk-UNrNU!G>6JQGPcH)os3D1Av(v;l2Q#rGboA~h9k_V zEJbOuL{bx}>`Np|80#xUN9VlnIi2&q*ZVxz^T+*M*Y~;a=a29A`n*cyDNW)5o$Yw} zqyPXA0#Y$|j#^}*g`9Z-;JF|GhyV(JAMxC|0K8wcUU+ag+I1Vis}pSCo)&80PCPFR zK=@W50Pwpy13i%1X(RRI^>GCol%GsFZ(%o|gR$hFkoVQECZ`5H-*giaXLc#wGDomYtSzIs1}26+d+8+PKWGJ4iLx;oIEclMI3PPiko zY42l=4mKE$^@AfRM73H*EVa6O3<`g0q|~^$xCl6w2SPC37GlE-)Kq=&!j7lhaxCB6 z^i`Zp`Rg7^?MH3%>|l6dWv;YbOe`Qj40L;vRfG@jf{^&O?}05mD-K;cY-RQ8*h>*P zJZe{2E2X?$^+7tzbWxsXW?0SS{8X7$)LsI-XA>(8@&z=xND-b94|il6>&(Yk$Ku`f z;x6mj?|<+uHL8yn9~w#TTRq}HAGlpGC*fgDjvf4<6&1#3^yt)awuxu<=y0Svk^Atj z>d6E1Gm}$zv-b>3+iRK&`IXapezKQ1n~~nTabHsebIJ0NPQi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tXTOjodJ|J9)Km}Nan_s^Oz)d*^Y|F&X3 z)|P&KLwnRxB@9v8ys?&qIxL!wLA|=?yBe35OR2cavL$MndEeXqZ~mVFf2)0%|O)g`uZKT zGM@(G28G8q^l|*ys;lYR4Z9XmPPl{8YbwSq%}~w?*FJBH4w{BJPZR8s!S~e-q(rMx z-REYc?IK&QOrLhtaQn3Mg-dcVL4L^yoD;vjaQXGZz{GyN=+MeMIL>9$HDb@>aCIc2 zO?@`~P`F<6Lff(~h;Dsc*xT0g`S`SG)8Y5*p4^)iB1a3g+Aegy9YEqS+fLi-I#7L( z;!0Ro7yW(W5$*(`AuFwN&VR!{(6j@0%TVE3X_{3=X#H6WMDEmiSHu7~=Zc8-3hkQX zRHz>xMsqsQ+$FOX~*c8Mn-<=Bvc@61Wv0pz1LR1yLsaHsJw2m ztI%`Vm+1Z5n*7wi(1|xu^Uc>v@D>*B=%Sl3zSaR;a=OoMb$J%k411YsNKzY&L>@T| zy34L_R*E)&Hf2It9EpYS8Est(tdyxls(&tQlhF~8ePVmH?S9S~;Ipx9E`zLG?m46z zPburD`O5w?@3s=l+*SxAopaCE}rf^n%m_QHWe6lmZ@_o zx+gpz 30USD to EUR -The default currency is DKK (can be changed) so the following will convert from USD to DKK: +> 30 USD in EUR + +Note that `in` and `to` are interchangable. The default currency is GBP (can be changed) so the following will convert from USD to GBP: + > 30USD Another shorthand is: + > 30$ to € -And even shorter: +And even shorter: + > 30$ € -Installation -========= -[Download](https://github.com/sqren/alfred-currency/raw/master/Currency%20Converter.alfredworkflow) and open the workflow file +All FX rates come from [fixer.io](http://fixer.io/). + +## Usage + +The alfred command is `c`, and hitting return will copy the converted currency value to the clipboard. + +## Installation + +[Download](https://github.com/remy/alfred-currency/raw/master/Currency%20Converter.alfredworkflow) and open the workflow file + +## Requirements -Requirements -========= - You must installed: +You must installed: - [Alfred 2.0](http://www.alfredapp.com/) or higher - [Alfred PowerPack](http://www.alfredapp.com/powerpack/) +## Author -Author -======= -Søren Louv-Jansen, [Konscript](http://www.konscript.com) +- [Remy sharp](https://remysharp.com) +- Søren Louv-Jansen, [Konscript](http://www.konscript.com) ([original author](https://github.com/sqren/alfred-currency)) diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0>> query'); + // print_r($query); // parse query - preg_match("/^(\d+)([A-Z]{3})\s?([A-Z]{3})?$/", $query, $matches); + preg_match("/^(\d+)\s?([A-Z]{3})\s?([A-Z]{3})?$/", $query, $matches); + // print_r('>>> matches'); // print_r($matches); if(!empty($matches)){ @@ -70,4 +79,4 @@ function getResult($query, $default_currency){ return $wf->toxml(); } -// echo getResult("40usd $"); \ No newline at end of file +// echo getResult("40usd $"); diff --git a/src/info.plist b/src/info.plist deleted file mode 100644 index e85087e..0000000 --- a/src/info.plist +++ /dev/null @@ -1,85 +0,0 @@ - - - - - bundleid - currencyconverter - connections - - 63F60794-BB56-4415-9372-BAF974C3A7E1 - - - createdby - Søren Louv-Jansen - description - Convert currencies with ease - disabled - - name - Currency Converter - objects - - - config - - argumenttype - 0 - escaping - 36 - keyword - c - runningsubtext - Please wait while I fetch the newest exchange rates - script - // Type your default currency below. -// Must be in the official three-letter format -// Eg. EUR, USD, GBP -$default_currency = "DKK"; - -// ======= DO NOT EDIT BELOW THIS LINE ====== -require_once('currency.php'); -$query = "{query}"; -echo getResult($query, $default_currency); - subtext - Easily convert between currencies - title - Currency Converter - type - 1 - withspace - - - type - alfred.workflow.input.scriptfilter - uid - 63F60794-BB56-4415-9372-BAF974C3A7E1 - version - 0 - - - readme - Currency Converter is a workflow for Alfred App on Mac. - -The basic way to use the converter is to call Alfred with: -30USD to EUR - -The default currency is DKK (can be changed) so the following will will convert from USD to DKK: -30USD - -Another shorthand is: -30$ to € - -And even shorter: -30$ € - uidata - - 63F60794-BB56-4415-9372-BAF974C3A7E1 - - ypos - 60 - - - webaddress - konscript.com - - From c626628c7b164dab7cea6e93892c445d92fa5ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Zu=CC=88rn?= Date: Fri, 8 Feb 2019 18:02:23 +0100 Subject: [PATCH 2/2] Updated API endpoint --- Currency Converter.alfredworkflow | Bin 33451 -> 33672 bytes README.md | 7 +++--- src/currency.php | 39 ++++++++++++++++++------------ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Currency Converter.alfredworkflow b/Currency Converter.alfredworkflow index 9b080a26c63448f8f2392dc0d7b8c6ee49d3b0db..caf0714fb17e69a3e03e352ab5719b511d188a6c 100644 GIT binary patch delta 2846 zcmajhXH*mU8V2y8cL5Dmiu7KxbSY8{-7H+~N02_et^YOXkiMS{3?d)x8LIDub*IQeOpB=vdDu96a69E8xn@%PVXuh)ob+0DV%;7UmP=zrMkW1}^0`tiUOP7}e-uh+dnnxeS?EwOIOzhY zqmu>>=Bjkh^#)0CF28NTK+1A?wvBuEG`ZskHY*~6^o?rFf(Ji6Sc9W7TgiQ_UZE`( zlN*v#?v*!o-;Ta7JQ^Y=UhrCJ`g%0v7WoS-Bhnrt=*zBz0@6y-v5;+Pv-P00LH-w_NX$7Ur3?Psl(iW27Q@Xb-D7vxuiL6Ar$K zr9^d%e&+TU>f9t-ZUh*nTMFg2<~v-*IYsT+NmsrN!cgfl=?dl7#^CohZm247Aw_-S zerF}Ge11I*mdYEmnmBuQDt zBpIo8-pf;cq+(23zM2GI%vajR&Fbd(x9`?8YXMG9{Op@6l~ol|zH8dK!ciicA`Vo% zWdr2mXbnpkx8bt*Z;d>%salo=yW1h1VprhzpiKJW`dX=YwmT{07$`S(bL~yjZS@9f z;p)D%;`N8F)LnITou$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#Ug(d%^KBtQSh2JS5yOj}U8Ll_`j$fs#7fL+M%>NgW~s zOHz(EV_nx^oi$nStu9FHC9f0PDT`IE1@2O-`ZI`&;q;@oAEi&1d}=4TTq@5O^+fHuOGjhYPNh~Te<&5jm7jtD4?iHhEqt(Ce z^^D_-fIVn3?m(yHfTvTk)RM~_CxcJ#hmS_%mB*kka#4ntl@d^~M>|7v zazyOm1Z(F*bdUNE(v1+z>wgI@37U*#`pS%?)_Z$K<@%FNO!&I5*cu19Xykh$_aiy^ z>R?McWBZ~JE#llUrAGF1Q&Kg@B`tc!b;eV$LU~ivA_BJ)cvral{_0uOrO!=62!lZ~ z^L<9cYrXbf2EG?g{cUIAPI)d&5vWlYn>8Soa4c1fx230=(J<4~ZiulVwA@If&Yx@( zj!bE6>0Uv&^_^N{y;M)wqY`c2_RTVTQ;ypot^l)r=V2^xvq*6wSm;%sDQYg8_ToC{ zV7#opma={Xn5Yz5gk#J4*x$rXXEB+hHs;>i)8v=Y2!_G<*xbB7}#EA`^@) zc6rr{X=M3e#69lf?r(;Ni8U9oB)0qt+HD`w=n5ibj|z z6kh1aLBVqi@Qmz|4^U0+=9Jn)36GN@=-sfwSIra2sb@d$*ZI1_0zG$f&!;$KUC%Xl z3YeOoEV`@t;wt=1nLcwNe(>>}+^M<2vO0%@Wln|Diu~)B`vzDE@Q0^`Yx@~7wBMPM z$2@jRLgi0%DZt`b?w^OwXWf$=uDm7@{_+d|PqgJGY@rQKlH*q$S^o>X+(}n>`TlAp zsVh+m^4kvbKmK8B!NxAl@xx=jqw+|!xL*2}$ov!-f*;y}6X4k9=RbtMlQbn-97J0K zK!8^eK|T22!ELnuL-6mA72UEb0N6q)P!L5A+M4zYa 30$ € -All FX rates come from [fixer.io](http://fixer.io/). +All exchange rates come from [exchangeratesapi.io](https://exchangeratesapi.io/). ## Usage @@ -26,7 +26,7 @@ The alfred command is `c`, and hitting return will copy the converted currency v ## Installation -[Download](https://github.com/remy/alfred-currency/raw/master/Currency%20Converter.alfredworkflow) and open the workflow file +[Download](./Currency%20Converter.alfredworkflow) and open the workflow file. ## Requirements @@ -37,5 +37,6 @@ You must installed: ## Author -- [Remy sharp](https://remysharp.com) +- Martin Zürn +- [Remy sharp](https://remysharp.com) ([Repo](https://github.com/remy/alfred-currency)) - Søren Louv-Jansen, [Konscript](http://www.konscript.com) ([original author](https://github.com/sqren/alfred-currency)) diff --git a/src/currency.php b/src/currency.php index fdef0fe..cab64a5 100644 --- a/src/currency.php +++ b/src/currency.php @@ -6,33 +6,42 @@ function getRow($currency_from, $currency_to, $amount){ global $wf; // build URL - $url = "http://api.fixer.io/latest?base=" . strtoupper($currency_from) . "&symbols=" . strtoupper($currency_to); + $url = "https://api.exchangeratesapi.io/latest?base=" . $currency_from . "&symbols=" . $currency_to; // get exchange rate - $data_json = file_get_contents($url); + $options = array('http' => array('ignore_errors' => TRUE)); + $context = stream_context_create($options); + $data_json = file_get_contents($url, false, $context); $data = json_decode($data_json); - // Error occurec. Probabl invalid currency - if(isset($data->err)){ - $subtext = "Supported currencies are: DKK, EUR, USD, SEK, GBP, CHF, AUD, NOK"; - $wf->result(time(), $data->err, "Invalid currency", $subtext, 'icon.png'); + // print_r($data); - // No problems - }else{ - // print_r($data); + if(!isset($data->error) && getHttpCode($http_response_header) == 200){ $exchange_rate = $data->rates->$currency_to; - - $clipboard = round($exchange_rate * $amount, 1); - $text = round($exchange_rate * $amount, 1) . " " . $currency_to; + $clipboard = number_format($exchange_rate * $amount, 2); + $text = $clipboard . " " . $currency_to; $sub_text = $currency_from . ' to ' . $currency_to; - $wf->result(time(), $clipboard, $text, $sub_text, 'icon.png'); + } else { + $subtext = $data->error . " Please check if currencies are valid."; + $wf->result(time(), $data->err, "Could not fetch data", trim($subtext), 'icon.png'); } } +function getHttpCode($http_response_header) +{ + if(is_array($http_response_header)) + { + $parts=explode(' ',$http_response_header[0]); + if(count($parts)>1) //HTTP/1.0 + return intval($parts[1]); //Get code + } + return 0; +} + function getWaitingRow(){ global $wf; - $wf->result(time(), "Waiting for input", "Waiting for input...", "Type in like: 50USD to EUR", 'icon.png'); + $wf->result(time(), "Waiting for input", "Waiting for input...", "Type in like: 50 USD to EUR", 'icon.png'); } function getResult($query, $default_currency){ @@ -79,4 +88,4 @@ function getResult($query, $default_currency){ return $wf->toxml(); } -// echo getResult("40usd $"); +// echo getResult("41 GBP", "EUR");