Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 243 additions & 0 deletions contrib/ExchangeRate.popclipext/Config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
{
"name": "Exchange Rate",
"icon": "circle $\u20ac\u00a5",
"identifier": "com.oxxie.popclipextensions.exchangerate",
"description": "Shows monetary amount in preferred currencies.",
"options": [
{
"identifier": "target_AUD",
"type": "boolean",
"label": "AUD Australian Dollar",
"defaultValue": false
},
{
"identifier": "target_BGN",
"type": "boolean",
"label": "BGN Bulgarian Lev",
"defaultValue": false
},
{
"identifier": "target_BRL",
"type": "boolean",
"label": "BRL Brazilian Real",
"defaultValue": false
},
{
"identifier": "target_CAD",
"type": "boolean",
"label": "CAD Canadian Dollar",
"defaultValue": false
},
{
"identifier": "target_CHF",
"type": "boolean",
"label": "CHF Swiss Franc",
"defaultValue": false
},
{
"identifier": "target_CNY",
"type": "boolean",
"label": "CNY Chinese Renminbi Yuan",
"defaultValue": false
},
{
"identifier": "target_CZK",
"type": "boolean",
"label": "CZK Czech Koruna",
"defaultValue": false
},
{
"identifier": "target_DKK",
"type": "boolean",
"label": "DKK Danish Krone",
"defaultValue": false
},
{
"identifier": "target_EUR",
"type": "boolean",
"label": "EUR Euro",
"defaultValue": false
},
{
"identifier": "target_GBP",
"type": "boolean",
"label": "GBP British Pound",
"defaultValue": false
},
{
"identifier": "target_HKD",
"type": "boolean",
"label": "HKD Hong Kong Dollar",
"defaultValue": false
},
{
"identifier": "target_HUF",
"type": "boolean",
"label": "HUF Hungarian Forint",
"defaultValue": false
},
{
"identifier": "target_IDR",
"type": "boolean",
"label": "IDR Indonesian Rupiah",
"defaultValue": false
},
{
"identifier": "target_ILS",
"type": "boolean",
"label": "ILS Israeli New Sheqel",
"defaultValue": false
},
{
"identifier": "target_INR",
"type": "boolean",
"label": "INR Indian Rupee",
"defaultValue": false
},
{
"identifier": "target_ISK",
"type": "boolean",
"label": "ISK Icelandic Kr\u00f3na",
"defaultValue": false
},
{
"identifier": "target_JPY",
"type": "boolean",
"label": "JPY Japanese Yen",
"defaultValue": false
},
{
"identifier": "target_KRW",
"type": "boolean",
"label": "KRW South Korean Won",
"defaultValue": false
},
{
"identifier": "target_MXN",
"type": "boolean",
"label": "MXN Mexican Peso",
"defaultValue": false
},
{
"identifier": "target_MYR",
"type": "boolean",
"label": "MYR Malaysian Ringgit",
"defaultValue": false
},
{
"identifier": "target_NOK",
"type": "boolean",
"label": "NOK Norwegian Krone",
"defaultValue": false
},
{
"identifier": "target_NZD",
"type": "boolean",
"label": "NZD New Zealand Dollar",
"defaultValue": false
},
{
"identifier": "target_PHP",
"type": "boolean",
"label": "PHP Philippine Peso",
"defaultValue": false
},
{
"identifier": "target_PLN",
"type": "boolean",
"label": "PLN Polish Z\u0142oty",
"defaultValue": false
},
{
"identifier": "target_RON",
"type": "boolean",
"label": "RON Romanian Leu",
"defaultValue": false
},
{
"identifier": "target_SEK",
"type": "boolean",
"label": "SEK Swedish Krona",
"defaultValue": false
},
{
"identifier": "target_SGD",
"type": "boolean",
"label": "SGD Singapore Dollar",
"defaultValue": false
},
{
"identifier": "target_THB",
"type": "boolean",
"label": "THB Thai Baht",
"defaultValue": false
},
{
"identifier": "target_TRY",
"type": "boolean",
"label": "TRY Turkish Lira",
"defaultValue": false
},
{
"identifier": "target_USD",
"type": "boolean",
"label": "USD United States Dollar",
"defaultValue": false
},
{
"identifier": "target_ZAR",
"type": "boolean",
"label": "ZAR South African Rand",
"defaultValue": false
}
],
"optionsTitle": "Exchange Rate shows monetary amount in preferred currencies.\n\nSelect currencies to show monetary amount in:",
"action": {
"regex": "^(MXN|DKK|US\\$|EUR|NOK|CNY|ISK|MYR|\u00a5|HKD|ILS|ZAR|\u20ac|SGD|TRY|CAD|INR|\u00a3|PHP|BGN|KRW|BRL|SEK|\\$|JPY|RON|HUF|CZK|THB|NZD|USD|IDR|GBP|PLN|AUD|CHF)\\s?(\\d{1,3}([\\.,]?\\d{3})*([\\.,]\\d{2})?)$",
"after": "preview-result",
"app": {
"name": "Frankfurter",
"link": "https://frankfurter.dev"
},
"shellScriptFile": "exchangerate.py",
"interpreter": "/usr/bin/python3"
},
"supported_symbols": {
"MXN": "MXN",
"DKK": "DKK",
"US$": "USD",
"EUR": "EUR",
"NOK": "NOK",
"CNY": "CNY",
"ISK": "ISK",
"MYR": "MYR",
"\u00a5": "JPY",
"HKD": "HKD",
"ILS": "ILS",
"ZAR": "ZAR",
"\u20ac": "EUR",
"SGD": "SGD",
"TRY": "TRY",
"CAD": "CAD",
"INR": "INR",
"\u00a3": "GBP",
"PHP": "PHP",
"BGN": "BGN",
"KRW": "KRW",
"BRL": "BRL",
"SEK": "SEK",
"$": "USD",
"JPY": "JPY",
"RON": "RON",
"HUF": "HUF",
"CZK": "CZK",
"THB": "THB",
"NZD": "NZD",
"USD": "USD",
"IDR": "IDR",
"GBP": "GBP",
"PLN": "PLN",
"AUD": "AUD",
"CHF": "CHF"
}
}
21 changes: 21 additions & 0 deletions contrib/ExchangeRate.popclipext/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 oxxie

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
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.
15 changes: 15 additions & 0 deletions contrib/ExchangeRate.popclipext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Exchange Rate
A PopClip extension for converting monetary amounts to multiple preferred currencies using recent exchange rates.

