ssb-pubmd 0.0.3__py3-none-any.whl → 0.0.4__py3-none-any.whl
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.
- ssb_pubmd/__init__.py +4 -0
- ssb_pubmd/functions.py +61 -20
- {ssb_pubmd-0.0.3.dist-info → ssb_pubmd-0.0.4.dist-info}/METADATA +2 -1
- ssb_pubmd-0.0.4.dist-info/RECORD +9 -0
- ssb_pubmd-0.0.3.dist-info/RECORD +0 -9
- {ssb_pubmd-0.0.3.dist-info → ssb_pubmd-0.0.4.dist-info}/LICENSE +0 -0
- {ssb_pubmd-0.0.3.dist-info → ssb_pubmd-0.0.4.dist-info}/WHEEL +0 -0
- {ssb_pubmd-0.0.3.dist-info → ssb_pubmd-0.0.4.dist-info}/entry_points.txt +0 -0
ssb_pubmd/__init__.py
CHANGED
ssb_pubmd/functions.py
CHANGED
|
@@ -5,33 +5,74 @@ https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
|
|
|
5
5
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
import nbformat
|
|
12
|
+
from nbformat import NotebookNode
|
|
11
13
|
|
|
12
|
-
This is merely an example function can be deleted. It is used to show and test generating
|
|
13
|
-
documentation from code, type hinting, testing, and testing examples
|
|
14
|
-
in the code.
|
|
15
14
|
|
|
15
|
+
def _read_notebook(fp: str) -> NotebookNode:
|
|
16
|
+
return nbformat.read(fp, as_version=nbformat.NO_CONVERT) # type: ignore
|
|
16
17
|
|
|
17
|
-
Args:
|
|
18
|
-
number1: The first number.
|
|
19
|
-
number2: The second number, which will be compared to number1.
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
def notebook_to_cms(
|
|
20
|
+
notebook_filename: str,
|
|
21
|
+
endpoint: str,
|
|
22
|
+
notebook_folder: str = "",
|
|
23
|
+
display_name: str = "",
|
|
24
|
+
) -> dict[str, str]:
|
|
25
|
+
r"""Sends all the markdown content of a notebook to a CMS endpoint.
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
to use the function.
|
|
27
|
+
This function can be executed within the notebook it gets the markdown content from, \
|
|
28
|
+
but the notebook filename always has to be explicitly passed.
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
The CMS endpoint has to satisfy two constraints:
|
|
31
|
+
* It must accept post requests with fields *id*, *displayName* and *markdown*.
|
|
32
|
+
* The response body must have a key *_id* whose value should be \
|
|
33
|
+
the unique identifier of the created content in the CMS.
|
|
30
34
|
|
|
35
|
+
On the first successfull request, an empty string is sent as *id*,
|
|
36
|
+
and the *_id* in the response is stored in a JSON file \
|
|
37
|
+
(created in the same directory as the notebook file). \
|
|
38
|
+
On subsequent requests, the stored value is sent as *id*.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
notebook_filename (str): The name of the notebook file.
|
|
42
|
+
endpoint (str): The URL of the CMS endpoint.
|
|
43
|
+
notebook_folder (str): Ignore this parameter when executing the function from \
|
|
44
|
+
the notebook containing the markdown content. \
|
|
45
|
+
Sets a custom base directory (absolute path) containing the notebook file.
|
|
46
|
+
display_name (str): Send a custom *displayName* value to the CMS endpoint.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
(dict): The response from the CMS endpoint.
|
|
31
50
|
"""
|
|
32
|
-
if
|
|
33
|
-
|
|
34
|
-
elif number1 > number2:
|
|
35
|
-
return f"{number1} is greater than {number2} by {number1 - number2}"
|
|
51
|
+
if notebook_folder:
|
|
52
|
+
os.chdir(notebook_folder)
|
|
36
53
|
else:
|
|
37
|
-
|
|
54
|
+
os.chdir(os.getcwd())
|
|
55
|
+
|
|
56
|
+
basename = os.path.splitext(notebook_filename)[0]
|
|
57
|
+
json_filename = basename + ".json"
|
|
58
|
+
|
|
59
|
+
_id = ""
|
|
60
|
+
if os.path.exists(json_filename):
|
|
61
|
+
with open(json_filename) as file:
|
|
62
|
+
_id = json.load(file)["_id"]
|
|
63
|
+
|
|
64
|
+
if not display_name:
|
|
65
|
+
display_name = basename.replace("_", " ").title()
|
|
66
|
+
|
|
67
|
+
markdown = ""
|
|
68
|
+
if os.path.exists(notebook_filename):
|
|
69
|
+
notebook = _read_notebook(notebook_filename)
|
|
70
|
+
markdown = "\n\n".join(
|
|
71
|
+
cell.source for cell in notebook.cells if cell.cell_type == "markdown"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
endpoint = endpoint
|
|
75
|
+
|
|
76
|
+
request_data = {"id": _id, "displayName": display_name, "markdown": markdown}
|
|
77
|
+
|
|
78
|
+
return request_data
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: ssb-pubmd
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: SSB Pubmd
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Olav Landsverk
|
|
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
16
16
|
Requires-Dist: click (>=8.0.1)
|
|
17
|
+
Requires-Dist: nbformat (>=5.10.4,<6.0.0)
|
|
17
18
|
Project-URL: Changelog, https://github.com/statisticsnorway/ssb-pubmd/releases
|
|
18
19
|
Project-URL: Documentation, https://statisticsnorway.github.io/ssb-pubmd
|
|
19
20
|
Project-URL: Homepage, https://github.com/statisticsnorway/ssb-pubmd
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
ssb_pubmd/__init__.py,sha256=GGdFjb7Gcazu5sC97C-Je8JY-8f0dZ6mKjL-G-4cJLo,88
|
|
2
|
+
ssb_pubmd/__main__.py,sha256=8D0yedPhnV_2L7nj0s0KUKxNQqPxoussMHGDNM-vyjg,209
|
|
3
|
+
ssb_pubmd/functions.py,sha256=UgNVKehv9ULKVJKcZt-zGBIcPUetD1Iy9Q9kJurj7BI,2591
|
|
4
|
+
ssb_pubmd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
ssb_pubmd-0.0.4.dist-info/LICENSE,sha256=tF5bnYv09fgH5ph9t1EpH1MGrVOGTQeswL4dzVeZ_ak,1073
|
|
6
|
+
ssb_pubmd-0.0.4.dist-info/METADATA,sha256=tGKSsJpSglhxqSIhDrepOCU6aVXRiR_3z_YLd3-guDE,3782
|
|
7
|
+
ssb_pubmd-0.0.4.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
8
|
+
ssb_pubmd-0.0.4.dist-info/entry_points.txt,sha256=o4oU99zbZNIBKGYWdgdEG6ev-62ZRWEJOe7EOjJaajk,53
|
|
9
|
+
ssb_pubmd-0.0.4.dist-info/RECORD,,
|
ssb_pubmd-0.0.3.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
ssb_pubmd/__init__.py,sha256=kCA0PilWSQNDZh4rUo5jRghGfLkmQkZDcWMNRJSQVaA,17
|
|
2
|
-
ssb_pubmd/__main__.py,sha256=8D0yedPhnV_2L7nj0s0KUKxNQqPxoussMHGDNM-vyjg,209
|
|
3
|
-
ssb_pubmd/functions.py,sha256=liG4j8_NaA1NGGZGqqDcexaOSUQmR9Ksbk7xa253O94,1122
|
|
4
|
-
ssb_pubmd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
ssb_pubmd-0.0.3.dist-info/LICENSE,sha256=tF5bnYv09fgH5ph9t1EpH1MGrVOGTQeswL4dzVeZ_ak,1073
|
|
6
|
-
ssb_pubmd-0.0.3.dist-info/METADATA,sha256=F33kVdLp4H2Jt4Oj4cMzCWhkydj01L47d0XnCnHf4wU,3740
|
|
7
|
-
ssb_pubmd-0.0.3.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
8
|
-
ssb_pubmd-0.0.3.dist-info/entry_points.txt,sha256=o4oU99zbZNIBKGYWdgdEG6ev-62ZRWEJOe7EOjJaajk,53
|
|
9
|
-
ssb_pubmd-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|