scripts/pd
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
35
36
37
38
39
40
41
42
43
44
45
#!/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")