📜 ⬆️ ⬇️

A simple reminder for Linux



For people who work in the office with a personal computer - accountants, engineers, secretaries, managers, specialists, experts, heads of departments, and especially directors - today it is common to accompany the solution of several issues simultaneously.

For example, a customer calls and asks for changes to the contract. You put the phone down - and then your colleague calls and asks you to send him a long-forgotten material that you need to try to find. You do not have time to negotiate with a colleague how he calls the cellular director and asks for a small report. But before that you dealt with your question! You need to remember everything, do not miss anything! Typical situation, isn't it?

In order to do everything in such situations, a simple reminder will help. But what is a simple reminder? What are the criteria for its simplicity?
For me, a “simple reminder” is one that acts according to the following principle:


')
The best, I think, the solution to this problem is the program XMinder . Probably, if I wrote a technical task for the development of a simple reminder, it would look exactly like XMinder.
I used this program for a long time, until one day I decided to install a Linux operating system on my work computer (unfortunately, the XMinder program was written only under Windows).

The loss of such a wonderful reminder was significant, it was necessary to find a way out and ... I decided to write the program myself.

Earlier I had a little experience writing programs in html, php, actionscript (flash) . However, for this task I decided to choose a bundle of Python + Bash + Zenity + At.
Why python? “Because good documentation was found on it, because by default it is installed in my Linux Mint 17 distribution kit. After the first steps of mastering a new language, I understood that I would be able to solve the problem.
Why bash? - This is a separate story and it is connected with the function “Postpone” in my reminder.
Why Zenity? - Because it is simple, concise and again - built in by default in most LInux distributions.
Why At? - So in fact this program solves the whole problem! And it can store data even after rebooting the computer!

Thus, I just put together a couple of programs and added the necessary syntax.
In the end, I got 2 files:

remind.py:

#!/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() 


and task:
 #!/bin/bash zenity --question --title= --ok-label= --cancel-label=Ok --text="$*" case $? in 0) ~/remindme/remind.py " 15 " "$*" ;; 1) ;; esac 


Files need to be put in one directory (I have ~ / remindme) and made executable (for example, using the “chmod + x” command).
On the remind.py file, you must assign hot keys (in different distributions this is done differently), for example, the key combination Ctrl + Shift + X.

Files for download are available here .
The project is posted on GitHub .

Source: https://habr.com/ru/post/240245/


All Articles