1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-11-16 14:58:08 +00:00
qownnotes-scripts/merge-notes/merge.py

35 lines
1.1 KiB
Python
Raw Normal View History

2017-08-17 18:29:11 +00:00
#!/usr/bin/env python
import os
import sys
2017-08-18 07:37:11 +00:00
import time
2017-08-17 18:29:11 +00:00
merge_to_first = sys.argv[1]
delete_merged = sys.argv[2]
note_list = sys.argv[3].split('//>')
note_content_list = []
for note_path in note_list:
with open(note_path, 'r') as note:
note_content_list.append(note.read())
if merge_to_first == 'true':
output_path = note_list.pop(0)
else:
output_path = "{}{} notes starting with '{}'{}".format(os.path.dirname(note_list[0]) + os.sep,
len(note_list),
os.path.splitext(os.path.basename(note_list[0]))[0],
os.path.splitext(note_list[0])[1])
2017-08-18 07:37:11 +00:00
if os.path.isfile(output_path):
output_path = os.path.splitext(output_path)[0] + '_' + str(int(time.time())) + os.path.splitext(note_list[0])[1]
2017-08-17 18:29:11 +00:00
try:
with open(output_path, 'w') as output:
output.write('\n\n'.join(note_content_list))
except:
pass
else:
if delete_merged == 'true':
for note_path in note_list:
2017-08-18 07:37:11 +00:00
os.remove(note_path)