## Usage
Simplicty is King:
1. Select a text consisting of a currency symbol and an amount
2. Hit the Exchange Rate icon

_Please note: this extension requires a working internet connection._

## Credits
Makes use of the free [Frankfurter](https://frankfurter.dev) API. All kudos go out to them!

## License
All source code is published under the [MIT License](LICENSE.txt).
41 changes: 41 additions & 0 deletions contrib/ExchangeRate.popclipext/exchangerate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import json
import os
import re
import sys
from typing import Any
import urllib.request

with open(os.path.dirname(__file__) + "/Config.json") as f:
config: Any = json.load(f)

text: str = os.environ["POPCLIP_TEXT"]
# text: str = "EUR 12.345,67" # Test input.
tokens: list[str] = re.split(config["action"]["regex"], text)
symbol: str = config["supported_symbols"][tokens[1]]
amount: str = tokens[2]

if re.match(r"^\d{1,3}(,\d{3})*(\.\d{2})?$", amount):
amount = amount.replace(",", "")
elif re.match(r"^\d{1,3}(\.\d{3})*(,\d{2})?$", amount):
amount = amount.replace(".", "").replace(",", ".")

target_symbols: list[str] = sorted(
s
for s in set(config["supported_symbols"].values())
if os.environ[f"POPCLIP_OPTION_TARGET_{s}"] == "1" and s != symbol
)

if not target_symbols:
quit(2) # Error code 2 invokes extension preferences panel.

with urllib.request.urlopen(
f"https://api.frankfurter.dev/v1/latest?base={symbol}&symbols="
+ ",".join(target_symbols)
) as r:
response: Any = json.load(r)

output: str = ", ".join(
sorted(f"{s} {float(amount) * response['rates'][s]:.2f}" for s in target_symbols)
)

sys.stdout.write(output)