ssb-pubmd 0.0.4__tar.gz → 0.0.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ssb-pubmd
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: SSB Pubmd
5
5
  License: MIT
6
6
  Author: Olav Landsverk
@@ -15,6 +15,8 @@ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Requires-Dist: click (>=8.0.1)
17
17
  Requires-Dist: nbformat (>=5.10.4,<6.0.0)
18
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
19
+ Requires-Dist: types-requests (>=2.32.0.20250306,<3.0.0.0)
18
20
  Project-URL: Changelog, https://github.com/statisticsnorway/ssb-pubmd/releases
19
21
  Project-URL: Documentation, https://statisticsnorway.github.io/ssb-pubmd
20
22
  Project-URL: Homepage, https://github.com/statisticsnorway/ssb-pubmd
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ssb-pubmd"
3
- version = "0.0.4"
3
+ version = "0.0.5"
4
4
  description = "SSB Pubmd"
5
5
  authors = ["Olav Landsverk <stud-oll@ssb.no>"]
6
6
  license = "MIT"
@@ -17,6 +17,8 @@ Changelog = "https://github.com/statisticsnorway/ssb-pubmd/releases"
17
17
  python = "^3.10"
18
18
  click = ">=8.0.1"
19
19
  nbformat = "^5.10.4"
20
+ requests = "^2.32.3"
21
+ types-requests = "^2.32.0.20250306"
20
22
 
21
23
  [tool.poetry.group.dev.dependencies]
22
24
  pygments = ">=2.10.0"
@@ -9,6 +9,7 @@ import json
9
9
  import os
10
10
 
11
11
  import nbformat
12
+ import requests
12
13
  from nbformat import NotebookNode
13
14
 
14
15
 
@@ -21,32 +22,33 @@ def notebook_to_cms(
21
22
  endpoint: str,
22
23
  notebook_folder: str = "",
23
24
  display_name: str = "",
24
- ) -> dict[str, str]:
25
+ ) -> str:
25
26
  r"""Sends all the markdown content of a notebook to a CMS endpoint.
26
27
 
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.
28
+ The CMS endpoint must satisfy two constraints:
29
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
+ - It must accept a post request with fields *id*, *displayName* and *markdown*.
31
+ - The response body must have a key *_id* whose value should be
32
+ a unique string identifier of the content.
34
33
 
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*.
34
+ Creating and updating content is handled in the following way:
35
+
36
+ - On the first request, an empty string is sent as *id*.
37
+ - If the request succeeds, the value of *_id* (in the response) is stored in a JSON file
38
+ (created in the same directory as the notebook file).
39
+ - On subsequent requests, the stored value is sent as *id*.
39
40
 
40
41
  Args:
41
- notebook_filename (str): The name of the notebook file.
42
+ notebook_filename (str): The name of the notebook file, e.g. `"my_notebook.ipynb"`.
42
43
  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.
44
+ notebook_folder (str): Sets a custom notebook folder (as absolute path) containing the notebook file.
45
+ If not set, the current folder is used.
46
46
  display_name (str): Send a custom *displayName* value to the CMS endpoint.
47
+ If not set, the notebook filename is used (with the file extension removed,
48
+ underscores replaced with spaces, and words capitalized).
47
49
 
48
50
  Returns:
49
- (dict): The response from the CMS endpoint.
51
+ str: The response from the CMS endpoint, string-formatted.
50
52
  """
51
53
  if notebook_folder:
52
54
  os.chdir(notebook_folder)
@@ -71,8 +73,7 @@ def notebook_to_cms(
71
73
  cell.source for cell in notebook.cells if cell.cell_type == "markdown"
72
74
  )
73
75
 
74
- endpoint = endpoint
75
-
76
76
  request_data = {"id": _id, "displayName": display_name, "markdown": markdown}
77
+ response = requests.post(endpoint, data=request_data)
77
78
 
78
- return request_data
79
+ return json.dumps(response, indent=4)
File without changes
File without changes