ssb-pubmd 0.0.12__py3-none-any.whl → 0.0.13__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/__main__.py CHANGED
@@ -1,37 +1,76 @@
1
1
  """Command-line interface."""
2
2
 
3
- import os
3
+ import json
4
4
 
5
5
  import click
6
6
 
7
7
  from ssb_pubmd.browser_context import BrowserRequestContext as RequestContext
8
8
  from ssb_pubmd.markdown_syncer import MarkdownSyncer
9
9
 
10
+ CONFIG_FILE = "pubmd_config.json"
11
+
12
+
13
+ class ConfigKeys:
14
+ """The keys used in the configuration file."""
15
+
16
+ LOGIN = "login_url"
17
+ POST = "post_url"
18
+
19
+
20
+ def get_config_value(key: str) -> str:
21
+ """Get a configuration value."""
22
+ try:
23
+ with open(CONFIG_FILE) as json_file:
24
+ config = json.load(json_file)
25
+ value = config[key]
26
+ except FileNotFoundError:
27
+ click.echo(
28
+ f"Configuration file '{CONFIG_FILE}' not found. Please run the 'config' command first."
29
+ )
30
+ except Exception:
31
+ click.echo(
32
+ f"Error reading configuration file '{CONFIG_FILE}'. Please run the 'pubmd config' command again."
33
+ )
34
+ return str(value)
35
+
10
36
 
11
37
  @click.group()
12
38
  def cli() -> None:
13
- """Command-line interface for the ssb_pubmd package."""
39
+ """'pubmd' is a tool to sync markdown and notebook files to a CMS application.
40
+
41
+ Setup with subcommands 'config' and 'login', then use subcommand 'sync'.
42
+ """
14
43
  pass
15
44
 
16
45
 
46
+ @click.command()
47
+ def config() -> None:
48
+ """Configure the CMS to connect to."""
49
+ login_url = click.prompt("Enter the login URL", type=str)
50
+ post_url = click.prompt("Enter the post URL", type=str)
51
+
52
+ config = {ConfigKeys.LOGIN: login_url, ConfigKeys.POST: post_url}
53
+
54
+ with open(CONFIG_FILE, "w") as json_file:
55
+ json.dump(config, json_file, indent=4)
56
+
57
+ click.echo(f"\nThe configuration has been stored in:\n{CONFIG_FILE}")
58
+
59
+
17
60
  @click.command()
18
61
  def login() -> None:
19
- """Login to the server."""
20
- login_url = os.getenv("PUBMD_LOGIN_URL", "")
62
+ """Login to the CMS application."""
63
+ login_url = get_config_value(ConfigKeys.LOGIN)
21
64
  request_context = RequestContext()
22
- print(login_url)
23
65
  storage_state_file, storage_state = request_context.create_new(login_url)
24
- click.echo(
25
- f"The following browser context object is now stored in {storage_state_file}:"
26
- )
27
- click.echo(storage_state)
66
+ click.echo(f"\nThe browser context has been stored in:\n{storage_state_file}")
28
67
 
29
68
 
30
69
  @click.command()
31
70
  @click.argument("content_file_path", type=click.Path())
32
71
  def sync(content_file_path: str) -> None:
33
- """Sync the content."""
34
- post_url = os.getenv("PUBMD_POST_URL", "")
72
+ """Sync a markdown or notebook file to the CMS."""
73
+ post_url = get_config_value(ConfigKeys.POST)
35
74
  request_context = RequestContext()
36
75
  request_context.recreate_from_file()
37
76
 
@@ -45,6 +84,7 @@ def sync(content_file_path: str) -> None:
45
84
  )
46
85
 
47
86
 
87
+ cli.add_command(config)
48
88
  cli.add_command(login)
49
89
  cli.add_command(sync)
50
90
 
@@ -4,7 +4,7 @@ from playwright.sync_api import sync_playwright
4
4
 
5
5
  from .markdown_syncer import Response
6
6
 
7
- BROWSER_CONTEXT_FILE = "browser_context.json"
7
+ BROWSER_CONTEXT_FILE = "pubmd_browser_context.json"
8
8
 
9
9
 
10
10
  class BrowserRequestContext:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ssb-pubmd
3
- Version: 0.0.12
3
+ Version: 0.0.13
4
4
  Summary: SSB Pubmd
5
5
  License: MIT
6
6
  Author: Olav Landsverk
@@ -55,43 +55,29 @@ Description-Content-Type: text/markdown
55
55
 
56
56
  - Supports logging in through a popup browser window.
57
57
 
