Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Espanso trigger to output time and date in another timezone
- # Requires Python and its pytz library
- matches:
- - trigger: :tzdate
- replace: '{{output}}'
- vars:
- - name: zones
- type: script
- params:
- args:
- - python
- - -c
- - |
- import pytz
- print("\n".join(pytz.all_timezones))
- - name: zone_choice
- type: form
- params:
- layout: 'Pick a time-zone: [[zone]]'
- fields:
- zone:
- type: list
- values: '{{zones}}'
- default: Europe/London
- - name: output
- type: script
- params:
- args:
- - python
- - -c
- - |
- import pytz; from datetime import datetime
- timezone = pytz.timezone('{{zone_choice.zone}}')
- # Get the current date and time in UTC
- utc_now = datetime.utcnow().replace(tzinfo=pytz.utc)
- # Convert UTC time to the specified timezone
- local_time = utc_now.astimezone(timezone)
- print("Current date and time in", timezone, "is:", local_time.strftime('%F %T'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement