diff --git a/README.md b/README.md new file mode 100644 index 0000000..da14db3 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# lunduke-cli + +A simple python api client for discourse, designed explicitly +for the lunduke discourse message board, but it could be used +with any discourse message board. + +## Requirements + +* Python 3.12 (or better) +* Poetry 2.0 (or better) + +Poetry's pyproject.toml handles all other requirements. + +## Initialization + +```shell +$ poetry install +``` + +## Usage + +See the "examples" directory. However, there are some +additional notes you will need, in order to make it work. + +First, a `keys` directory at the root of the project, where +you will store a user api key you have already generated. A +well formed api key should look something like this: + +``` +X4ktxE5tsvC+RcvjF9Pa1N//PWTgjAF1xx5UcuaHFVKu84A14n6stDheUxxx +xxx8xxxUbpVN3xOtDxxIg5sU4ZjAZ+LRyKxU9+ikQMqno4Spqb9SOrclxxxx +5Lo/6xkBB/xM9/Rxxx3I0ZAcvurYeIHkVQmSigmaPMJBjx/MKLMGdlVOq+is +mxu7qTQcl85E5k0MC86LNr5Ds4xUQXgIGVGVICxxxUMr2VxxxD9tglgG+9sL +VYFehH4HxxPxx67XRfrq8WxZjYRMHcWaGO4O03lQZwPEpIz7aL6D6wPNdCaq +nH9ivM/3MdEUOQZQuh8R+XJ9Ik7RlTLNVxx8bxTJ2X== +``` + +Second, you will need a file called `config.toml` in the root +of the project. That file should look like this: + +```ini +[user] +username = "joe-doakes" + +[api] +key_file = "cli_key.txt" +host = "forum.wherever.com" +``` + +Then, you can run the test scripts either with or without +poetry support: + +```shell +$ poetry run python examples/check-key.py # for example + +$ python examples/example.py # for example +``` + diff --git a/config/create_config.py b/config/create_config.py index 0161edf..779de30 100644 --- a/config/create_config.py +++ b/config/create_config.py @@ -1,5 +1,5 @@ import os - +from io import StringIO import toml @@ -14,13 +14,18 @@ def create_sample_config(config_path="config.toml"): "username": "joe_doakes" }, "api": { - "key_file": "../keys/cli_key.txt", + "key_file": "cli_key.txt", "host": "discourse.forum.com" } } + buffer = StringIO() + toml.dump(config_data, buffer) with open(config_path, "w") as config_file: - toml.dump(config_data, config_file) + config_file.write(buffer.getvalue()) + +# with open(config_path, "w") as config_file: +# toml.dump(config_data, config_file) # type: ignore print(f"Created sample configuration file: {config_path}") diff --git a/examples/example.py b/examples/example.py index 08f50b2..fdc75f1 100644 --- a/examples/example.py +++ b/examples/example.py @@ -6,7 +6,6 @@ from lunduke.client import DiscourseClient def main(): config_data = Config() - print(config_data) # Set up configuration config = DiscourseConfig( diff --git a/pyproject.toml b/pyproject.toml index 283e670..8d47f32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,18 +1,19 @@ -[project] +[tool.poetry] name = "lunduke-cli" version = "0.1.0" description = "An API client for the Lunduke Discourse server" -authors = [ - {name = "Greg Gauthier",email = "gmgauthier@protonmail.com"} -] +authors = ["Greg Gauthier "] readme = "README.md" -requires-python = ">=3.12" -dependencies = [ - "requests (>=2.32.3,<3.0.0)", - "toml (>=0.10.2, <1.0.0)" +packages = [ + {include = "config"}, + {include = "lunduke"} ] +[tool.poetry.dependencies] +python = ">=3.12" +requests = ">=2.32.3,<3.0.0" +toml = ">=0.10.2, <1.0.0" [build-system] requires = ["poetry-core>=2.0.0,<3.0.0"] -build-backend = "poetry.core.masonry.api" +build-backend = "poetry.core.masonry.api" \ No newline at end of file