-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyOneNoteJournal.py
More file actions
66 lines (49 loc) · 2.36 KB
/
pyOneNoteJournal.py
File metadata and controls
66 lines (49 loc) · 2.36 KB
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
import onepy
import datetime
from sys import exit
def find_journal_notebook():
"""Look for a suitable notebook to use.
We guess it's named 'work' or 'journal'"""
notebook_name_guesses = ('work', 'journal') # keep these lowercase since we convert to lowercase to match
notebooks = onepy.getNotebooks()
chosen_notebook_id = None
for notebook in notebooks:
if notebook['name'].lower() in notebook_name_guesses or notebook['nickname'] in notebook_name_guesses:
chosen_notebook_id = notebook['ID']
break
if chosen_notebook_id is None:
return None
return chosen_notebook_id
def get_today():
"""Get date fields necessary"""
today = datetime.date.today()
return today.year, today.strftime('%B'), today.day, today.isoformat()
def create_year_section(journal_group_element, year):
#TODO use UpdateHierarchy method (ew)
pass
def section_exists(journal_group_element, section_name):
"""Ensure the section exists within the given element"""
is_exists = False
for section in journal_group_element:
if section.attrib.get('name') == str(section_name):
is_exists = True
return is_exists
def main():
#Final structure should look like this
#Work(or Journal) notebook -- 'Journal' section group -- YYYY section group -- MonthWord Section -- Date Page
target_notebook_id = find_journal_notebook()
target_journal_section_id, target_journal_section = onepy.getSectionByName(target_notebook_id, 'Journal', 'sectiongroup')
# Store some date related values we're gonna need
year, month_word, day, iso_format_date = get_today()
assert section_exists(target_journal_section, year), "No section group found for current year: %s" % year
year_section_id, year_section = onepy.getSectionByName(target_journal_section_id, str(year), 'sectiongroup')
assert section_exists(year_section, month_word), "No section group found for current month: %s" % month_word
month_section_id, month_section = onepy.getSectionByName(year_section_id, month_word, 'section')
month_pages = onepy.getPages(month_section)
for page in month_pages:
if page['name'] == iso_format_date:
print 'Page named "%s" already exists' % iso_format_date
exit()
onepy.createNewPage(month_section_id, iso_format_date)
if __name__ == '__main__':
main()