commit 867917f3300fe62522505f7c392ba52bda996c9b Author: Anton Vakhrushev Date: Sun Jul 10 16:34:37 2016 +0300 Init files diff --git a/README.md b/README.md new file mode 100644 index 0000000..db1645b --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Diary + +Simple diary based on files. Just run and write. + +One record for one day by default. + +Use `DIARY_ROOT_DIRECTORY` environment variable +to setup root directory for records. + +You can fork it and edit templates any way you like. diff --git a/diary.py b/diary.py new file mode 100755 index 0000000..080f6e7 --- /dev/null +++ b/diary.py @@ -0,0 +1,69 @@ +#!/usr/bin/python +# coding: utf-8 + +import datetime +import os +import subprocess +import sys + + +ROOR_DIRECTORY_ENV = 'DIARY_ROOT_DIRECTORY' + +ROOT_DIRECTORY_DEFAULT = '/home/av/Dropbox/Diary' + + +def main(): + root_directory = get_root_directory() + check_root_directory(root_directory) + filename = get_file_name() + full_path = os.path.join(root_directory, filename) + touch_file(full_path) + run_editor(full_path) + + +def get_root_directory(): + return os.getenv(ROOR_DIRECTORY_ENV, ROOT_DIRECTORY_DEFAULT) + + +def check_root_directory(root_directory): + if not os.path.exists(root_directory): + print 'Root directory "{}" does not exists'.format(root_directory) + sys.exit(1) + + +def get_file_name(): + today = datetime.date.today() + return '{:04}-{:02}-{:02}.md'.format(today.year, today.month, today.day) + + +def get_template(): + template = [ + '---', + 'Title: Запись {day}.{month}.{year}', + '---', + '', + '', + ] + today = datetime.date.today() + return '\n'.join(template).format(**{ + 'day': today.day, + 'month': today.month, + 'year': today.year, + }) + + +def touch_file(full_path): + if os.path.exists(full_path): + return + + template = get_template() + with open(full_path, 'w') as new_file: + new_file.write(template) + + +def run_editor(full_path): + subprocess.Popen(['subl', '--new-window', full_path]) + + +if __name__ == '__main__': + main()