58
- ## Requirements
59
-
60
- - This library uses [playwright](https://github.com/microsoft/playwright-python) to create a logged in browser context. This requires installing a [browser binary](https://playwright.dev/python/docs/browsers#install-browsers) and necessary [system dependencies](https://playwright.dev/python/docs/browsers#install-system-dependencies).
61
58
 
62
59
  ## Installation
63
60
 
64
- You can install _SSB Pubmd_ via [pip] from [PyPI]:
61
+ Installation with pip:
65
62
 
66
63
  ```console
67
64
  pip install ssb-pubmd
68
65
  ```
69
66
 
70
- ## Usage
71
-
72
- First set environment variables:
67
+ If you need to create a logged-in browser context, you will also need to install a [Playwright browser](https://playwright.dev/python/docs/browsers#install-browsers):
73
68
 
74
69
  ```console
75
- export PUBMD_LOGIN_URL=<https://www.example.com/login>
76
- export PUBMD_POST_URL=<https://www.example.com/post>
70
+ playwright install --with-deps chromium`
77
71
  ```
78
72
 
79
- To log in, run:
80
-
81
- ```console
82
- pubmd login
83
- ```
84
-
85
- Close the popup browser window when you are logged in.
73
+ ## Usage
86
74
 
87
- To synchronize markdown content to the CMS server, run:
75
+ Run the main command in a terminal to see available subcommands with documentation:
88
76
 
89
77
  ```console
90
- pubmd sync <file>
78
+ pubmd
91
79
  ```
92
80
 
93
- `<file>` should be an absolute or relative path, and the allowed extensions are `.ipynb` and `md`.
94
-
95
81
  ## Contributing
96
82
 
97
83
  Contributions are very welcome.
@@ -0,0 +1,10 @@
1
+ ssb_pubmd/__init__.py,sha256=WD-U43QQTQIRSRgTHSnEjcG5MuH4T_CPFHPXols2NLk,179
2
+ ssb_pubmd/__main__.py,sha256=a99fscfnw6rr2fOG4KFsCzZnSzo2eo94xpX7vyLImV8,2611
3
+ ssb_pubmd/browser_context.py,sha256=zNT-YehZh00uG8f4KGr3KbXIFOE84_7Ky4HjOmxN4zs,2350
4
+ ssb_pubmd/markdown_syncer.py,sha256=RHP3bHIGPRLichrleygOS2WIVN1KOlYPehbrcenJMRk,7631
5
+ ssb_pubmd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ ssb_pubmd-0.0.13.dist-info/LICENSE,sha256=tF5bnYv09fgH5ph9t1EpH1MGrVOGTQeswL4dzVeZ_ak,1073
7
+ ssb_pubmd-0.0.13.dist-info/METADATA,sha256=P05Hv5mkPm8z0dF63GMhfE7PZdUr4u8uWylv-WvvXWU,4208
8
+ ssb_pubmd-0.0.13.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
9
+ ssb_pubmd-0.0.13.dist-info/entry_points.txt,sha256=1_NfsiOfqTg948JWXYPwi4QtDk90KHkNn1CQtye8rJ0,48
10
+ ssb_pubmd-0.0.13.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- ssb_pubmd/__init__.py,sha256=WD-U43QQTQIRSRgTHSnEjcG5MuH4T_CPFHPXols2NLk,179
2
- ssb_pubmd/__main__.py,sha256=WdiICEorWrTbM1NDIkG-97Gg49IV5Pm_MBkQHr3Scec,1364
3
- ssb_pubmd/browser_context.py,sha256=JXDlvUJZ-NYLQlE0_MRAiuRxGrMVBfvm5Rt2QX7dYRA,2344
4
- ssb_pubmd/markdown_syncer.py,sha256=RHP3bHIGPRLichrleygOS2WIVN1KOlYPehbrcenJMRk,7631
5
- ssb_pubmd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- ssb_pubmd-0.0.12.dist-info/LICENSE,sha256=tF5bnYv09fgH5ph9t1EpH1MGrVOGTQeswL4dzVeZ_ak,1073
7
- ssb_pubmd-0.0.12.dist-info/METADATA,sha256=6YfXG5dXzW-2xU-Cdbtik5-ophdBRngUsSbBJ_DVYkw,4707
8
- ssb_pubmd-0.0.12.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
9
- ssb_pubmd-0.0.12.dist-info/entry_points.txt,sha256=1_NfsiOfqTg948JWXYPwi4QtDk90KHkNn1CQtye8rJ0,48
10
- ssb_pubmd-0.0.12.dist-info/RECORD,,