#!/usr/bin/env python # -*- coding: utf-8 -*- # RemindMe v1.5 created by Dennis Smal' in 2014 godgrace@mail.ru from __future__ import print_function import subprocess import re import sys def replace_all(t, d): """ """ for i, j in d.iteritems(): t = t.replace(i, j, 1) return t def get_datex(text): """ , """ whatdate = '' delwhatdate = '' datex = re.findall(r'\d{2}[.,-]\d{2}[.,-]\d{4}|\d{1}[.,-]\d{2}[.,-]\d{4}',text) # 19.08.2014 19-08-2014 19,08,2014 if datex: date = datex[0].replace('-','.').replace(',','.') # 19.08.2014 whatdate = date delwhatdate = datex[0]+' ' return whatdate, delwhatdate def get_day(text): """ , """ when = '' delday = '' day = re.findall('|| | | | | | | ',text) daywithoutin = re.findall('||||||',text) if day: ind = {'':'tomorrow', '':'tomorrow', ' ':'mon', ' ':'tue', ' ':'wed', ' ':'thu', ' ':'fri', ' ':'sat', ' ':'sun'} when = replace_all(day[0], ind) delday = day[0]+' ' elif daywithoutin: ind = {'':'mon', '':'tue', '':'wed', '':'thu', '':'fri', '':'sat', '':'sun'} when = replace_all(daywithoutin[0], ind) delday = daywithoutin[0]+' ' return (when, delday) def get_clock(text): """ , """ how = '' delclock = '' clock = re.findall(' | | | | | | | | ',text) if clock: # , , , clockbank = {' ':'min', ' ':'hour', ' ':'days', ' ':'min', ' ':'hours', ' ':'days', ' ':'min', ' ':'hours', ' ':'days'} how = replace_all(clock[0], clockbank) delclock = clock[0] return (how, delclock) def add_task(out, x): """ at""" # , #x = 'at now' #print (x) cmd = 'echo "DISPLAY=:0 ~/remindme/task %s" | %s' % (out, x) subprocess.Popen(cmd, shell=True) def main(when=" 15 ", reminder=""): warn_cmd = [ 'zenity', '--warning', '--text=" .."' ] cmd = [ 'zenity', '--entry', '--title=', '--text= ', '--entry-text={} {}'.format(when, reminder), '--width=400' ] loop = True while loop: get = subprocess.check_output(cmd) # text = get+' ' # , " 10 ". , clock . clock "" , "" "". find = re.findall(' [0-9]+| [0-9:-]+| [0-9:-]+| ',text) if get: # , if find: # , what = find[0].split() timex = what[1].replace('-',':').replace('','1') if len(timex) > 2: # " 10" " 10:00" time = timex else: time = timex+':00' whatdate, delwhatdate = get_datex(text) when, delday = get_day(text) how, delclock = get_clock(text) reps = {'':'at now + %s %s' % (timex,how),'':'at %s %s %s' % (time,when,whatdate),'':'at %s %s %s' % (time,when,whatdate)} wors = {' %s %s' % (what[1],delclock):'',' %s %s' % (what[1],delclock):'',' %s ' % what[1]:'',' %s ' % what[1]:'', '%s' % delday:'', ' ':'', ' ':'', '%s' % delwhatdate:'',} # x = replace_all(what[0], reps) # , out = replace_all(text, wors) # add_task(out, x) loop = False else: error = subprocess.check_output(warn_cmd) else: loop = False def usage(): s = ": {} [ []]".format(__file__) print(s) if __name__ == "__main__": if len(sys.argv) <= 3: main(*sys.argv[1:]) else: usage()
#!/bin/bash zenity --question --title= --ok-label= --cancel-label=Ok --text="$*" case $? in 0) ~/remindme/remind.py " 15 " "$*" ;; 1) ;; esac
Source: https://habr.com/ru/post/240245/
All Articles