raw = raw.replace('-', ' ') raw = raw.replace(':', ' ') return datetime.datetime.strptime(raw, '%H %M %d %m %Y') def add_notification(ses, title, text, raw_date): try: newnote = Notification(title, text, date_from_input(raw_date)) ses.add(newnote) ses.commit() return True except Exception as er: print('Exception!:\n%s' % str(er)) return False if __name__ == '__main__': ses, met, eng = get_sesnmetneng(pathtobd) if not os.path.exists(pathtobd): met.create_all(eng) if len(sys.argv) > 2: if sys.argv[1] == 'add': if len(sys.argv) < 4: print('Bad args!') exit() title = sys.argv[2] text = sys.argv[3] raw_date = " ".join(sys.argv[4:]) if add_notification(ses, title, text, raw_date): print('Nice :)') else: print('Something went wrong') print('Showing all notes...')
return datetime.datetime.strptime(raw, '%H %M %d %m %Y') def add_notification(ses, title, text, raw_date): try: newnote = Notification(title, text, date_from_input(raw_date)) ses.add(newnote) ses.commit() return True except Exception as er: print('Exception!:\n%s' % str(er)) return False if __name__ == '__main__': ses, met, eng = get_sesnmetneng(pathtobd) if not os.path.exists(pathtobd): met.create_all(eng) if len(sys.argv) > 2: if sys.argv[1] == 'add': if len(sys.argv) < 4: print('Bad args!') exit() title = sys.argv[2] text = sys.argv[3] raw_date = " ".join(sys.argv[4:]) if add_notification(ses, title, text, raw_date): print('Nice :)') else: print('Something went wrong') print('Showing all notes...')
import time import datetime from notimodel import Notification, get_sesnmetneng class NotifyDaemon(object): def __init__(self, dbses): self.dbses = dbses self.timeout = 5 def run(self): while True: now = datetime.datetime.now() cand_notes = self.dbses.query(Notification)\ .filter(Notification.dt < now).all() for note in cand_notes: if not note.has_shown: n = pynotify.Notification( 'NOTIFICATION\n%s' % note.title, '%s\nDate:%s' % (note.text, str(note.dt))) n.set_timeout(10000) n.show() note.has_shown = True self.dbses.commit() time.sleep(self.timeout) if __name__ == '__main__': pynotify.init('reminder') daemon = NotifyDaemon(get_sesnmetneng('reminder.db')[0]) daemon.run()
import datetime from notimodel import Notification, get_sesnmetneng class NotifyDaemon(object): def __init__(self, dbses): self.dbses = dbses self.timeout = 5 def run(self): while True: now = datetime.datetime.now() cand_notes = self.dbses.query(Notification)\ .filter(Notification.dt < now).all() for note in cand_notes: if not note.has_shown: n = pynotify.Notification( 'NOTIFICATION\n%s' % note.title, '%s\nDate:%s' % (note.text, str(note.dt))) n.set_timeout(10000) n.show() note.has_shown = True self.dbses.commit() time.sleep(self.timeout) if __name__ == '__main__': pynotify.init('reminder') daemon = NotifyDaemon(get_sesnmetneng('reminder.db')[0]) daemon.run()