-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes_recovery.py
70 lines (59 loc) · 2.47 KB
/
notes_recovery.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from pathlib import Path
import json
with open('init_data/data_for_recovery.json', encoding='utf8') as initialization_file:
initialization_data = json.load(initialization_file)
notes_data = Path().cwd() / initialization_data['boyeu_notes_folder'] / 'data'
note_pages = {}
for note_id in initialization_data['note_ids']:
png_files = notes_data.glob(f'noteid-{note_id}*.png')
note_pages[note_id] = [
png.name for png in png_files if not png.stem.endswith('note')
]
with open((notes_data / 'notes.xml'), encoding='UTF-8') as notes_database_file:
notes_database = notes_database_file.readlines()
all_known_notebook_lines = [
line for line in notes_database if '","noteName":"' in line
]
all_known_notebook_names = [
line[
line.find('","noteName":"')
+ len('","noteName":"') : line.find(
'","notebg"'
)
]
for line in all_known_notebook_lines
]
FAKE_EDIT_DATE = 1703486477983
note_pages['1698500249858'][0][note_pages['1698500249858'][0].find('-pageid-') + 1 : -4]
recovered_xml_lines = []
current_edit_data = FAKE_EDIT_DATE
for note_id, notes_pages in note_pages.items():
current_pages_xml_list = ''
for note_page_file_name in notes_pages:
current_pages_xml_list += '"'
current_page_id = note_page_file_name[
note_page_file_name.find('-pageid-') + 1 : -4
]
current_pages_xml_list += current_page_id + '",'
current_pages_xml_list = current_pages_xml_list[:-1]
current_edit_data += 1
recovered_xml_lines += [
'\t<string name="noteid-'
+ note_id
+ '">{"category":0,"createDate":1604595761039,"editDate":'
+ str(current_edit_data)
+ ',"noteId":"noteid-'
+ note_id
+ '","noteName":"'
+ initialization_data["note_ids"][note_id]
+ '","notebg":0,"notebgName":"White paper","pageIds":['
+ current_pages_xml_list
+ ']}</string>'
]
with (Path().cwd() / 'output/recovered_xml_lines.txt').open(
mode='w', encoding='UTF-8'
) as recovered_xml_lines_file:
print(*recovered_xml_lines, sep='\n', file=recovered_xml_lines_file)
print(
f"Data for notes' recovery is written to {Path('output/recovered_xml_lines.txt').resolve()}"
)