all repos — dotfiles @ 5339ca6e4eeca001203ad3430ad88c5ad26e842d

linux dotfiles

scripts/pd (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
#!/usr/bin/env python3
# This script opens a temp file in a vim buffer and after wrting and quiting from vim, it writes the contents to the file
# specified by the file_path with a date and timestamp.
# I use this for my journal.

import os
import datetime
import sys
import tempfile
import subprocess, shlex


file_path = r'/home/prithu/Dropbox/Tasker/pd.txt'


entry = None
with tempfile.NamedTemporaryFile(suffix='.pdtemp') as temp:
    command = "vim {}".format(temp.name)
    subprocess.run(shlex.split(command))
    entry = open(temp.name, 'r').read()
    if entry == '':
        print("Nothing was entered...")
        exit()
        
with open(file_path, 'a', encoding='utf8') as fp:
    dt = datetime.datetime.now()
    date_string = dt.strftime('%a, %d %b %Y')
    time_string = dt.strftime('%I:%M %p')
    date_and_time = '[' + date_string + ' | ' + time_string + ']'

    fp.write('\n\n\n===============================\n' + date_and_time + '\n')
    fp.write(entry)

subprocess.run(['dropbox', 'start'])