-
Notifications
You must be signed in to change notification settings - Fork 7
/
notebook_item.py
87 lines (72 loc) · 2.75 KB
/
notebook_item.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import re
import os
ONENOTE_USER_INFO_CACHE = "~/Library/Containers/com.microsoft.onenote.mac/" \
"Data/Library/Application Support/Microsoft/UserInfoCache/"
ONENOTE_USER_UID = None
ICON_PAGE = 'icons/page.png'
ICON_SECTION = 'icons/section.png'
ICON_NOTEBOOK = 'icons/notebook.png'
ICON_SECTION_GROUP = 'icons/sectiongroup.png'
class NotebookItem:
def __init__(self, row):
self.Type = row[str('Type')]
self.GOID = row[str('GOID')]
self.GUID = row[str('GUID')]
self.GOSID = row[str('GOSID')]
self.ParentGOID = row[str('ParentGOID')]
self.GrandparentGOIDs = row[str('GrandparentGOIDs')]
self.ContentRID = row[str('ContentRID')]
self.RootRevGenCount = row[str('RootRevGenCount')]
self.LastModifiedTime = row[str('LastModifiedTime')]
self.RecentTime = row[str('RecentTime')]
self.PinTime = row[str('PinTime')]
self.Color = row[str('Color')]
self.Title = row[str('Title')]
self.last_grandparent = self.GrandparentGOIDs
self.path = None
self.icon = None
self.url = None
self.set_last_grandparent()
self.set_url()
self.set_icon()
def has_parent(self):
return self.ParentGOID is not None
def has_grandparent(self):
return self.GrandparentGOIDs is not None
def set_last_grandparent(self):
if self.has_grandparent():
if len(self.GrandparentGOIDs) > 50:
grandparents = self.split_grandparents()
self.last_grandparent = grandparents[-1]
def split_grandparents(self):
new_ids = []
items = self.GrandparentGOIDs.split('}')
for i in range(len(items) - 1):
if i % 2 == 0:
new_ids.append("{0}}}{1}}}".format(items[i], items[i + 1]))
i += 1
return new_ids
def set_path(self, path):
self.path = path.replace('.one#', '/')
def set_icon(self):
if self.Type == 4:
self.icon = ICON_NOTEBOOK
elif self.Type == 3:
self.icon = ICON_SECTION_GROUP
elif self.Type == 2:
self.icon = ICON_SECTION
else:
self.icon = ICON_PAGE
def set_url(self):
if self.Type == 4:
self.url = 'onenote:https://d.docs.live.net/{0}/Documents/{1}'.format(get_user_uid(), self.Title)
else:
self.url = 'onenote:#page-id={0}&end'.format(self.GUID)
def get_user_uid():
global ONENOTE_USER_UID
if ONENOTE_USER_UID is None:
files = os.listdir(os.path.expanduser(ONENOTE_USER_INFO_CACHE))
for f in files:
if 'LiveId.db' in f:
ONENOTE_USER_UID = re.search('(.*)_LiveId\\.db', f).group(1)
return ONENOTE_USER_UID