notion-cascade-insert 0.0.5__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {notion_cascade_insert-0.0.5/notion_cascade_insert.egg-info → notion_cascade_insert-0.0.7}/PKG-INFO +1 -1
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert/__init__.py +1 -1
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert/_modidx.py +20 -19
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert/core.py +29 -13
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7/notion_cascade_insert.egg-info}/PKG-INFO +1 -1
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/settings.ini +1 -1
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/LICENSE +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/MANIFEST.in +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/README.md +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert/webhook.py +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert.egg-info/SOURCES.txt +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert.egg-info/dependency_links.txt +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert.egg-info/entry_points.txt +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert.egg-info/not-zip-safe +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert.egg-info/requires.txt +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert.egg-info/top_level.txt +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/pyproject.toml +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/setup.cfg +0 -0
- {notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/setup.py +0 -0
{notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert/_modidx.py
RENAMED
|
@@ -5,41 +5,42 @@ d = { 'settings': { 'branch': 'main',
|
|
|
5
5
|
'doc_host': 'https://amezaikupan.github.io',
|
|
6
6
|
'git_url': 'https://github.com/amezaikupan/notion_cascade_insert',
|
|
7
7
|
'lib_path': 'notion_cascade_insert'},
|
|
8
|
-
'syms': { 'notion_cascade_insert.core': { 'notion_cascade_insert.core.AutoLogger': ( '
|
|
8
|
+
'syms': { 'notion_cascade_insert.core': { 'notion_cascade_insert.core.AutoLogger': ( 'core_dup1.html#autologger',
|
|
9
9
|
'notion_cascade_insert/core.py'),
|
|
10
|
-
'notion_cascade_insert.core.AutoLogger.__init__': ( '
|
|
10
|
+
'notion_cascade_insert.core.AutoLogger.__init__': ( 'core_dup1.html#autologger.__init__',
|
|
11
11
|
'notion_cascade_insert/core.py'),
|
|
12
|
-
'notion_cascade_insert.core.AutoLogger.handle_update': ( '
|
|
12
|
+
'notion_cascade_insert.core.AutoLogger.handle_update': ( 'core_dup1.html#autologger.handle_update',
|
|
13
13
|
'notion_cascade_insert/core.py'),
|
|
14
|
-
'notion_cascade_insert.core.AutoLogger.process': ( '
|
|
14
|
+
'notion_cascade_insert.core.AutoLogger.process': ( 'core_dup1.html#autologger.process',
|
|
15
15
|
'notion_cascade_insert/core.py'),
|
|
16
|
-
'notion_cascade_insert.core.AutoLogger.undo_all': ( '
|
|
16
|
+
'notion_cascade_insert.core.AutoLogger.undo_all': ( 'core_dup1.html#autologger.undo_all',
|
|
17
17
|
'notion_cascade_insert/core.py'),
|
|
18
|
-
'notion_cascade_insert.core.Database': ('
|
|
19
|
-
|
|
18
|
+
'notion_cascade_insert.core.Database': ( 'core_dup1.html#database',
|
|
19
|
+
'notion_cascade_insert/core.py'),
|
|
20
|
+
'notion_cascade_insert.core.Database.__init__': ( 'core_dup1.html#database.__init__',
|
|
20
21
|
'notion_cascade_insert/core.py'),
|
|
21
|
-
'notion_cascade_insert.core.Database.check_db_exists': ( '
|
|
22
|
+
'notion_cascade_insert.core.Database.check_db_exists': ( 'core_dup1.html#database.check_db_exists',
|
|
22
23
|
'notion_cascade_insert/core.py'),
|
|
23
|
-
'notion_cascade_insert.core.Database.get_data_source_schema': ( '
|
|
24
|
+
'notion_cascade_insert.core.Database.get_data_source_schema': ( 'core_dup1.html#database.get_data_source_schema',
|
|
24
25
|
'notion_cascade_insert/core.py'),
|
|
25
|
-
'notion_cascade_insert.core.JunctionDB': ( '
|
|
26
|
+
'notion_cascade_insert.core.JunctionDB': ( 'core_dup1.html#junctiondb',
|
|
26
27
|
'notion_cascade_insert/core.py'),
|
|
27
|
-
'notion_cascade_insert.core.JunctionDB.__init__': ( '
|
|
28
|
+
'notion_cascade_insert.core.JunctionDB.__init__': ( 'core_dup1.html#junctiondb.__init__',
|
|
28
29
|
'notion_cascade_insert/core.py'),
|
|
29
|
-
'notion_cascade_insert.core.JunctionDB.get_items': ( '
|
|
30
|
+
'notion_cascade_insert.core.JunctionDB.get_items': ( 'core_dup1.html#junctiondb.get_items',
|
|
30
31
|
'notion_cascade_insert/core.py'),
|
|
31
|
-
'notion_cascade_insert.core.LogDB': ('
|
|
32
|
-
'notion_cascade_insert.core.LogDB.__init__': ( '
|
|
32
|
+
'notion_cascade_insert.core.LogDB': ('core_dup1.html#logdb', 'notion_cascade_insert/core.py'),
|
|
33
|
+
'notion_cascade_insert.core.LogDB.__init__': ( 'core_dup1.html#logdb.__init__',
|
|
33
34
|
'notion_cascade_insert/core.py'),
|
|
34
|
-
'notion_cascade_insert.core.LogDB.create_entry': ( '
|
|
35
|
+
'notion_cascade_insert.core.LogDB.create_entry': ( 'core_dup1.html#logdb.create_entry',
|
|
35
36
|
'notion_cascade_insert/core.py'),
|
|
36
|
-
'notion_cascade_insert.core.LogDB.get_entries_for_trigger': ( '
|
|
37
|
+
'notion_cascade_insert.core.LogDB.get_entries_for_trigger': ( 'core_dup1.html#logdb.get_entries_for_trigger',
|
|
37
38
|
'notion_cascade_insert/core.py'),
|
|
38
|
-
'notion_cascade_insert.core.TriggerDB': ( '
|
|
39
|
+
'notion_cascade_insert.core.TriggerDB': ( 'core_dup1.html#triggerdb',
|
|
39
40
|
'notion_cascade_insert/core.py'),
|
|
40
|
-
'notion_cascade_insert.core.TriggerDB.__init__': ( '
|
|
41
|
+
'notion_cascade_insert.core.TriggerDB.__init__': ( 'core_dup1.html#triggerdb.__init__',
|
|
41
42
|
'notion_cascade_insert/core.py'),
|
|
42
|
-
'notion_cascade_insert.core.TriggerDB.get_page_data': ( '
|
|
43
|
+
'notion_cascade_insert.core.TriggerDB.get_page_data': ( 'core_dup1.html#triggerdb.get_page_data',
|
|
43
44
|
'notion_cascade_insert/core.py')},
|
|
44
45
|
'notion_cascade_insert.webhook': { 'notion_cascade_insert.webhook.NotionWebhook': ( 'webhook.html#notionwebhook',
|
|
45
46
|
'notion_cascade_insert/webhook.py'),
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"""Notion Automation for multiple page creation"""
|
|
2
2
|
|
|
3
|
-
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/
|
|
3
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core_dup1.ipynb.
|
|
4
4
|
|
|
5
5
|
# %% auto #0
|
|
6
6
|
__all__ = ['Database', 'TriggerDB', 'JunctionDB', 'LogDB', 'AutoLogger']
|
|
7
7
|
|
|
8
|
-
# %% ../nbs/
|
|
8
|
+
# %% ../nbs/00_core_dup1.ipynb #6211d16e
|
|
9
9
|
from fastcore.basics import patch
|
|
10
10
|
|
|
11
|
-
# %% ../nbs/
|
|
11
|
+
# %% ../nbs/00_core_dup1.ipynb #68712bbc
|
|
12
12
|
class Database:
|
|
13
13
|
"""Base class for interacting with a Notion database."""
|
|
14
14
|
def __init__(self,
|
|
@@ -40,7 +40,7 @@ class Database:
|
|
|
40
40
|
print(f"✗ Database not found: {e}")
|
|
41
41
|
return False
|
|
42
42
|
|
|
43
|
-
# %% ../nbs/
|
|
43
|
+
# %% ../nbs/00_core_dup1.ipynb #52b04240
|
|
44
44
|
class TriggerDB(Database):
|
|
45
45
|
"""
|
|
46
46
|
Database that triggers logging when updated.
|
|
@@ -51,12 +51,16 @@ class TriggerDB(Database):
|
|
|
51
51
|
notion, # Notion client instance
|
|
52
52
|
status_prop, # Name of status property
|
|
53
53
|
relation_prop, # Name of relation property
|
|
54
|
-
qty_prop # Name of the quantity property
|
|
54
|
+
qty_prop, # Name of the quantity property
|
|
55
|
+
buf_qty_prop = None # Name of the quantity buffer
|
|
55
56
|
):
|
|
56
57
|
"""Initialize a TriggerDB instance.
|
|
57
58
|
"""
|
|
58
59
|
super().__init__(db_id, notion)
|
|
59
|
-
self.status_prop
|
|
60
|
+
self.status_prop = status_prop
|
|
61
|
+
self.relation_prop = relation_prop
|
|
62
|
+
self.qty_prop = qty_prop
|
|
63
|
+
self.buf_qty_prop = buf_qty_prop
|
|
60
64
|
|
|
61
65
|
#| exec_doc
|
|
62
66
|
def get_page_data(self,
|
|
@@ -71,10 +75,17 @@ class TriggerDB(Database):
|
|
|
71
75
|
try:
|
|
72
76
|
qty = page['properties'][self.qty_prop]['number']
|
|
73
77
|
except (KeyError, TypeError):
|
|
78
|
+
# In case the quantity is a formula
|
|
74
79
|
qty = page['properties'][self.qty_prop]['formula']['number']
|
|
75
|
-
return status, relation_id, qty
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
if self.buf_qty_prop is not None:
|
|
82
|
+
buf_qty = page['properties'][self.buf_qty_prop]['number']
|
|
83
|
+
else:
|
|
84
|
+
buf_qty = None
|
|
85
|
+
|
|
86
|
+
return status, relation_id, qty, buf_qty
|
|
87
|
+
|
|
88
|
+
# %% ../nbs/00_core_dup1.ipynb #82d6f2e9
|
|
78
89
|
class JunctionDB(Database):
|
|
79
90
|
"""Database that connects trigger items to log items with amounts.
|
|
80
91
|
|
|
@@ -137,7 +148,7 @@ class LogDB(Database):
|
|
|
137
148
|
|
|
138
149
|
|
|
139
150
|
|
|
140
|
-
# %% ../nbs/
|
|
151
|
+
# %% ../nbs/00_core_dup1.ipynb #b5e31e9a
|
|
141
152
|
class AutoLogger:
|
|
142
153
|
"""Orchestrates automatic logging from trigger to log via junction.
|
|
143
154
|
|
|
@@ -159,20 +170,25 @@ class AutoLogger:
|
|
|
159
170
|
reason:str # Reason for log entry
|
|
160
171
|
):
|
|
161
172
|
"""Process a trigger page and create log entries."""
|
|
162
|
-
status, relation_id, qty = self.trigger_db.get_page_data(page_id)
|
|
173
|
+
status, relation_id, qty, buf_qty = self.trigger_db.get_page_data(page_id)
|
|
174
|
+
|
|
175
|
+
if buf_qty is not None:
|
|
176
|
+
qty = qty + buf_qty
|
|
177
|
+
|
|
163
178
|
if status != self.trigger_status: return f"Status is {status}, not {self.trigger_status}"
|
|
164
179
|
items = self.junction_db.get_items(relation_id)
|
|
165
180
|
if not items: return "No items found in junction"
|
|
166
181
|
for item_id, amt in items.items(): self.log_db.create_entry(item_id, self.multiplier * qty * amt, page_id, reason)
|
|
167
182
|
return f"Logged {len(items)} items"
|
|
168
183
|
|
|
169
|
-
# %% ../nbs/
|
|
184
|
+
# %% ../nbs/00_core_dup1.ipynb #e56edb4d
|
|
170
185
|
@patch
|
|
171
186
|
def get_entries_for_trigger(self:LogDB, trigger_page_id):
|
|
172
187
|
"Find all log entries linked to a specific trigger page"
|
|
173
|
-
results = self.notion.
|
|
174
|
-
return [(p['id'], p['properties'][self.item_prop]['relation'][0]['id'], p['properties'][self.
|
|
188
|
+
results = self.notion.data_sources.query(data_source_id=self.data_source_id, filter={"property": self.trigger_prop, "relation": {"contains": trigger_page_id}})
|
|
189
|
+
return [(p['id'], p['properties'][self.item_prop]['relation'][0]['id'], p['properties'][self.amount_prop]['number']) for p in results['results']]
|
|
175
190
|
|
|
191
|
+
# %% ../nbs/00_core_dup1.ipynb #ae4afffa
|
|
176
192
|
@patch
|
|
177
193
|
def undo_all(self:AutoLogger, page_id, reason='Undo Changes'):
|
|
178
194
|
"Reverse all existing log entries for a trigger page"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{notion_cascade_insert-0.0.5 → notion_cascade_insert-0.0.7}/notion_cascade_insert/webhook.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|