diff --git a/CHANGELOG.md b/CHANGELOG.md index 6289cc9..eb80509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,27 @@ Changelog ========= +### [3.7.0][v3.7.0] ### + +Released 2020-02-20 + +- Add exchange rates from ExchangeRate-API.com (no API key required) + + +### [3.6.2][v3.6.2] ### + +Released 2019-09-06 + +- Include `pkg_resources` (Pint dependency) + + +### [3.6.1][v3.6.1] ### + +Released 2019-05-30 + +- Fix argument quoting + + ### [3.6.0][v3.6.0] ### Released 2019-05-06 @@ -200,4 +221,7 @@ Released 2014-08-09. [v3.5.2]: https://github.com/deanishe/alfred-convert/releases/tag/v3.5.2 [v3.5.3]: https://github.com/deanishe/alfred-convert/releases/tag/v3.5.3 [v3.6.0]: https://github.com/deanishe/alfred-convert/releases/tag/v3.6.0 +[v3.6.1]: https://github.com/deanishe/alfred-convert/releases/tag/v3.6.1 +[v3.6.2]: https://github.com/deanishe/alfred-convert/releases/tag/v3.6.2 +[v3.7.0]: https://github.com/deanishe/alfred-convert/releases/tag/v3.7.0 [openx]: https://openexchangerates.org/ \ No newline at end of file diff --git a/Convert-3.6.2.alfredworkflow b/Convert-3.7.0.alfredworkflow similarity index 84% rename from Convert-3.6.2.alfredworkflow rename to Convert-3.7.0.alfredworkflow index c1b8929..b21b1ef 100644 Binary files a/Convert-3.6.2.alfredworkflow and b/Convert-3.7.0.alfredworkflow differ diff --git a/README.md b/README.md index e27867b..c1483c4 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Downloading Download from [GitHub releases][ghreleases]. -**Note**: Version 3.0 and above only supports Alfred 3+. If you're still using Alfred 2, please download [v2.5][v2.5]. +**Note**: Version 3.7 and above only supports Alfred 4+. If you're still using Alfred 4, please download [v3.6.2][v3.6.2]. @@ -58,7 +58,7 @@ Usage ### Conversions ### -**NOTE**: To perform conversions between fiat currencies, you must set a key for the [openexchangerates.org][openx] API in the workflow's [configuration sheet](#configuration). You can sign up for a free account [here][openx-free]. When you're signed up, copy the **App ID** from the email you receive or [this page][openx-appid] into the `APP_KEY` field in the [configuration sheet](#configuration). +**NOTE**: Only a limited number of fiat currencies are supported by default. Additional rates are only supported if you set a key for the [openexchangerates.org][openx] API in the workflow's [configuration sheet](#configuration). You can sign up for a free account [here][openx-free]. When you're signed up, copy the **App ID** from the email you receive or [this page][openx-appid] into the `APP_KEY` field in the [configuration sheet](#configuration). - `conv [] []` — Perform a conversion - `↩` or `⌘C` — Copy the result to the pasteboard @@ -161,6 +161,9 @@ See [CHANGELOG][changelog] for more information. | Release | Date | |-----------------|----------------| +| [3.7.0][v3.7.0] | 2020-02-20 | +| [3.6.2][v3.6.2] | 2019-09-06 | +| [3.6.1][v3.6.1] | 2019-05-30 | | [3.6.0][v3.6.0] | 2019-05-06 | | [3.5.3][v3.5.3] | 2019-01-26 | | [3.5.2][v3.5.2] | 2019-01-26 | @@ -232,6 +235,9 @@ All other code/media are released under the [MIT Licence][mit]. [v3.5.2]: https://github.com/deanishe/alfred-convert/releases/tag/v3.5.2 [v3.5.3]: https://github.com/deanishe/alfred-convert/releases/tag/v3.5.3 [v3.6.0]: https://github.com/deanishe/alfred-convert/releases/tag/v3.6.0 +[v3.6.1]: https://github.com/deanishe/alfred-convert/releases/tag/v3.6.1 +[v3.6.2]: https://github.com/deanishe/alfred-convert/releases/tag/v3.6.2 +[v3.7.0]: https://github.com/deanishe/alfred-convert/releases/tag/v3.7.0 [cryptocompare]: https://www.cryptocompare.com/ [openx]: https://openexchangerates.org/ [openx-free]: https://openexchangerates.org/signup/free diff --git a/docs/currencies.md b/docs/currencies.md index 730ac56..c7f80df 100644 --- a/docs/currencies.md +++ b/docs/currencies.md @@ -15,199 +15,183 @@ Supported Currencies Fiat currencies --------------- -Exchange rates are downloaded from [OpenExchangeRates.org][openx]. - -The following fiat currencies are supported by the workflow: - -| Symbol | Name | -|--------|-----------------------------------------------| -| AED | UAE Dirham | -| AFN | Afghani | -| ALL | Lek | -| AMD | Armenian Dram | -| ANG | Netherlands Antillean Guilder | -| AOA | Kwanza | -| ARS | Argentine Peso | -| AUD | Australian Dollar | -| AWG | Aruban Florin | -| AZN | Azerbaijan Manat | -| BAM | Convertible Mark | -| BBD | Barbados Dollar | -| BDT | Taka | -| BGN | Bulgarian Lev | -| BHD | Bahraini Dinar | -| BIF | Burundi Franc | -| BMD | Bermudian Dollar | -| BND | Brunei Dollar | -| BOB | Boliviano | -| BOV | Mvdol | -| BRL | Brazilian Real | -| BSD | Bahamian Dollar | -| BTC | Bitcoin | -| BTN | Ngultrum | -| BWP | Pula | -| BYN | Belarusian Ruble | -| BZD | Belize Dollar | -| CAD | Canadian Dollar | -| CDF | Congolese Franc | -| CHE | WIR Euro | -| CHF | Swiss Franc | -| CHW | WIR Franc | -| CLF | Unidad de Fomento | -| CLP | Chilean Peso | -| CNH | Chinese yuan (Hong Kong) | -| CNT | Chinese yuan (Taiwan) | -| CNY | Yuan Renminbi | -| COP | Colombian Peso | -| COU | Unidad de Valor Real | -| CRC | Costa Rican Colon | -| CUC | Peso Convertible | -| CUP | Cuban Peso | -| CVE | Cabo Verde Escudo | -| CZK | Czech Koruna | -| DJF | Djibouti Franc | -| DKK | Danish Krone | -| DOP | Dominican Peso | -| DZD | Algerian Dinar | -| EGP | Egyptian Pound | -| ERN | Nakfa | -| ETB | Ethiopian Birr | -| EUR | Euro | -| FJD | Fiji Dollar | -| FKP | Falkland Islands Pound | -| GBP | Pound Sterling | -| GEL | Lari | -| GGP | Guernsey pound | -| GHS | Ghana Cedi | -| GIP | Gibraltar Pound | -| GMD | Dalasi | -| GNF | Guinean Franc | -| GTQ | Quetzal | -| GYD | Guyana Dollar | -| HKD | Hong Kong Dollar | -| HNL | Lempira | -| HRK | Kuna | -| HTG | Gourde | -| HUF | Forint | -| IDR | Rupiah | -| ILS | New Israeli Sheqel | -| IMP | Manx pound | -| INR | Indian Rupee | -| IQD | Iraqi Dinar | -| IRR | Iranian Rial | -| ISK | Iceland Krona | -| JEP | Jersey pound | -| JMD | Jamaican Dollar | -| JOD | Jordanian Dinar | -| JPY | Yen | -| KES | Kenyan Shilling | -| KGS | Som | -| KHR | Riel | -| KID | Kiribati dollar | -| KMF | Comorian Franc | -| KPW | North Korean Won | -| KRW | Won | -| KWD | Kuwaiti Dinar | -| KYD | Cayman Islands Dollar | -| KZT | Tenge | -| LAK | Lao Kip | -| LBP | Lebanese Pound | -| LKR | Sri Lanka Rupee | -| LRD | Liberian Dollar | -| LSL | Loti | -| LYD | Libyan Dinar | -| MAD | Moroccan Dirham | -| MDL | Moldovan Leu | -| MGA | Malagasy Ariary | -| MKD | Denar | -| MMK | Kyat | -| MNT | Tugrik | -| MOP | Pataca | -| MRO | Ouguiya | -| MUR | Mauritius Rupee | -| MVR | Rufiyaa | -| MWK | Malawi Kwacha | -| MXN | Mexican Peso | -| MXV | Mexican Unidad de Inversion (UDI) | -| MYR | Malaysian Ringgit | -| MZN | Mozambique Metical | -| NAD | Namibia Dollar | -| NGN | Naira | -| NIO | Cordoba Oro | -| NIS | New Israeli Shekel | -| NOK | Norwegian Krone | -| NPR | Nepalese Rupee | -| NTD | New Taiwan Dollar | -| NZD | New Zealand Dollar | -| OMR | Rial Omani | -| PAB | Balboa | -| PEN | Sol | -| PGK | Kina | -| PHP | Philippine Piso | -| PKR | Pakistan Rupee | -| PLN | Zloty | -| PYG | Guarani | -| QAR | Qatari Rial | -| RON | Romanian Leu | -| RSD | Serbian Dinar | -| RUB | Russian Ruble | -| RWF | Rwanda Franc | -| SAR | Saudi Riyal | -| SBD | Solomon Islands Dollar | -| SCR | Seychelles Rupee | -| SDG | Sudanese Pound | -| SEK | Swedish Krona | -| SGD | Singapore Dollar | -| SHP | Saint Helena Pound | -| SLL | Leone | -| SLS | Somaliland shilling | -| SOS | Somali Shilling | -| SRD | Surinam Dollar | -| SSP | South Sudanese Pound | -| STD | Dobra | -| SVC | El Salvador Colon | -| SYP | Syrian Pound | -| SZL | Lilangeni | -| THB | Baht | -| TJS | Somoni | -| TMT | Turkmenistan New Manat | -| TND | Tunisian Dinar | -| TOP | Pa’anga | -| TRY | Turkish Lira | -| TTD | Trinidad and Tobago Dollar | -| TVD | Tuvalu dollar | -| TWD | New Taiwan Dollar | -| TZS | Tanzanian Shilling | -| UAH | Hryvnia | -| UGX | Uganda Shilling | -| USD | US Dollar | -| USN | US Dollar (Next day) | -| UYI | Uruguay Peso en Unidades Indexadas (URUIURUI) | -| UYU | Peso Uruguayo | -| UZS | Uzbekistan Sum | -| VEF | Bolívar | -| VND | Dong | -| VUV | Vatu | -| WST | Tala | -| XAF | CFA Franc BEAC | -| XAG | Silver | -| XAU | Gold | -| XBA | Bond Markets Unit European Composite Unit | -| XBB | Bond Markets Unit European Monetary Unit | -| XBD | Bond Markets Unit European Unit of Account 17 | -| XCD | East Caribbean Dollar | -| XDR | SDR (Special Drawing Right) | -| XOF | CFA Franc BCEAO | -| XPF | CFP Franc | -| XPT | Platinum | -| XSU | Sucre | -| XUA | ADB Unit of Account | -| YER | Yemeni Rial | -| ZAR | Rand | -| ZMW | Zambian Kwacha | -| ZWL | Zimbabwe Dollar | +Exchange rates are downloaded from [ExchangeRate-API.com][xapi] and [OpenExchangeRates.org][openx]. +The following fiat currencies are supported by the workflow (currencies marked with `*` require an API key for OpenExchangeRates.org): +| Symbol | Name | +|--------|----------------------------------------| +| AED | United Arab Emirates Dirham | +| AFN | Afghan Afghani \* | +| ALL | Albanian Lek \* | +| AMD | Armenian Dram \* | +| ANG | Netherlands Antillean Guilder \* | +| AOA | Angolan Kwanza \* | +| ARS | Argentine Peso | +| AUD | Australian Dollar | +| AWG | Aruban Florin \* | +| AZN | Azerbaijani Manat \* | +| BAM | Bosnia-Herzegovina Convertible Mark \* | +| BBD | Barbadian Dollar \* | +| BDT | Bangladeshi Taka \* | +| BGN | Bulgarian Lev | +| BHD | Bahraini Dinar \* | +| BIF | Burundian Franc \* | +| BMD | Bermudan Dollar \* | +| BND | Brunei Dollar \* | +| BOB | Bolivian Boliviano \* | +| BRL | Brazilian Real | +| BSD | Bahamian Dollar | +| BTC | Bitcoin \* | +| BTN | Bhutanese Ngultrum \* | +| BWP | Botswanan Pula \* | +| BYN | Belarusian Ruble \* | +| BYR | Belarusian Ruble (pre-2016) \* | +| BZD | Belize Dollar \* | +| CAD | Canadian Dollar | +| CDF | Congolese Franc \* | +| CHF | Swiss Franc | +| CLF | Chilean Unit of Account (UF) \* | +| CLP | Chilean Peso | +| CNH | Chinese Yuan (Offshore) \* | +| CNY | Chinese Renminbi | +| COP | Colombian Peso | +| CRC | Costa Rican Colón \* | +| CUC | Cuban Convertible Peso \* | +| CUP | Cuban Peso \* | +| CVE | Cape Verdean Escudo \* | +| CZK | Czech Koruna | +| DJF | Djiboutian Franc \* | +| DKK | Danish Krone | +| DOP | Dominican Peso | +| DZD | Algerian Dinar \* | +| EEK | Estonian Kroon \* | +| EGP | Egyptian Pound | +| ERN | Eritrean Nakfa \* | +| ETB | Ethiopian Birr \* | +| EUR | Euro | +| FJD | Fijian Dollar | +| FKP | Falkland Islands Pound \* | +| GBP | British Pound Sterling | +| GEL | Georgian Lari \* | +| GGP | Guernsey Pound \* | +| GHS | Ghanaian Cedi \* | +| GIP | Gibraltar Pound \* | +| GMD | Gambian Dalasi \* | +| GNF | Guinean Franc \* | +| GTQ | Guatemalan Quetzal | +| GYD | Guyanaese Dollar \* | +| HKD | Hong Kong Dollar | +| HNL | Honduran Lempira \* | +| HRK | Croatian Kuna | +| HTG | Haitian Gourde \* | +| HUF | Hungarian Forint | +| IDR | Indonesian Rupiah | +| ILS | Israeli Shekel | +| IMP | Manx pound \* | +| INR | Indian Rupee | +| IQD | Iraqi Dinar \* | +| IRR | Iranian Rial \* | +| ISK | Icelandic Krona | +| JEP | Jersey Pound \* | +| JMD | Jamaican Dollar \* | +| JOD | Jordanian Dinar \* | +| JPY | Japanese Yen | +| KES | Kenyan Shilling \* | +| KGS | Kyrgystani Som \* | +| KHR | Cambodian Riel \* | +| KMF | Comorian Franc \* | +| KPW | North Korean Won \* | +| KRW | South Korean Won | +| KWD | Kuwaiti Dinar \* | +| KYD | Cayman Islands Dollar \* | +| KZT | Kazakhstani Tenge | +| LAK | Laotian Kip \* | +| LBP | Lebanese Pound \* | +| LKR | Sri Lankan Rupee \* | +| LRD | Liberian Dollar \* | +| LSL | Lesotho Loti \* | +| LYD | Libyan Dinar \* | +| MAD | Moroccan Dirham \* | +| MDL | Moldovan Leu \* | +| MGA | Malagasy Ariary \* | +| MKD | Macedonian Denar \* | +| MMK | Myanma Kyat \* | +| MNT | Mongolian Tugrik \* | +| MOP | Macanese Pataca \* | +| MRO | Mauritanian Ouguiya (pre-2018) \* | +| MRU | Mauritanian Ouguiya \* | +| MTL | Maltese Lira \* | +| MUR | Mauritian Rupee \* | +| MVR | Maldivian Rufiyaa \* | +| MWK | Malawian Kwacha \* | +| MXN | Mexican Peso | +| MYR | Malaysian Ringgit | +| MZN | Mozambican Metical \* | +| NAD | Namibian Dollar \* | +| NGN | Nigerian Naira \* | +| NIO | Nicaraguan Córdoba \* | +| NOK | Norwegian Krone | +| NPR | Nepalese Rupee \* | +| NZD | New Zealand Dollar | +| OMR | Omani Rial \* | +| PAB | Panamanian Balboa | +| PEN | Peruvian Nuevo Sol | +| PGK | Papua New Guinean Kina \* | +| PHP | Philippine Peso | +| PKR | Pakistani Rupee | +| PLN | Polish Zloty | +| PYG | Paraguayan Guarani | +| QAR | Qatari Rial \* | +| RON | Romanian Leu | +| RSD | Serbian Dinar \* | +| RUB | Russian Ruble | +| RWF | Rwandan Franc \* | +| SAR | Saudi Riyal | +| SBD | Solomon Islands Dollar \* | +| SCR | Seychellois Rupee \* | +| SDG | Sudanese Pound \* | +| SEK | Swedish Krona | +| SGD | Singapore Dollar | +| SHP | Saint Helena Pound \* | +| SLL | Sierra Leonean Leone \* | +| SOS | Somali Shilling \* | +| SRD | Surinamese Dollar \* | +| SSP | South Sudanese Pound \* | +| STN | São Tomé and Príncipe Dobra \* | +| SVC | Salvadoran Colón \* | +| SYP | Syrian Pound \* | +| SZL | Swazi Lilangeni \* | +| THB | Thai Baht | +| TJS | Tajikistani Somoni \* | +| TMT | Turkmenistani Manat \* | +| TND | Tunisian Dinar \* | +| TOP | Tongan Paʻanga \* | +| TRY | Turkish Lira | +| TTD | Trinidad and Tobago Dollar \* | +| TWD | New Taiwan Dollar | +| TZS | Tanzanian Shilling \* | +| UAH | Ukrainian Hryvnia | +| UGX | Ugandan Shilling \* | +| USD | US Dollar | +| UYU | Uruguayan Peso | +| UZS | Uzbekistan Som \* | +| VEF | Venezuelan Bolívar Fuerte \* | +| VND | Vietnamese Dong \* | +| VUV | Vanuatu Vatu \* | +| WST | Samoan Tala \* | +| XAF | CFA Franc BEAC \* | +| XAG | Silver (troy ounce) \* | +| XAU | Gold (troy ounce) \* | +| XCD | East Caribbean Dollar \* | +| XDR | Special Drawing Rights \* | +| XOF | CFA Franc BCEAO \* | +| XPD | Palladium Ounce \* | +| XPF | CFP Franc \* | +| XPT | Platinum Ounce \* | +| YER | Yemeni Rial \* | +| ZAR | South African Rand | +| ZMW | Zambian Kwacha | @@ -1737,5 +1721,6 @@ The following (crypto)currencies are unsupported. Some have symbols that conflic | ZRC* | ZiftrCoin | +[xapi]: https://www.exchangerate-api.com/ [openx]: https://openexchangerates.org/ [cryptocompare]: https://www.cryptocompare.com/ diff --git a/requirements.txt b/requirements.txt index 7554959..aab93e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ Pint==0.9 -Alfred-Workflow==1.36 +Alfred-Workflow==1.37.2 docopt==0.6.2 diff --git a/src/active_currencies.txt.default b/src/active_currencies.txt.default index 6a7834b..d6a3fbc 100644 --- a/src/active_currencies.txt.default +++ b/src/active_currencies.txt.default @@ -26,25 +26,22 @@ BIF BMD BND BOB -BOV BRL BSD +BTC BTN BWP BYN +BYR BZD CAD CDF -CHE CHF -CHW CLF CLP CNH -CNT CNY COP -COU CRC CUC CUP @@ -54,6 +51,7 @@ DJF DKK DOP DZD +EEK EGP ERN ETB @@ -88,7 +86,6 @@ JPY KES KGS KHR -KID KMF KPW KRW @@ -109,20 +106,19 @@ MMK MNT MOP MRO +MRU +MTL MUR MVR MWK MXN -MXV MYR MZN NAD NGN NIO -NIS NOK NPR -NTD NZD OMR PAB @@ -145,11 +141,10 @@ SEK SGD SHP SLL -SLS SOS SRD SSP -STD +STN SVC SYP SZL @@ -160,14 +155,11 @@ TND TOP TRY TTD -TVD TWD TZS UAH UGX USD -USN -UYI UYU UZS VEF @@ -177,21 +169,15 @@ WST XAF XAG XAU -XBA -XBB -XBD XCD XDR XOF XPD XPF XPT -XSU -XUA YER ZAR ZMW -ZWL # Crypto currencies AUR diff --git a/src/config.py b/src/config.py index 149539b..204c8ad 100644 --- a/src/config.py +++ b/src/config.py @@ -37,6 +37,7 @@ CURRENCY_CACHE_NAME = 'exchange_rates' REFERENCE_CURRENCY = 'USD' OPENX_API_URL = 'https://openexchangerates.org/api/latest.json?app_id={}' +XRA_API_URL = 'https://api.exchangerate-api.com/v4/latest/{}' CRYPTO_COMPARE_BASE_URL = ( 'https://min-api.cryptocompare.com/data/price?fsym={}&tsyms={}') SYMBOLS_PER_REQUEST = 20 @@ -55,193 +56,177 @@ ACTIVE_CURRENCIES_FILENAME = 'active_currencies.txt' CURRENCIES = { - u'AED': u'United Arab Emirates dirham', - u'AFN': u'Afghan afghani', - u'ALL': u'Albanian lek', - u'AMD': u'Armenian dram', - u'ANG': u'Netherlands Antillean guilder', - u'AOA': u'Angolan kwanza', - u'ARS': u'Argentine peso', - u'AUD': u'Australian dollar', - u'AWG': u'Aruban florin', - u'AZN': u'Azerbaijani manat', - u'BAM': u'Bosnia and Herzegovina convertible mark', - u'BBD': u'Barbados dollar', - u'BDT': u'Bangladeshi taka', - u'BGN': u'Bulgarian lev', - u'BHD': u'Bahraini dinar', - u'BIF': u'Burundian franc', - u'BMD': u'Bermudian dollar', - u'BND': u'Brunei dollar', - u'BOB': u'Boliviano', - u'BOV': u'Bolivian Mvdol', - u'BRL': u'Brazilian real', - u'BSD': u'Bahamian dollar', - # u'BTC': u'Bitcoin', - u'BTN': u'Bhutanese ngultrum', - u'BWP': u'Botswana pula', - u'BYN': u'Belarusian ruble', - u'BZD': u'Belize dollar', - u'CAD': u'Canadian dollar', - u'CDF': u'Congolese franc', - u'CHE': u'WIR Euro', - u'CHF': u'Swiss franc', - u'CHW': u'WIR Franc', - u'CLF': u'Unidad de Fomento', - u'CLP': u'Chilean peso', - u'CNH': u'Chinese yuan (Hong Kong)', - u'CNT': u'Chinese yuan (Taiwan)', - u'CNY': u'Chinese yuan', - u'COP': u'Colombian peso', - u'COU': u'Unidad de Valor Real (UVR)', - u'CRC': u'Costa Rican colon', - u'CUC': u'Cuban convertible peso', - u'CUP': u'Cuban peso', - u'CVE': u'Cape Verde escudo', - u'CZK': u'Czech koruna', - u'DJF': u'Djiboutian franc', - u'DKK': u'Danish krone', - u'DOP': u'Dominican peso', - u'DZD': u'Algerian dinar', - u'EGP': u'Egyptian pound', - u'ERN': u'Eritrean nakfa', - u'ETB': u'Ethiopian birr', + u'AED': u'United Arab Emirates Dirham', + u'AFN': u'Afghan Afghani', + u'ALL': u'Albanian Lek', + u'AMD': u'Armenian Dram', + u'ANG': u'Netherlands Antillean Guilder', + u'AOA': u'Angolan Kwanza', + u'ARS': u'Argentine Peso', + u'AUD': u'Australian Dollar', + u'AWG': u'Aruban Florin', + u'AZN': u'Azerbaijani Manat', + u'BAM': u'Bosnia-Herzegovina Convertible Mark', + u'BBD': u'Barbadian Dollar', + u'BDT': u'Bangladeshi Taka', + u'BGN': u'Bulgarian Lev', + u'BHD': u'Bahraini Dinar', + u'BIF': u'Burundian Franc', + u'BMD': u'Bermudan Dollar', + u'BND': u'Brunei Dollar', + u'BOB': u'Bolivian Boliviano', + u'BRL': u'Brazilian Real', + u'BSD': u'Bahamian Dollar', + u'BTC': u'Bitcoin', + u'BTN': u'Bhutanese Ngultrum', + u'BWP': u'Botswanan Pula', + u'BYN': u'Belarusian Ruble', + u'BYR': u'Belarusian Ruble (pre-2016)', + u'BZD': u'Belize Dollar', + u'CAD': u'Canadian Dollar', + u'CDF': u'Congolese Franc', + u'CHF': u'Swiss Franc', + u'CLF': u'Chilean Unit of Account (UF)', + u'CLP': u'Chilean Peso', + u'CNH': u'Chinese Yuan (Offshore)', + u'CNY': u'Chinese Renminbi', + u'COP': u'Colombian Peso', + u'CRC': u'Costa Rican Colón', + u'CUC': u'Cuban Convertible Peso', + u'CUP': u'Cuban Peso', + u'CVE': u'Cape Verdean Escudo', + u'CZK': u'Czech Koruna', + u'DJF': u'Djiboutian Franc', + u'DKK': u'Danish Krone', + u'DOP': u'Dominican Peso', + u'DZD': u'Algerian Dinar', + u'EEK': u'Estonian Kroon', + u'EGP': u'Egyptian Pound', + u'ERN': u'Eritrean Nakfa', + u'ETB': u'Ethiopian Birr', u'EUR': u'Euro', - u'FJD': u'Fiji dollar', - u'FKP': u'Falkland Islands pound', - u'GBP': u'Pound sterling', - u'GEL': u'Georgian lari', - u'GGP': u'Guernsey pound', - u'GHS': u'Ghanaian cedi', - u'GIP': u'Gibraltar pound', - u'GMD': u'Gambian dalasi', - u'GNF': u'Guinean franc', - u'GTQ': u'Guatemalan quetzal', - u'GYD': u'Guyanese dollar', - u'HKD': u'Hong Kong dollar', - u'HNL': u'Honduran lempira', - u'HRK': u'Croatian kuna', - u'HTG': u'Haitian gourde', - u'HUF': u'Hungarian forint', - u'IDR': u'Indonesian rupiah', - u'ILS': u'Israeli new shekel', + u'FJD': u'Fijian Dollar', + u'FKP': u'Falkland Islands Pound', + u'GBP': u'British Pound Sterling', + u'GEL': u'Georgian Lari', + u'GGP': u'Guernsey Pound', + u'GHS': u'Ghanaian Cedi', + u'GIP': u'Gibraltar Pound', + u'GMD': u'Gambian Dalasi', + u'GNF': u'Guinean Franc', + u'GTQ': u'Guatemalan Quetzal', + u'GYD': u'Guyanaese Dollar', + u'HKD': u'Hong Kong Dollar', + u'HNL': u'Honduran Lempira', + u'HRK': u'Croatian Kuna', + u'HTG': u'Haitian Gourde', + u'HUF': u'Hungarian Forint', + u'IDR': u'Indonesian Rupiah', + u'ILS': u'Israeli Shekel', u'IMP': u'Manx pound', - u'INR': u'Indian rupee', - u'IQD': u'Iraqi dinar', - u'IRR': u'Iranian rial', - u'ISK': u'Icelandic króna', - u'JEP': u'Jersey pound', - u'JMD': u'Jamaican dollar', - u'JOD': u'Jordanian dinar', - u'JPY': u'Japanese yen', - u'KES': u'Kenyan shilling', - u'KGS': u'Kyrgyzstani som', - u'KHR': u'Cambodian riel', - u'KID': u'Kiribati dollar', - u'KMF': u'Comoro franc', - u'KPW': u'North Korean won', - u'KRW': u'South Korean won', - u'KWD': u'Kuwaiti dinar', - u'KYD': u'Cayman Islands dollar', - u'KZT': u'Kazakhstani tenge', - u'LAK': u'Lao kip', - u'LBP': u'Lebanese pound', - u'LKR': u'Sri Lankan rupee', - u'LRD': u'Liberian dollar', - u'LSL': u'Lesotho loti', - u'LYD': u'Libyan dinar', - u'MAD': u'Moroccan dirham', - u'MDL': u'Moldovan leu', - u'MGA': u'Malagasy ariary', - u'MKD': u'Macedonian denar', - u'MMK': u'Myanmar kyat', - u'MNT': u'Mongolian tögrög', - u'MOP': u'Macanese pataca', - u'MRO': u'Mauritanian ouguiya', - u'MUR': u'Mauritian rupee', - u'MVR': u'Maldivian rufiyaa', - u'MWK': u'Malawian kwacha', - u'MXN': u'Mexican peso', - u'MXV': u'Mexican Unidad de Inversion (UDI)', - u'MYR': u'Malaysian ringgit', - u'MZN': u'Mozambican metical', - u'NAD': u'Namibian dollar', - u'NGN': u'Nigerian naira', - u'NIO': u'Nicaraguan córdoba', - u'NIS': u'New Israeli Shekel', - u'NOK': u'Norwegian krone', - u'NPR': u'Nepalese rupee', - u'NTD': u'New Taiwan Dollar', - u'NZD': u'New Zealand dollar', - u'OMR': u'Omani rial', - u'PAB': u'Panamanian balboa', - u'PEN': u'Peruvian Sol', - u'PGK': u'Papua New Guinean kina', - u'PHP': u'Philippine piso[10]', - u'PKR': u'Pakistani rupee', - u'PLN': u'Polish złoty', - u'PYG': u'Paraguayan guaraní', - u'QAR': u'Qatari riyal', - u'RON': u'Romanian leu', - u'RSD': u'Serbian dinar', - u'RUB': u'Russian ruble', - u'RWF': u'Rwandan franc', - u'SAR': u'Saudi riyal', - u'SBD': u'Solomon Islands dollar', - u'SCR': u'Seychelles rupee', - u'SDG': u'Sudanese pound', - u'SEK': u'Swedish krona/kronor', - u'SGD': u'Singapore dollar', - u'SHP': u'Saint Helena pound', - u'SLL': u'Sierra Leonean leone', - u'SLS': u'Somaliland shilling', - u'SOS': u'Somali shilling', - u'SRD': u'Surinamese dollar', - u'SSP': u'South Sudanese pound', - u'STD': u'São Tomé and Príncipe dobra', - u'SVC': u'Salvadoran colón', - u'SYP': u'Syrian pound', - u'SZL': u'Swazi lilangeni', - u'THB': u'Thai baht', - u'TJS': u'Tajikistani somoni', - u'TMT': u'Turkmenistan manat', - u'TND': u'Tunisian dinar', - u'TOP': u'Tongan paʻanga', - u'TRY': u'Turkish lira', - u'TTD': u'Trinidad and Tobago dollar', - u'TVD': u'Tuvalu dollar', - u'TWD': u'New Taiwan dollar', - u'TZS': u'Tanzanian shilling', - u'UAH': u'Ukrainian hryvnia', - u'UGX': u'Ugandan shilling', - u'USD': u'United States dollar', - u'USN': u'United States dollar (next day)', - u'UYI': u'Uruguay Peso en Unidades Indexadas (URUIURUI)', - u'UYU': u'Uruguayan peso', - u'UZS': u'Uzbekistan som', - u'VEF': u'Venezuelan bolívar', - u'VND': u'Vietnamese đồng', - u'VUV': u'Vanuatu vatu', - u'WST': u'Samoan tala', - u'XAF': u'CFA franc BEAC', - u'XAG': u'Silver (one troy ounce)', - u'XAU': u'Gold (one troy ounce)', - u'XBA': u'European Composite Unit (EURCO)', - u'XBB': u'European Monetary Unit (E.M.U.-6)', - # u'XBC': u'European Unit of Account 9 (E.U.A.-9)', - u'XBD': u'European Unit of Account 17 (E.U.A.-17)', - u'XCD': u'East Caribbean dollar', - u'XDR': u'Special drawing rights', - u'XOF': u'CFA franc BCEAO', - # u'XPD': u'Palladium (one troy ounce)', - u'XPF': u'CFP franc (franc Pacifique)', - u'XPT': u'Platinum (one troy ounce)', - u'XSU': u'SUCRE', - u'XUA': u'ADB Unit of Account', - u'YER': u'Yemeni rial', - u'ZAR': u'South African rand', - u'ZMW': u'Zambian kwacha', - u'ZWL': u'Zimbabwean dollar', + u'INR': u'Indian Rupee', + u'IQD': u'Iraqi Dinar', + u'IRR': u'Iranian Rial', + u'ISK': u'Icelandic Krona', + u'JEP': u'Jersey Pound', + u'JMD': u'Jamaican Dollar', + u'JOD': u'Jordanian Dinar', + u'JPY': u'Japanese Yen', + u'KES': u'Kenyan Shilling', + u'KGS': u'Kyrgystani Som', + u'KHR': u'Cambodian Riel', + u'KMF': u'Comorian Franc', + u'KPW': u'North Korean Won', + u'KRW': u'South Korean Won', + u'KWD': u'Kuwaiti Dinar', + u'KYD': u'Cayman Islands Dollar', + u'KZT': u'Kazakhstani Tenge', + u'LAK': u'Laotian Kip', + u'LBP': u'Lebanese Pound', + u'LKR': u'Sri Lankan Rupee', + u'LRD': u'Liberian Dollar', + u'LSL': u'Lesotho Loti', + u'LYD': u'Libyan Dinar', + u'MAD': u'Moroccan Dirham', + u'MDL': u'Moldovan Leu', + u'MGA': u'Malagasy Ariary', + u'MKD': u'Macedonian Denar', + u'MMK': u'Myanma Kyat', + u'MNT': u'Mongolian Tugrik', + u'MOP': u'Macanese Pataca', + u'MRO': u'Mauritanian Ouguiya (pre-2018)', + u'MRU': u'Mauritanian Ouguiya', + u'MTL': u'Maltese Lira', + u'MUR': u'Mauritian Rupee', + u'MVR': u'Maldivian Rufiyaa', + u'MWK': u'Malawian Kwacha', + u'MXN': u'Mexican Peso', + u'MYR': u'Malaysian Ringgit', + u'MZN': u'Mozambican Metical', + u'NAD': u'Namibian Dollar', + u'NGN': u'Nigerian Naira', + u'NIO': u'Nicaraguan Córdoba', + u'NOK': u'Norwegian Krone', + u'NPR': u'Nepalese Rupee', + u'NZD': u'New Zealand Dollar', + u'OMR': u'Omani Rial', + u'PAB': u'Panamanian Balboa', + u'PEN': u'Peruvian Nuevo Sol', + u'PGK': u'Papua New Guinean Kina', + u'PHP': u'Philippine Peso', + u'PKR': u'Pakistani Rupee', + u'PLN': u'Polish Zloty', + u'PYG': u'Paraguayan Guarani', + u'QAR': u'Qatari Rial', + u'RON': u'Romanian Leu', + u'RSD': u'Serbian Dinar', + u'RUB': u'Russian Ruble', + u'RWF': u'Rwandan Franc', + u'SAR': u'Saudi Riyal', + u'SBD': u'Solomon Islands Dollar', + u'SCR': u'Seychellois Rupee', + u'SDG': u'Sudanese Pound', + u'SEK': u'Swedish Krona', + u'SGD': u'Singapore Dollar', + u'SHP': u'Saint Helena Pound', + u'SLL': u'Sierra Leonean Leone', + u'SOS': u'Somali Shilling', + u'SRD': u'Surinamese Dollar', + u'SSP': u'South Sudanese Pound', + u'STN': u'São Tomé and Príncipe Dobra', + u'SVC': u'Salvadoran Colón', + u'SYP': u'Syrian Pound', + u'SZL': u'Swazi Lilangeni', + u'THB': u'Thai Baht', + u'TJS': u'Tajikistani Somoni', + u'TMT': u'Turkmenistani Manat', + u'TND': u'Tunisian Dinar', + u'TOP': u'Tongan Paʻanga', + u'TRY': u'Turkish Lira', + u'TTD': u'Trinidad and Tobago Dollar', + u'TWD': u'New Taiwan Dollar', + u'TZS': u'Tanzanian Shilling', + u'UAH': u'Ukrainian Hryvnia', + u'UGX': u'Ugandan Shilling', + u'USD': u'US Dollar', + u'UYU': u'Uruguayan Peso', + u'UZS': u'Uzbekistan Som', + u'VEF': u'Venezuelan Bolívar Fuerte', + u'VND': u'Vietnamese Dong', + u'VUV': u'Vanuatu Vatu', + u'WST': u'Samoan Tala', + u'XAF': u'CFA Franc BEAC', + u'XAG': u'Silver (troy ounce)', + u'XAU': u'Gold (troy ounce)', + u'XCD': u'East Caribbean Dollar', + u'XDR': u'Special Drawing Rights', + u'XOF': u'CFA Franc BCEAO', + u'XPD': u'Palladium Ounce', + u'XPF': u'CFP Franc', + u'XPT': u'Platinum Ounce', + u'YER': u'Yemeni Rial', + u'ZAR': u'South African Rand', + u'ZMW': u'Zambian Kwacha', } CRYPTO_CURRENCIES = { diff --git a/src/convert.py b/src/convert.py index 851d18a..db28bfa 100755 --- a/src/convert.py +++ b/src/convert.py @@ -70,8 +70,8 @@ def error_if_currency(unit): """ if unit_is_currency(unit): log.error( - "[parser] unit %s is a fiat currency, but exchange " - "rates aren't configured", unit) + "[parser] unit %s is a fiat currency, but OpenExchangeRates.org " + "API key isn't set", unit) show_currency_help() sys.exit(0) @@ -79,7 +79,7 @@ def error_if_currency(unit): def show_currency_help(): """Show a message in Alfred telling user to set ``APP_KEY``.""" - wf.add_item('Set APP_KEY to convert currencies', + wf.add_item('Set APP_KEY to convert this currency', 'Action this item for instructions', autocomplete='workflow:appkey', icon=ICON_WARNING) diff --git a/src/currency.py b/src/currency.py index c1ac0df..34895a9 100644 --- a/src/currency.py +++ b/src/currency.py @@ -32,6 +32,7 @@ OPENX_APP_KEY, SYMBOLS_PER_REQUEST, USER_AGENT, + XRA_API_URL, ) @@ -83,6 +84,31 @@ def load_cryptocurrency_rates(symbols): return data +def load_xra_rates(symbols): + """Return dict of exchange rates from exchangerate-api.com. + + Returns: + dict: `{symbol: rate}` mapping of exchange rates. + + """ + rates = {} + wanted = set(symbols) + url = XRA_API_URL.format(REFERENCE_CURRENCY) + r = web.get(url, headers={'User-Agent': USER_AGENT}) + r.raise_for_status() + log.debug('[%s] %s', r.status_code, url) + data = r.json() + + for sym, rate in data['rates'].items(): + if sym not in wanted: + continue + log.debug('[ExchangeRate-API.com] 1 %s = %s %s', + REFERENCE_CURRENCY, rate, sym) + rates[sym] = rate + + return rates + + def load_openx_rates(symbols): """Return dict of exchange rates from openexchangerates.org. @@ -160,8 +186,16 @@ def fetch_exchange_rates(): active = load_active_currencies() syms = [s for s in CURRENCIES.keys() if s in active] - # rates.update(load_openx_rates(syms)) - jobs = [(load_openx_rates, (syms,))] + if not OPENX_APP_KEY: + log.warning( + 'fetching limited set of fiat currency exchange rates: ' + 'APP_KEY for openexchangerates.org not set. ' + 'Please sign up for a free account here: ' + 'https://openexchangerates.org/signup/free' + ) + jobs = [(load_xra_rates, (syms,))] + else: + jobs = [(load_openx_rates, (syms,))] syms = [] for s in CRYPTO_CURRENCIES.keys(): @@ -190,7 +224,7 @@ def fetch_exchange_rates(): def main(wf): - """Update exchange rates from Yahoo! Finance. + """Update exchange rates. Args: wf (workflow.Workflow): Workflow object. @@ -199,8 +233,10 @@ def main(wf): start_time = time.time() bootstrap(wf) - log.info('fetching exchange rates from OpenExchangeRates.org and ' - 'CryptoCompare.com ...') + site = 'OpenExchangeRates.org' if OPENX_APP_KEY else 'ExchangeRate-API.com' + + log.info('fetching exchange rates from %s and CryptoCompare.com ...', + site) rates = wf.cached_data(CURRENCY_CACHE_NAME, fetch_exchange_rates, diff --git a/src/info.plist b/src/info.plist index d072fba..c88e6c0 100644 --- a/src/info.plist +++ b/src/info.plist @@ -182,7 +182,7 @@ uid 607FA0B2-94A5-48E4-96E9-0BFA8872F7EE version - 2 + 3 config @@ -210,6 +210,8 @@ alfredfiltersresultsmatchmode 0 + argumenttreatemptyqueryasnil + argumenttrimmode 0 argumenttype @@ -248,7 +250,7 @@ uid 1E12C11D-30DB-44A8-AD75-F5BE7F2DA451 version - 2 + 3 config @@ -364,6 +366,8 @@ variables={allvars} alfredfiltersresultsmatchmode 0 + argumenttreatemptyqueryasnil + argumenttrimmode 0 argumenttype @@ -402,7 +406,7 @@ variables={allvars} uid EF92F243-C49B-4DFC-B0A4-72317B2457A7 version - 2 + 3 config @@ -649,7 +653,7 @@ UPDATE_INTERVAL is the number of minutes between exchange rate updates. APP_KEY version - 3.6.2 + 3.7.0 webaddress diff --git a/src/workflow/.alfredversionchecked b/src/workflow/.alfredversionchecked deleted file mode 100644 index e69de29..0000000 diff --git a/src/workflow/update.py b/src/workflow/update.py index ffc6353..6affc94 100644 --- a/src/workflow/update.py +++ b/src/workflow/update.py @@ -222,7 +222,7 @@ class Version(object): """ #: Match version and pre-release/build information in version strings - match_version = re.compile(r'([0-9\.]+)(.+)?').match + match_version = re.compile(r'([0-9][0-9\.]*)(.+)?').match def __init__(self, vstr): """Create new `Version` object. @@ -247,7 +247,7 @@ def _parse(self, vstr): else: m = self.match_version(vstr) if not m: - raise ValueError('invalid version number: {!r}'.format(vstr)) + raise ValueError('invalid version number: ' + vstr) version, suffix = m.groups() parts = self._parse_dotted_string(version) @@ -257,7 +257,7 @@ def _parse(self, vstr): if len(parts): self.patch = parts.pop(0) if not len(parts) == 0: - raise ValueError('version number too long: {!r}'.format(vstr)) + raise ValueError('version number too long: ' + vstr) if suffix: # Build info @@ -268,11 +268,9 @@ def _parse(self, vstr): if suffix: if not suffix.startswith('-'): raise ValueError( - 'suffix must start with - : {0}'.format(suffix)) + 'suffix must start with - : ' + suffix) self.suffix = suffix[1:] - # wf().logger.debug('version str `{}` -> {}'.format(vstr, repr(self))) - def _parse_dotted_string(self, s): """Parse string ``s`` into list of ints and strings.""" parsed = [] diff --git a/src/workflow/version b/src/workflow/version index 71437d0..673b6a6 100644 --- a/src/workflow/version +++ b/src/workflow/version @@ -1 +1 @@ -1.37 \ No newline at end of file +1.37.2 \ No newline at end of file diff --git a/src/workflow/workflow.py b/src/workflow/workflow.py index 584f376..2a057b0 100644 --- a/src/workflow/workflow.py +++ b/src/workflow/workflow.py @@ -1052,31 +1052,30 @@ def alfred_env(self): data = {} for key in ( - 'alfred_debug', - 'alfred_preferences', - 'alfred_preferences_localhash', - 'alfred_theme', - 'alfred_theme_background', - 'alfred_theme_subtext', - 'alfred_version', - 'alfred_version_build', - 'alfred_workflow_bundleid', - 'alfred_workflow_cache', - 'alfred_workflow_data', - 'alfred_workflow_name', - 'alfred_workflow_uid', - 'alfred_workflow_version'): - - value = os.getenv(key) - - if isinstance(value, str): - if key in ('alfred_debug', 'alfred_version_build', - 'alfred_theme_subtext'): + 'debug', + 'preferences', + 'preferences_localhash', + 'theme', + 'theme_background', + 'theme_subtext', + 'version', + 'version_build', + 'workflow_bundleid', + 'workflow_cache', + 'workflow_data', + 'workflow_name', + 'workflow_uid', + 'workflow_version'): + + value = os.getenv('alfred_' + key, '') + + if value: + if key in ('debug', 'version_build', 'theme_subtext'): value = int(value) else: value = self.decode(value) - data[key[7:]] = value + data[key] = value self._alfred_env = data @@ -1113,7 +1112,7 @@ def debugging(self): :rtype: ``bool`` """ - return self.alfred_env.get('debug') == '1' + return self.alfred_env.get('debug') == 1 @property def name(self):