pysstorytime 0.0.2__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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2022, fastai
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ include pyproject.toml
2
+ include LICENSE
3
+ include CONTRIBUTING.md
4
+ include README.md
5
+ recursive-exclude * __pycache__
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: pysstorytime
3
+ Version: 0.0.2
4
+ Author-email: Christophe Beauce <chris@chrphb.com>
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Repository, https://github.com/chrphb/pysstorytime
7
+ Project-URL: Documentation, https://chrphb.github.io/pysstorytime/
8
+ Keywords: nbdev
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: asyncpg>=0.31
15
+ Dynamic: license-file
16
+
17
+ # pysstorytime
18
+
19
+
20
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
21
+
22
+ This file will become your README and also the index of your documentation.
23
+
24
+ ## Developer Guide
25
+
26
+ If you are new to using `nbdev` here are some useful pointers to get you started.
27
+
28
+ ### Install pysstorytime in Development mode
29
+
30
+ ``` sh
31
+ # make sure pysstorytime package is installed in development mode
32
+ $ pip install -e .
33
+
34
+ # make changes under nbs/ directory
35
+ # ...
36
+
37
+ # compile to have changes apply to pysstorytime
38
+ $ nbdev_prepare
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### Installation
44
+
45
+ Install latest from the GitHub [repository](https://github.com/chrphb/pysstorytime):
46
+
47
+ ``` sh
48
+ $ pip install git+https://github.com/chrphb/pysstorytime.git
49
+ ```
50
+
51
+ or from [pypi](https://pypi.org/project/pysstorytime/)
52
+
53
+ ``` sh
54
+ $ pip install pysstorytime
55
+ ```
56
+
57
+ ### Documentation
58
+
59
+ Documentation can be found hosted on this GitHub [repository](https://github.com/chrphb/pysstorytime)’s [pages](https://chrphb.github.io/pysstorytime/). Additionally you can find package manager specific guidelines on [conda](https://anaconda.org/chrphb/pysstorytime) and [pypi](https://pypi.org/project/pysstorytime/) respectively.
60
+
61
+ ## How to use
62
+
63
+ Fill me in please! Don’t forget code examples:
@@ -0,0 +1,47 @@
1
+ # pysstorytime
2
+
3
+
4
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
5
+
6
+ This file will become your README and also the index of your documentation.
7
+
8
+ ## Developer Guide
9
+
10
+ If you are new to using `nbdev` here are some useful pointers to get you started.
11
+
12
+ ### Install pysstorytime in Development mode
13
+
14
+ ``` sh
15
+ # make sure pysstorytime package is installed in development mode
16
+ $ pip install -e .
17
+
18
+ # make changes under nbs/ directory
19
+ # ...
20
+
21
+ # compile to have changes apply to pysstorytime
22
+ $ nbdev_prepare
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Installation
28
+
29
+ Install latest from the GitHub [repository](https://github.com/chrphb/pysstorytime):
30
+
31
+ ``` sh
32
+ $ pip install git+https://github.com/chrphb/pysstorytime.git
33
+ ```
34
+
35
+ or from [pypi](https://pypi.org/project/pysstorytime/)
36
+
37
+ ``` sh
38
+ $ pip install pysstorytime
39
+ ```
40
+
41
+ ### Documentation
42
+
43
+ Documentation can be found hosted on this GitHub [repository](https://github.com/chrphb/pysstorytime)’s [pages](https://chrphb.github.io/pysstorytime/). Additionally you can find package manager specific guidelines on [conda](https://anaconda.org/chrphb/pysstorytime) and [pypi](https://pypi.org/project/pysstorytime/) respectively.
44
+
45
+ ## How to use
46
+
47
+ Fill me in please! Don’t forget code examples:
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pysstorytime"
7
+ dynamic = ["version"]
8
+ description = ""
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ authors = [{name = "Christophe Beauce", email = "chris@chrphb.com"}]
13
+ keywords = ['nbdev']
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3 :: Only",
17
+ ]
18
+ dependencies = ["asyncpg>=0.31"]
19
+
20
+ [project.urls]
21
+ Repository = "https://github.com/chrphb/pysstorytime"
22
+ Documentation = "https://chrphb.github.io/pysstorytime/"
23
+
24
+ [project.entry-points.nbdev]
25
+ pysstorytime = "pysstorytime._modidx:d"
26
+
27
+ [tool.setuptools.dynamic]
28
+ version = {attr = "pysstorytime.__version__"}
29
+
30
+ [tool.setuptools.packages.find]
31
+ include = ["pysstorytime"]
32
+
33
+ [tool.nbdev]
@@ -0,0 +1 @@
1
+ __version__ = "0.0.2"
@@ -0,0 +1,36 @@
1
+ # Autogenerated by nbdev
2
+
3
+ d = { 'settings': { 'branch': 'main',
4
+ 'doc_baseurl': '/pysstorytime',
5
+ 'doc_host': 'https://chrphb.github.io',
6
+ 'git_url': 'https://github.com/chrphb/pysstorytime',
7
+ 'lib_path': 'pysstorytime'},
8
+ 'syms': { 'pysstorytime.core': { 'pysstorytime.core.Arrow': ('api.html#arrow', 'pysstorytime/core.py'),
9
+ 'pysstorytime.core.Arrow.__init__': ('api.html#arrow.__init__', 'pysstorytime/core.py'),
10
+ 'pysstorytime.core.Arrow.__repr__': ('api.html#arrow.__repr__', 'pysstorytime/core.py'),
11
+ 'pysstorytime.core.Link': ('api.html#link', 'pysstorytime/core.py'),
12
+ 'pysstorytime.core.Link.__init__': ('api.html#link.__init__', 'pysstorytime/core.py'),
13
+ 'pysstorytime.core.Link.__repr__': ('api.html#link.__repr__', 'pysstorytime/core.py'),
14
+ 'pysstorytime.core.Link.dst_label': ('api.html#link.dst_label', 'pysstorytime/core.py'),
15
+ 'pysstorytime.core.Link.label': ('api.html#link.label', 'pysstorytime/core.py'),
16
+ 'pysstorytime.core.Link.pretty_repr': ('api.html#link.pretty_repr', 'pysstorytime/core.py'),
17
+ 'pysstorytime.core.Node': ('api.html#node', 'pysstorytime/core.py'),
18
+ 'pysstorytime.core.Node.__init__': ('api.html#node.__init__', 'pysstorytime/core.py'),
19
+ 'pysstorytime.core.Node.__repr__': ('api.html#node.__repr__', 'pysstorytime/core.py'),
20
+ 'pysstorytime.core.Node.pretty_repr': ('api.html#node.pretty_repr', 'pysstorytime/core.py'),
21
+ 'pysstorytime.core.NodePtr': ('api.html#nodeptr', 'pysstorytime/core.py'),
22
+ 'pysstorytime.core.NodePtr.to_tuple_str': ('api.html#nodeptr.to_tuple_str', 'pysstorytime/core.py'),
23
+ 'pysstorytime.core.connection': ('api.html#connection', 'pysstorytime/core.py'),
24
+ 'pysstorytime.core.count_arrows': ('api.html#count_arrows', 'pysstorytime/core.py'),
25
+ 'pysstorytime.core.count_connected_nodes': ('api.html#count_connected_nodes', 'pysstorytime/core.py'),
26
+ 'pysstorytime.core.count_nodes': ('api.html#count_nodes', 'pysstorytime/core.py'),
27
+ 'pysstorytime.core.expand_node': ('api.html#expand_node', 'pysstorytime/core.py'),
28
+ 'pysstorytime.core.fetch_link_label': ('api.html#fetch_link_label', 'pysstorytime/core.py'),
29
+ 'pysstorytime.core.fetch_nptr_label': ('api.html#fetch_nptr_label', 'pysstorytime/core.py'),
30
+ 'pysstorytime.core.get_all_arrows': ('api.html#get_all_arrows', 'pysstorytime/core.py'),
31
+ 'pysstorytime.core.get_arrow_with_arrow_name': ( 'api.html#get_arrow_with_arrow_name',
32
+ 'pysstorytime/core.py'),
33
+ 'pysstorytime.core.get_db_nptr_matching_name': ( 'api.html#get_db_nptr_matching_name',
34
+ 'pysstorytime/core.py'),
35
+ 'pysstorytime.core.get_node': ('api.html#get_node', 'pysstorytime/core.py'),
36
+ 'pysstorytime.core.search_my_notes': ('api.html#search_my_notes', 'pysstorytime/core.py')}}}
@@ -0,0 +1,396 @@
1
+ """Docs: https://chrphb.github.io/pysstorytime/api.html.md"""
2
+
3
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_api.ipynb.
4
+
5
+ # %% auto #0
6
+ __all__ = ['host', 'port', 'db', 'user', 'password', 'connection', 'count_nodes', 'count_arrows', 'count_connected_nodes',
7
+ 'Arrow', 'get_arrow_with_arrow_name', 'NodePtr', 'Node', 'get_node', 'get_all_arrows', 'fetch_link_label',
8
+ 'fetch_nptr_label', 'Link', 'get_db_nptr_matching_name', 'expand_node', 'search_my_notes']
9
+
10
+ # %% ../nbs/01_api.ipynb #5948bf93
11
+ import os
12
+
13
+ # %% ../nbs/01_api.ipynb #5589480b
14
+ host = os.environ['N4L_HOST']
15
+ port = int(os.environ['N4L_PORT'])
16
+ db = os.environ['N4L_DB']
17
+ user = os.environ['N4L_USER']
18
+ password = os.environ['N4L_PASSWORD']
19
+
20
+ # %% ../nbs/01_api.ipynb #320fb87f
21
+ import asyncio
22
+
23
+ # %% ../nbs/01_api.ipynb #fa90a948
24
+ import asyncpg
25
+
26
+ # %% ../nbs/01_api.ipynb #b04ad717
27
+ from contextlib import asynccontextmanager
28
+
29
+ @asynccontextmanager
30
+ async def connection(user:str=None, password:str=None, db:str=None, host:str=None, port:str=None):
31
+ """
32
+ An async context manager opening a connection to the database, and closing it at the end
33
+ yields an asyncpg connection
34
+ """
35
+ if(not(user)):
36
+ user = os.environ['N4L_USER']
37
+ if(not(password)):
38
+ password = os.environ['N4L_PASSWORD']
39
+ if(not(db)):
40
+ db = os.environ['N4L_DB']
41
+ if(not(host)):
42
+ host = os.environ['N4L_HOST']
43
+ if(not(port)):
44
+ port = int(os.environ.get('N4L_PORT'))
45
+ if(not(port)):
46
+ port = 5432
47
+ conn = await asyncpg.connect(user=user, password=password,
48
+ database=db, host=host, port=port)
49
+ try:
50
+ yield conn
51
+ finally:
52
+ #print('closing the connection')
53
+ await conn.close()
54
+
55
+ # %% ../nbs/01_api.ipynb #fff2f18d
56
+ async def count_nodes(conn):
57
+ """
58
+ return the total number of Nodes in the database
59
+ """
60
+ row = await conn.fetchrow("SELECT COUNT(*) FROM Node")
61
+ return int(row['count'])
62
+
63
+ # %% ../nbs/01_api.ipynb #4b2747fd
64
+ async def count_arrows(conn):
65
+ """
66
+ return the total number of Arrows in the database
67
+ """
68
+ row = await conn.fetchrow("SELECT COUNT(*) FROM ArrowDirectory")
69
+ return int(row['count'])
70
+
71
+ # %% ../nbs/01_api.ipynb #f3d9c1b0
72
+ async def count_connected_nodes(conn):
73
+ """
74
+ return the total number of connected nodes in the database
75
+ """
76
+ row = await conn.fetchrow("""SELECT COUNT(*) FROM Node
77
+ WHERE EXISTS (
78
+ SELECT 1 FROM unnest(Im3||Im2||Im1||In0||Il1||Ic2||Ie3) as l
79
+ WHERE l.arr <> 0
80
+ )""")
81
+ return int(row['count'])
82
+
83
+ # %% ../nbs/01_api.ipynb #16d71ac9
84
+ class Arrow():
85
+ def __init__(self, row:dict):
86
+ self.__dict__.update(row)
87
+
88
+ def __repr__(self):
89
+ return f'<Arrow short={self.short} staindex={self.staindex} arrptr={self.arrptr}>'
90
+
91
+ # %% ../nbs/01_api.ipynb #78fe3640
92
+ async def get_arrow_with_arrow_name(conn,arrow):
93
+ row = await conn.fetchrow("SELECT Short, STAindex,ArrPtr FROM ArrowDirectory WHERE Long='"+arrow+"' OR Short='"+arrow+"' ORDER BY ArrPtr")
94
+ return Arrow(dict(row))
95
+ #pg_rows = curs.fetchall()
96
+ #a = pg_rows[0]
97
+ #sttype = STIndexToSTType(a[0])
98
+ #arrowptr = a[1]
99
+ #return arrowptr,sttype
100
+
101
+
102
+ # %% ../nbs/01_api.ipynb #d5295ad1
103
+ from typing import NamedTuple
104
+
105
+ # %% ../nbs/01_api.ipynb #2010db40
106
+ class NodePtr(NamedTuple):
107
+ chan: int
108
+ cptr: int
109
+
110
+ def to_tuple_str(self):
111
+ return f'({self.chan},{self.cptr})'
112
+
113
+ # %% ../nbs/01_api.ipynb #58c76b8d
114
+ class Node:
115
+ def __init__(self, record):
116
+ self.s = record['s']
117
+ self.chap = record['chap']
118
+ self.nptr = NodePtr(**record['nptr'])
119
+ self.m3 = []
120
+ for item in record['im3']:
121
+ link = Link(item)
122
+ self.m3.append(link)
123
+ self.m2 = []
124
+ for item in record['im2']:
125
+ link = Link(item)
126
+ self.m2.append(link)
127
+ self.m1 = []
128
+ for item in record['im1']:
129
+ link = Link(item)
130
+ self.m1.append(link)
131
+ self.n0 = []
132
+ for item in record['in0']:
133
+ link = Link(item)
134
+ self.n0.append(link)
135
+ self.l1 = []
136
+ for item in record['il1']:
137
+ link = Link(item)
138
+ self.l1.append(link)
139
+ self.c2 = []
140
+ for item in record['ic2']:
141
+ link = Link(item)
142
+ self.c2.append(link)
143
+ self.e3 = []
144
+ for item in record['ie3']:
145
+ link = Link(item)
146
+ self.e3.append(link)
147
+
148
+ def __repr__(self):
149
+ return f'<Node s="{self.s}" chap="{self.chap}" nptr="{self.nptr}" e3="{self.e3}">'
150
+
151
+ def pretty_repr(self):
152
+ r = f'{self.chap}\n'
153
+ r = r + f'{self.s} \n'
154
+ for links in [self.m3, self.m2, self.m1, self.n0, self.l1, self.c2, self.e3]:
155
+ for link in links:
156
+ # todo : improve this - see NodePtr(0,0)
157
+ if(link.pretty_repr()!='SKIPPED'):
158
+ r = r + f' {link.pretty_repr()} \n'
159
+ return r
160
+
161
+ # %% ../nbs/01_api.ipynb #4e91ef92
162
+ async def get_node(conn,nptr:NodePtr):
163
+ """
164
+ Retrieves a Node from a node pointer, as a tuple of 2 integers such as (1,2)
165
+ """
166
+ row = await conn.fetchrow("SELECT S,L,Chap,NPtr,Im3,Im2,Im1,In0,Il1,Ic2,Ie3 FROM Node where nptr='"+nptr.to_tuple_str()+"'::NodePtr")
167
+ print(row)
168
+ return Node(row)
169
+
170
+ # %% ../nbs/01_api.ipynb #81a7eda3
171
+ async def get_all_arrows(conn):
172
+ rows = await conn.fetchmany("SELECT Short,STAindex,ArrPtr FROM ArrowDirectory",[])
173
+ print(rows)
174
+ for row in rows[:5]:
175
+ print(row)
176
+
177
+ # %% ../nbs/01_api.ipynb #2d3578e0
178
+ async def get_all_arrows(conn):
179
+ rows = await conn.fetch("SELECT Short,Long,STAindex,ArrPtr FROM ArrowDirectory")
180
+ for row in rows[:5]:
181
+ print(row)
182
+
183
+ # %% ../nbs/01_api.ipynb #65a08d84
184
+ async def fetch_link_label(conn, link):
185
+ #print('link:',link)
186
+ row = await conn.fetchrow("SELECT Short FROM ArrowDirectory WHERE ArrPtr='"+str(link.arr)+"'")
187
+ #print(row)
188
+ link.label = row['short']
189
+ return None
190
+
191
+ # %% ../nbs/01_api.ipynb #0262488d
192
+ async def fetch_nptr_label(conn, link):
193
+ nptr = link.dst
194
+ row = await conn.fetchrow("SELECT S AS label FROM Node WHERE nptr='"+nptr.to_tuple_str()+"'::NodePtr")
195
+ print(row)
196
+ link.dst_label = row['label']
197
+ return None
198
+
199
+ # %% ../nbs/01_api.ipynb #0631d21c
200
+ class Link:
201
+
202
+ def __init__(self, record):
203
+ self.arr = record['arr']
204
+ self.ctx = record['ctx']
205
+ self.dst = NodePtr(**record['dst'])
206
+ self._label = None
207
+ self._dst_label = None
208
+
209
+ @property
210
+ def label(self):
211
+ return self._label
212
+
213
+ @property
214
+ def dst_label(self):
215
+ return self._dst_label
216
+
217
+ @label.setter
218
+ def label(self, label):
219
+ self._label = label
220
+
221
+ @dst_label.setter
222
+ def dst_label(self, dlabel):
223
+ self._dst_label = dlabel
224
+
225
+ def __repr__(self):
226
+ if(self.label and self.dst_label):
227
+ return f'<Link arr={self.label} ctx={self.ctx} dest={self.dst_label}>'
228
+ else:
229
+ return f'<Link arr={self.arr} ctx={self.ctx} dest={self.dst}>'
230
+
231
+ def pretty_repr(self):
232
+ if(self.label and self.dst_label):
233
+ r = f'-- {self.label} --> {self.dst_label}'
234
+ return r
235
+ else:
236
+ return 'SKIPPED'
237
+
238
+ # %% ../nbs/01_api.ipynb #430ea37f
239
+ async def get_db_nptr_matching_name(conn, name):
240
+ rows = await conn.fetch("SELECT * FROM Node WHERE S LIKE '%"+name+"%'")
241
+ for row in rows:
242
+ node = Node(row)
243
+ print("node before",node)
244
+ e3_links = node.e3
245
+ for link in e3_links:
246
+ print("--",link)
247
+ await fetch_link_label(conn,link)
248
+ dst = link.dst
249
+ await fetch_nptr_label(conn, link)
250
+ print("node after",node)
251
+ return None
252
+
253
+
254
+ # %% ../nbs/01_api.ipynb #0dfdc6ef
255
+ class Link:
256
+
257
+ def __init__(self, record):
258
+ self.arr = record['arr']
259
+ self.ctx = record['ctx']
260
+ self.dst = NodePtr(**record['dst'])
261
+ self._label = None
262
+ self._dst_label = None
263
+
264
+ @property
265
+ def label(self):
266
+ return self._label
267
+
268
+ @property
269
+ def dst_label(self):
270
+ return self._dst_label
271
+
272
+ @label.setter
273
+ def label(self, label):
274
+ self._label = label
275
+
276
+ @dst_label.setter
277
+ def dst_label(self, dlabel):
278
+ self._dst_label = dlabel
279
+
280
+ def __repr__(self):
281
+ if(self.label and self.dst_label):
282
+ return f'<Link arr={self.label} ctx={self.ctx} dest={self.dst_label}>'
283
+ else:
284
+ return f'<Link arr={self.arr} ctx={self.ctx} dest={self.dst}>'
285
+
286
+ def pretty_repr(self):
287
+ if(self.label and self.dst_label):
288
+ r = f'-- {self.label} --> {self.dst_label}'
289
+ return r
290
+ else:
291
+ return 'SKIPPED'
292
+
293
+ # %% ../nbs/01_api.ipynb #1271a733
294
+ class Node:
295
+ def __init__(self, record):
296
+ self.s = record['s']
297
+ self.chap = record['chap']
298
+ self.nptr = NodePtr(**record['nptr'])
299
+ self.m3 = []
300
+ for item in record['im3']:
301
+ link = Link(item)
302
+ self.m3.append(link)
303
+ self.m2 = []
304
+ for item in record['im2']:
305
+ link = Link(item)
306
+ self.m2.append(link)
307
+ self.m1 = []
308
+ for item in record['im1']:
309
+ link = Link(item)
310
+ self.m1.append(link)
311
+ self.n0 = []
312
+ for item in record['in0']:
313
+ link = Link(item)
314
+ self.n0.append(link)
315
+ self.l1 = []
316
+ for item in record['il1']:
317
+ link = Link(item)
318
+ self.l1.append(link)
319
+ self.c2 = []
320
+ for item in record['ic2']:
321
+ link = Link(item)
322
+ self.c2.append(link)
323
+ self.e3 = []
324
+ for item in record['ie3']:
325
+ link = Link(item)
326
+ self.e3.append(link)
327
+
328
+ def __repr__(self):
329
+ return f'<Node s="{self.s}" chap="{self.chap}" nptr="{self.nptr}" e3="{self.e3}">'
330
+
331
+ def pretty_repr(self):
332
+ r = f'{self.chap}\n'
333
+ r = r + f'{self.s} \n'
334
+ for links in [self.m3, self.m2, self.m1, self.n0, self.l1, self.c2, self.e3]:
335
+ for link in links:
336
+ # todo : improve this - see NodePtr(0,0)
337
+ if(link.pretty_repr()!='SKIPPED'):
338
+ r = r + f' {link.pretty_repr()} \n'
339
+ return r
340
+
341
+ # %% ../nbs/01_api.ipynb #0bbfffe6
342
+ async def get_db_nptr_matching_name(conn, name):
343
+ rows = await conn.fetch("SELECT * FROM Node WHERE S LIKE '%"+name+"%'")
344
+ for row in rows:
345
+ node = Node(row)
346
+ #print("node before",node)
347
+ e3_links = node.e3
348
+ for link in e3_links:
349
+ #print("--",link)
350
+ await fetch_link_label(conn,link)
351
+ dst = link.dst
352
+ await fetch_nptr_label(conn, link)
353
+ print(node.pretty_repr())
354
+ return None
355
+
356
+
357
+ # %% ../nbs/01_api.ipynb #330b5692
358
+ async def get_db_nptr_matching_name(conn, name):
359
+ rows = await conn.fetch("SELECT * FROM Node WHERE S LIKE '%"+name+"%'")
360
+ for row in rows:
361
+ node = Node(row)
362
+ await expand_node(conn, node)
363
+ print(node.pretty_repr())
364
+ return None
365
+
366
+
367
+ # %% ../nbs/01_api.ipynb #73320244
368
+ async def expand_node(conn, node):
369
+ """
370
+ expands the labels of node with the link labels with the destination labels
371
+ note: node is updated by this function
372
+ """
373
+ for links in [node.m3, node.m2, node.m1, node.n0, node.l1, node.c2, node.e3]:
374
+ for link in links:
375
+ await fetch_link_label(conn, link)
376
+ dst = link.dst
377
+ await fetch_nptr_label(conn, link)
378
+ return None
379
+
380
+ # %% ../nbs/01_api.ipynb #d54acaa9
381
+ async def fetch_nptr_label(conn, link):
382
+ nptr = link.dst
383
+ row = await conn.fetchrow("SELECT S AS label FROM Node WHERE nptr='"+nptr.to_tuple_str()+"'::NodePtr")
384
+ if not(row is None):
385
+ link.dst_label = row['label']
386
+ return None
387
+
388
+ # %% ../nbs/01_api.ipynb #0bbe1f97
389
+ async def search_my_notes(search_term:str):
390
+ """
391
+ a tool to search within my notes, it will output/print notes in a structured format
392
+ node label
393
+ -- arrow label --> other node label
394
+ """
395
+ async with connection() as conn:
396
+ await get_db_nptr_matching_name(conn, search_term)
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: pysstorytime
3
+ Version: 0.0.2
4
+ Author-email: Christophe Beauce <chris@chrphb.com>
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Repository, https://github.com/chrphb/pysstorytime
7
+ Project-URL: Documentation, https://chrphb.github.io/pysstorytime/
8
+ Keywords: nbdev
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: asyncpg>=0.31
15
+ Dynamic: license-file
16
+
17
+ # pysstorytime
18
+
19
+
20
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
21
+
22
+ This file will become your README and also the index of your documentation.
23
+
24
+ ## Developer Guide
25
+
26
+ If you are new to using `nbdev` here are some useful pointers to get you started.
27
+
28
+ ### Install pysstorytime in Development mode
29
+
30
+ ``` sh
31
+ # make sure pysstorytime package is installed in development mode
32
+ $ pip install -e .
33
+
34
+ # make changes under nbs/ directory
35
+ # ...
36
+
37
+ # compile to have changes apply to pysstorytime
38
+ $ nbdev_prepare
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### Installation
44
+
45
+ Install latest from the GitHub [repository](https://github.com/chrphb/pysstorytime):
46
+
47
+ ``` sh
48
+ $ pip install git+https://github.com/chrphb/pysstorytime.git
49
+ ```
50
+
51
+ or from [pypi](https://pypi.org/project/pysstorytime/)
52
+
53
+ ``` sh
54
+ $ pip install pysstorytime
55
+ ```
56
+
57
+ ### Documentation
58
+
59
+ Documentation can be found hosted on this GitHub [repository](https://github.com/chrphb/pysstorytime)’s [pages](https://chrphb.github.io/pysstorytime/). Additionally you can find package manager specific guidelines on [conda](https://anaconda.org/chrphb/pysstorytime) and [pypi](https://pypi.org/project/pysstorytime/) respectively.
60
+
61
+ ## How to use
62
+
63
+ Fill me in please! Don’t forget code examples:
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ pysstorytime/__init__.py
6
+ pysstorytime/_modidx.py
7
+ pysstorytime/core.py
8
+ pysstorytime.egg-info/PKG-INFO
9
+ pysstorytime.egg-info/SOURCES.txt
10
+ pysstorytime.egg-info/dependency_links.txt
11
+ pysstorytime.egg-info/entry_points.txt
12
+ pysstorytime.egg-info/requires.txt
13
+ pysstorytime.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [nbdev]
2
+ pysstorytime = pysstorytime._modidx:d
@@ -0,0 +1 @@
1
+ asyncpg>=0.31
@@ -0,0 +1 @@
1
+ pysstorytime
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+