mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-23 00:18:10 +00:00
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
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])
|
|
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]
|
|
|
|
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:
|
|
os.remove(note_path)
|