Last active
March 22, 2020 18:48
-
-
Save miratcan/fc3badeb3a7c121f6256739a0ad5c2e3 to your computer and use it in GitHub Desktop.
logme: Simplest diary program written in python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""logme: Simplest diary program""" | |
__author__ = "Mirat Can Bayrak" | |
__copyright__ = "Copyright 2016, Planet Earth" | |
from datetime import datetime | |
from os import mkdir | |
from os.path import expanduser, join, exists | |
from sys import argv | |
DAY_FILE_PATTERN = '%Y-%m-%d.txt' | |
DAY_TITLE_PATTERN = '%Y/%m/%d/ - %A\n' | |
LOG_DIR = join(expanduser('~'), '.logme') | |
if not exists(LOG_DIR): | |
mkdir(LOG_DIR) | |
now = datetime.now() | |
file_name = datetime.strftime(now, DAY_FILE_PATTERN) | |
file_path = join(LOG_DIR, file_name) | |
if not exists(file_path): | |
fp = open(file_path, 'w') | |
title = datetime.strftime(now, DAY_TITLE_PATTERN) | |
fp.write(title) | |
fp.write('-' * (len(title) - 1) + '\n') | |
else: | |
fp = open(file_path, 'a') | |
if len(argv) > 1: | |
note = ' '.join(argv[1:]) | |
timestamp = now.strftime("%H:%M") | |
fp.write('%s: %s\n' % (timestamp, note)) | |
fp.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@miratcan bu yazdığımız komutlar bash_history'e kaydediliyordur diye düşünüyorum? eğer öyleyse, bash_history den silen fonksiyonu da yazsan ne hoş olur.