Created
March 4, 2020 17:28
-
-
Save cdw9/02721aab6c2aa7c04d70e02f935abcd5 to your computer and use it in GitHub Desktop.
Mac daily reminder with Python, Arrow, and a cronjob!
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
1. Install terminal-notifier: https://github.com/julienXX/terminal-notifier | |
2. Create a virtualenv | |
3. pip install arrow | |
4. test code with `env/bin/python daily-notify.py` | |
5. Set up the cronjob | |
6. If you want the notifications to be sticky, go to System Preferences > Notifications, and make sure terminal-notifier notifications display as Alerts |
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
# daily reminder at 9am, with full path to virtualenv python and script | |
0 9 * * * /Users/chrissy/projects/scripts/env/bin/python /Users/chrissy/projects/scripts/daily-notify.py |
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
import arrow | |
import os | |
end_date = '2020-04-01' | |
def notify(title='Notification', subtitle='', message='Alert message here'): | |
t = '-title {!r}'.format(title) | |
s = '-subtitle {!r}'.format(subtitle) | |
m = '-message {!r}'.format(message) | |
msg = ' '.join([m, t, s]) | |
os.system(f'/usr/local/bin/terminal-notifier {msg}') | |
end_date_arrow = arrow.get(end_date) | |
remain = (end_date_arrow - arrow.now()).days | |
topic = 'figure out an April Fool\'s Prank' | |
if remain > 2: | |
notify(title='Reminder!', | |
message=f'You have {remain} days to {topic}') | |
elif remain > -1: | |
notify(title='WARNING!', | |
message=f'You have {remain} days to {topic}') | |
else: | |
notify(title='****OVERDUE****', | |
message=f'You have {remain} days to {topic}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment