Skip to content

Commit

Permalink
Complete rewrite and new options
Browse files Browse the repository at this point in the history
  • Loading branch information
biati-digital committed May 18, 2020
1 parent 91a67e2 commit d5e6b9d
Show file tree
Hide file tree
Showing 151 changed files with 4,617 additions and 3,005 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ $RECYCLE.BIN/
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

calculate-anything.zip
vendor
vendor
flags/.DS_Store
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 biati digital
Copyright (c) 2020 biati digital

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
46 changes: 41 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ There are several workflows out there but i just needed a workflow that worked n

- **Natural language** - type 100 euros to dollars or 100 euros in usd or 100€ to $ or 100eur usd or 100 euros a dolares. It does not matter, the same result will be displayed.
- **Currency** - Up to 168 currencies
- **Cryptocurrency** - Support for 100 cryptocurrencies
- **Units** - 100 kilometers to meters or 100 km to m or simply 100km m
- **Percentages** - 100 + 16% | 100 - 16% etc.
- **PX,Em,Rem,Pt** - 12px or 12px to em or 12px pt
Expand Down Expand Up @@ -47,7 +48,7 @@ You can use natural language or type a few characters and that's all, for exampl
- 100 usd in mxn
- 100 usd yen
- 100usd eur
- 100eur (If no target the currency will be converted to the base currency that you configured)
- 100eur (If no target the currency will be converted to the base currencies that you configured)
```

All this examples will simply work, you can add spaces between the value and the currency or don't.
Expand All @@ -61,8 +62,10 @@ By default the workflow will use exchangerates api to make the conversion, excha

The following options are available for the currency. Simply launch Alfred and type **calculate configure** and select any of the options below. [View the configuration section for more info](#configuration)

- **Set base currency**
This will become your base currency, if you type 100eur it will automatically be converted to mxn, examples of currency (USD, EUR, MXN, CAD, etc)
- **Add base currency**
This will become your base currency, if you type 100eur it will automatically be converted to the currencies you define here. You can enter multiple currencies at once separated by comma for example: USD, EUR, MXN
- **Delete base currency**
If you no longer want a base currency you can select this option to list all configured base currencies, you can delete a currency by simply presing enter
- **Set currency locale**
Used to give format to the converted amount using the money format of your contry
- **Set Fixer API**
Expand Down Expand Up @@ -112,6 +115,31 @@ TT$ | TTD | Trinidad and Tobago dollar
TT$ | TTD | Trinidad and Tobago dollar
₴ | UAH | Ukrainian hryvnia


## Cryptocurrency

You can use this in conjunction with currency to convert 100 cryptocurrencies to up to 168 currencies, again you can use natural language or simply pass the currency simbol and that's all.

```
- 2 bitcoin to dollars
- 0.1 bitcoin in dollars
- 5 bitcoins in ethereum
- 1 ethereum to ¥
- 10 ethereum in mxn
- 1eth btc
- 1btc (If no target the currency will be converted to the base currency that you configured)
```

### Cryptocurrency Options

You need to get a FREE API Key from [https://coinmarketcap.com/api/pricing/](https://coinmarketcap.com/api/pricing/) it takes less than a minute.

The following options are available for cryptocurrency. Simply launch Alfred and type **calculate configure** and select any of the options below. [View the configuration section for more info](#configuration)

- **Set Coinmarketcap API**
Select this option and paste your API key and press enter to save it.


## Units

You can write your query using natural language or just a few characters, either way this workflow will give you the result you need.
Expand Down Expand Up @@ -478,7 +506,9 @@ You can easily configure the workflow simply by opening Alfred and typing **calc

## Updates

Starting from version 1.0.5 automatic updates were implemente, you will be notified if a new update is available or if you prefer you can launch Alfred and type **calculate update** to check for updates.
~~Starting from version 1.0.5 automatic updates were implemente, you will be notified if a new update is available or if you prefer you can launch Alfred and type **calculate update** to check for updates.~~

Starting from version 1.0.8 there's a new way to search and install automatic updates, before it was necessary to press enter when you used "Calculate Anything" and it will trigger the updater but the "Enter" key is not regularly used as this workflow does not depends on this key for the queries so you'll probably ended up with an outdated version. If you want you can still use **calculate update** to check for updates but it's not necessary anymore, the workflow will do it automatically for you.

## Performance

Expand All @@ -490,10 +520,16 @@ This workflow could not be possible without:

- [Convertor](https://github.com/olifolkerd/convertor) with some modifications
- [currency-converter-php](https://github.com/ojhaujjwal/currency-converter-php) for ExchangeRatesIo
- [OneUpdater](https://www.alfredforum.com/topic/9224-oneupdater-—-update-workflows-with-a-single-node/) Automatic updates for Alfred Workflows

## Changelog

### 2.0.0

- New: Complete rewrite to be more maintainable and extendable
- New: Added cryptocurrencies support
- New: Display exchange rate conversions in multiple currencies at once
- New: Added new workflow updater

### 1.0.7

- Fixed a bug where some configuration was saves in lowercase causing some problems with dates and currency formatting
Expand Down
35 changes: 31 additions & 4 deletions actions.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

/**
* Actions
* This file handles
* saving the workflow
* configuration
*/

require __DIR__ . '/functions.php';
$settings = get_settings();
require __DIR__ . '/workflow/lib/functions.php';
$settings = getSettings();

$param = getenv('configure_key');
$value = getenv('configure_val');
Expand All @@ -16,10 +17,36 @@
die();
}

// Handle currencies
if (!isset($settings['base_currency'])) {
$settings['base_currency'] = [];
} elseif (is_string($settings['base_currency'])) {
// convert all setting to array
$settings['base_currency'] = [$settings['base_currency']];
}
if ($param == 'add_base_currency' || $param == 'delete_base_currency') {
if ($param == 'add_base_currency') {
$value = str_replace(' ', '', $value);
$value = strtoupper($value);
$value = trim($value);
$value = explode(',', $value);
$newcurrencies = array_mege($settings['base_currency'], $value);
$settings['base_currency'] = array_unique($newcurrencies);
}
if ($param == 'delete_base_currency') {
if (isset($settings['base_currency'][$value])) {
unset($settings['base_currency'][$value]);
}
}

$value = $settings['base_currency'];
$param = 'base_currency';
}

// Handle timezones
if (!isset($settings['timezones'])) {
$settings['timezones'] = [];
}

if ($param == 'add_time_zone' || $param == 'delete_time_zone') {
if ($param == 'add_time_zone') {
$settings['timezones'][] = $value;
Expand All @@ -35,5 +62,5 @@
}

$settings[$param] = $value;
save_settings($settings);
saveSettings($settings);
echo "Value saved: $param";
Loading

0 comments on commit d5e6b9d

Please sign in to comment.