all repos — dotfiles @ cf2ec2fc9f34434ea780f4c6357bb38a4071a028

linux dotfiles

scripts/pd

#!/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 'rclone' to sync the journal to my dropbox
# the script first fetches any changes done to the pd.txt file
# and then appends the entry and uploads it.
# I use this for my journal.

import os
import datetime
import tempfile


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


entry = None
with tempfile.NamedTemporaryFile(suffix='.pdtemp') as temp:
    command = "vim {}".format(temp.name)
    os.system(command)
    entry = open(temp.name, 'r').read()
    if entry == '':
        print("Nothing was entered...")
        exit()
        
print("Fetching changes...")
if not os.system('rclone sync drop:/pd/ ~/Dropbox/pd/'):
    print("Done")
else:
    print("Something went wrong")

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)

print("Pushing changes...")
if not os.system('rclone sync ~/Dropbox/pd/ drop:/pd/'):
    print("Done")
else:
    print("Something went wrong")