Advertisement
smeech

Temperature C/°F conversion

Jun 22nd, 2024 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 0.84 KB | None | 0 0
  1. # Espanso temperature C/°F conversion
  2. # From conversation at: https://discord.com/channels/884163483409731584/1013914627886817372/1253000300730515508
  3. # Usage: ::10C → 10C / 50.00°F or ::10F → 10°F / -12.22C
  4.  
  5.   - regex: ::(?P<value>\d+)(?P<unit>[C,F])
  6.     replace: "{{output}}"
  7.     vars:
  8.       - name: output
  9.         type: script
  10.         params:
  11.           args:
  12.            - python
  13.             - -c
  14.             - |
  15.              import sys
  16.               sys.stdout.reconfigure(encoding='utf-8') # May be necessary if "°" doesn't render
  17.               if "{{unit}}" == "C":
  18.                   conv_value = {{value}} * 9 / 5 + 32
  19.                   print(f"{{{value}}}C / {conv_value:.2f}°F")
  20.               else:
  21.                   conv_value = ({{value}} - 32) * 5 / 9
  22.                   print(f"{{{value}}}°F / {conv_value:.2f}C")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement