Skip to content

Instantly share code, notes, and snippets.

@toomore
Created September 9, 2011 10:30
Show Gist options
  • Save toomore/1205910 to your computer and use it in GitHub Desktop.
Save toomore/1205910 to your computer and use it in GitHub Desktop.
退伍倒數的進化板!在 notify 顯示!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
try:
import gtk, pygtk, os, os.path, pynotify
pygtk.require('2.0')
except:
print "Error: need python-notify, python-gtk2 and gtk"
from datetime import datetime
from datetime import timedelta
intime = datetime(2011,02,15) # 入伍時間
outtime = datetime(2012,01,16) # 退伍時間
def cd(d):
''' 倒數天數 '''
tod = outtime - timedelta(d)
tods = tod - datetime.today()
return (tod.date(),tods.days)
alldays = outtime- intime
TEXT = "- 今天是:%s\r\n" % datetime.today()
TEXT += "- 退伍倒數:%s 天\r\n" % (outtime-datetime.now()).days
TEXT += "- 役期天數:%s 天\r\n" % alldays.days
TEXT += "- 行程:%.2f%%\r\n" % float(float((datetime.now()-intime).days)/alldays.days*100)
TEXT += "- 100 日:%s (距離 100 日:%3s 天)\r\n" % cd(100)
TEXT += "- 050 日:%s (距離 050 日:%3s 天)\r\n" % cd(50)
TEXT += "- 025 日:%s (距離 025 日:%3s 天)\r\n" % cd(25)
TEXT += "- 010 日:%s (距離 010 日:%3s 天)\r\n" % cd(10)
TEXT += "- 005 日:%s (距離 005 日:%3s 天)" % cd(5)
if __name__ == '__main__':
if not pynotify.init("Timekpr notification"):
sys.exit(1)
n = pynotify.Notification("Toomore 退伍倒數計時!!",TEXT)
#n = pynotify.Notification("Moo title", "test", "file:///path/to/icon.png")
n.set_urgency(pynotify.URGENCY_CRITICAL)
n.set_timeout(10000) # 10 seconds
n.set_category("device")
#Call an icon
helper = gtk.Button()
icon = helper.render_icon(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG)
n.set_icon_from_pixbuf(icon)
if not n.show():
print "Failed to send notification"
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment