Advertisement
smeech

Espanso trigger to output time and date in another timezone

Dec 27th, 2024 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.20 KB | Software | 0 0
  1. # Espanso trigger to output time and date in another timezone
  2. # Requires Python and its pytz library
  3.  
  4. matches:
  5.   - trigger: :tzdate
  6.     replace: '{{output}}'
  7.     vars:
  8.       - name: zones
  9.         type: script
  10.         params:
  11.           args:
  12.            - python
  13.             - -c
  14.             - |
  15.              import pytz
  16.               print("\n".join(pytz.all_timezones))
  17.       - name: zone_choice
  18.         type: form
  19.         params:
  20.           layout: 'Pick a time-zone: [[zone]]'
  21.           fields:
  22.             zone:
  23.               type: list
  24.               values: '{{zones}}'
  25.               default: Europe/London
  26.       - name: output
  27.         type: script
  28.         params:
  29.           args:
  30.            - python
  31.             - -c
  32.             - |
  33.              import pytz; from datetime import datetime
  34.               timezone = pytz.timezone('{{zone_choice.zone}}')
  35.               # Get the current date and time in UTC
  36.               utc_now = datetime.utcnow().replace(tzinfo=pytz.utc)
  37.               # Convert UTC time to the specified timezone
  38.               local_time = utc_now.astimezone(timezone)
  39.               print("Current date and time in", timezone, "is:", local_time.strftime('%F %T'))
Tags: espanso
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement