Created
January 31, 2020 01:50
-
-
Save velnias75/e27e45b04ce16ada1e1bc5bdeba94065 to your computer and use it in GitHub Desktop.
Time range script for use in KMail filters
This file contains 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
#!/usr/bin/python3 | |
# | |
# Copyright 2020 by Heiko Schäfer <[email protected]> | |
# | |
# | |
# Checks if a email date is *NOT* within a range of hours | |
# | |
# For usage in kmail filter, ex.: | |
# | |
# /path/to/isdaymail.py "%{date}" 18 4 && echo "Youtube announcement: %{subject}" | sed 's/Subject: //' | /usr/bin/espeak -s140 -a25 -b1 -k20 --stdin & | |
# | |
# Returns success for any email before 6 PM and after 4 AM local time | |
import sys | |
import time | |
import email.utils | |
__in = sys.argv[1] | |
__yt = email.utils.mktime_tz(email.utils.parsedate_tz(__in[7:-1])) | |
__lt = time.localtime(__yt) | |
__lh = __lt.tm_hour | |
if __lh >= int(sys.argv[2]) or __lh < int(sys.argv[3]): | |
sys.exit(1) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment