Skip to content

Instantly share code, notes, and snippets.

@aweffr
Last active June 29, 2021 02:10
Show Gist options
  • Save aweffr/494cca71cbb2967378fc19f6bcc906b3 to your computer and use it in GitHub Desktop.
Save aweffr/494cca71cbb2967378fc19f6bcc906b3 to your computer and use it in GitHub Desktop.
"""
Mac 喝水提示
crontab -e
*/30 8-22/1 * * * [your python] [script path]
- 8点到20点每半小时提示一次喝水
"""
import os
import time
number_map = ('十二', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一')
_time = time.localtime()
hour_idx = _time.tm_hour % 12
# https://stackoverflow.com/a/41318195
def notify(title, text):
os.system("""
osascript -e 'display notification "{}" with title "{}"'
""".format(text, title))
if __name__ == '__main__':
_title = "喂!喂!喂!"
if _time.tm_min < 30:
_msg = number_map[hour_idx] + "点啦!! 喝水先!!"
else:
_msg = number_map[hour_idx] + "点半啦!! 喝水先!!"
notify(_title, _msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment