Last active
February 18, 2025 15:07
-
-
Save smeech/632a50aece7c75eb48cb0eaa488532b9 to your computer and use it in GitHub Desktop.
[Temperature C/°F conversion] Espanso temperature C/°F conversion. From conversation at: https://discord.com/channels/884163483409731584/1013914627886817372/1253000300730515508. Usage: ::10C → 10C / 50.00°F or ::10F → 10°F / -12.22C #espanso #python #regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Espanso temperature C/°F conversion | |
| # From conversation at: https://discord.com/channels/884163483409731584/1013914627886817372/1253000300730515508 | |
| # Usage: ::10C → 10C / 50.00°F, or ::10F → 10°F / -12.22C | |
| matches: | |
| - regex: ::(?P<value>\d+(?:\.\d+)?)(?P<unit>[CF]) | |
| replace: "{{output}}" | |
| vars: | |
| - name: output | |
| type: script | |
| params: | |
| args: | |
| - python | |
| - -c | |
| - | | |
| import sys | |
| sys.stdout.reconfigure(encoding='utf-8') # May be necessary if "°" doesn't render | |
| if "{{unit}}" == "C": | |
| print(f"{{value}}C / {{{value}} * 9 / 5 + 32:.2f}°F") | |
| else: | |
| conv_value = ({{value}} - 32) * 5 / 9 | |
| print(f"{{{value}}}°F / {({{value}} - 32) * 5 / 9:.2f}C") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment