Skip to content

Commit

Permalink
documentation updates (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
UTXOnly authored May 12, 2024
1 parent 8bba436 commit 6fd6623
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,42 @@ pip install .


## Usage
Once installed, you can run nostpy-cli from the command line. Below are some examples of how to use the CLI tool:
Once installed, you can run `nostpy-cli` from the command line as shown below:

### Send Event
To send an event, you would use a command similar to the following:

```
nostpy-cli send_event --pubkey "your_public_key" --privkey "your_private_key" --content "your plaintext message" --tags "[['tag1', 'value1']]" --kind 4 --relay "wss://yourrelayurl.com"
nostpy-cli send_event -pubkey "your_public_key_hex" -privkey "your_private_key_hex" -content "your plaintext message" -tags "[['tag1', 'value1']]" -kind 4 --relay "wss://yourrelayurl.com" "wss://yoursecondrelayurl.com"
```
`--pubkey` , `--priv_key` and `--relay` arguments are required, all else are optional

#### Example
* Send a kind 1 event with tags

```
nostpy-cli send_event -pubkey 5ce5b352f1ef76b1dffc5694dd5b34126137184cc9a7d78cba841c0635e17952 -privkey 2b1e4e1f26517dda57458596760bb3bd3bd3717083763166e12983a6421abc18 -content test27 -tags "[
['t', 'vvfdvfd'], ['v', 'v2']]" -kind 1 --relay wss://relay.nostpy.lol wss://relay.damus.io wss://nos.lol
```

* Send a kind 4 direct message
```
nostpy-cli send_event -pubkey 5ce5b352f1ef76b1dffc5694dd5b34126137184cc9a7d78cba841c0635e17952 -privkey 2b1e4e1f26517dda57458596760bb3bd3bd3717083763166e12983a6421abc18 -content "This is my plaintext message" -tags "[['p', '4503baa127bdfd0b054384dc5ba82cb0e2a8367cbdb0629179f00db1a34caacc']]" -kind 4 --relay wss://relay.nostpy.lol wss://relay.damus.io wss://nos.lol
```

### Query Event
To query events, use the following command:

```
nostpy-cli query --kinds "[1,9075]" --relay "wss://yourrelayurl.com"
nostpy-cli query --kinds "[1,9735]" --relay "wss://yourrelayurl.com"
```
`--relay` field required

#### Example
* Query an event with search
```
nostpy-cli query -kinds "[31990,1]" -search "random_search" -since 1713629501 -authors npub1g5pm4gf8hh7skp2rsnw9h2pvkr32sdnuhkcx9yte7qxmrg6v4txqqudjqv --relay wss://relay.nostpy.lol
```
### Help
To view all available commands and their options, use the help command:

Expand Down
2 changes: 1 addition & 1 deletion nostpy_cli/create_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def send_event(self, public_key, private_key_hex, content, kind, tags):
event_data = self.create_event(
public_key, private_key_hex, content, kind, tags
)
for ws_relay in self.relays_kind4:
for ws_relay in self.relays:
async with websockets.connect(ws_relay) as ws:
event_json = ("EVENT", event_data)
print("Sending event:")
Expand Down
6 changes: 4 additions & 2 deletions nostpy_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def handle_send_event(args):


def main():
parser = argparse.ArgumentParser(description="Send events via WebSocket.")
parser = argparse.ArgumentParser(description="Send and query nostr events")
subparsers = parser.add_subparsers(
title="commands", description="valid commands", help="additional help"
)
Expand All @@ -55,7 +55,7 @@ def main():
"-until", "--until", type=int, help="Collect events until"
)
query_parser.add_argument(
"-authors", "--authors", type=ast.literal_eval, help="List of authors e.g. []"
"-authors", "--authors", type=str, help="List of authors e.g. []"
)
query_parser.add_argument(
"-limit",
Expand Down Expand Up @@ -92,6 +92,8 @@ def main():
)
send_event_parser.set_defaults(func=handle_send_event)

parser.epilog = 'Example send usage: nostpy-cli send_event -pubkey "abc123..." -privkey "def456..." -content "Hello, world!" --relay "wss://example.com"'

args = parser.parse_args()
if hasattr(args, "func"):
asyncio.run(args.func(args))
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ build-backend = "setuptools.build_meta"

[project]
name = "nostpy-cli"
version = "0.1.3"

version = "0.2.0"

authors = [{ name = "Brian Hartford", email = "bh419@protonmail.com" }]
description = "CLI tool for handling nostpy events"
readme = "README.md"
Expand Down

0 comments on commit 6fd6623

Please sign in to comment.