Skip to content

Commit 087c293

Browse files
committed
clis use getpass
1 parent 48e986e commit 087c293

2 files changed

Lines changed: 10 additions & 21 deletions

File tree

examples/basic_usage.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Basic usage of the stackcoin library."""
22

33
import asyncio
4+
import getpass
45
import os
56

67
import stackcoin
@@ -13,12 +14,8 @@ async def main(token: str, base_url: str):
1314
print(f"Logged in as {me.username} with balance {me.balance} STK")
1415

1516
# Create a request
16-
req = await client.create_request(
17-
to_user_id=2, amount=100, label="pay up buddy"
18-
)
19-
print(
20-
f"Created request #{req.request_id} to {req.responder.username} for {req.amount} STK"
21-
)
17+
req = await client.create_request(to_user_id=2, amount=100, label="pay up buddy")
18+
print(f"Created request #{req.request_id} to {req.responder.username} for {req.amount} STK")
2219

2320
# List pending requests
2421
requests = await client.get_requests()
@@ -30,9 +27,7 @@ async def main(token: str, base_url: str):
3027
transactions = await client.get_transactions()
3128
print(f"\n{len(transactions)} transaction(s):")
3229
for txn in transactions:
33-
print(
34-
f" #{txn.id} {txn.from_.username} -> {txn.to.username}: {txn.amount} STK"
35-
)
30+
print(f" #{txn.id} {txn.from_.username} -> {txn.to.username}: {txn.amount} STK")
3631

3732
# List users
3833
users = await client.get_users()
@@ -44,7 +39,7 @@ async def main(token: str, base_url: str):
4439
if __name__ == "__main__":
4540
token = os.getenv("STACKCOIN_BOT_TOKEN")
4641
if not token:
47-
token = input("Enter your bot token: ").strip()
42+
token = getpass.getpass("Enter your bot token: ").strip()
4843
if not token:
4944
print("Token is required")
5045
exit(1)

examples/simple_cli.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import asyncio
9+
import getpass
910
import os
1011
import sys
1112

@@ -98,10 +99,7 @@ async def handle_command(client: stackcoin.Client, line: str):
9899
txns = await client.get_transactions()
99100
for t in txns[:10]:
100101
label_str = f" ({t.label})" if t.label else ""
101-
print(
102-
f" #{t.id} {t.from_.username} -> {t.to.username}: "
103-
f"{t.amount} STK{label_str}"
104-
)
102+
print(f" #{t.id} {t.from_.username} -> {t.to.username}: {t.amount} STK{label_str}")
105103
print(f"({len(txns)} total)")
106104

107105
elif cmd == "events":
@@ -129,7 +127,7 @@ async def read_stdin_lines(queue: asyncio.Queue[str | None]):
129127
async def main():
130128
token = os.getenv("STACKCOIN_BOT_TOKEN")
131129
if not token:
132-
token = input("Enter your bot token: ").strip()
130+
token = getpass.getpass("Enter your bot token: ").strip()
133131
if not token:
134132
print("Token is required")
135133
return
@@ -154,9 +152,7 @@ async def main():
154152
@gateway.on("transfer.completed")
155153
async def on_transfer(event: stackcoin.TransferCompletedEvent):
156154
if event.data.role == "sender":
157-
print(
158-
f"\n [event] Sent {event.data.amount} STK to user #{event.data.to_id}"
159-
)
155+
print(f"\n [event] Sent {event.data.amount} STK to user #{event.data.to_id}")
160156
else:
161157
print(
162158
f"\n [event] Received {event.data.amount} STK from user #{event.data.from_id}"
@@ -165,9 +161,7 @@ async def on_transfer(event: stackcoin.TransferCompletedEvent):
165161

166162
@gateway.on("request.created")
167163
async def on_request_created(event: stackcoin.RequestCreatedEvent):
168-
print(
169-
f"\n [event] New request #{event.data.request_id} for {event.data.amount} STK"
170-
)
164+
print(f"\n [event] New request #{event.data.request_id} for {event.data.amount} STK")
171165
print("> ", end="", flush=True)
172166

173167
@gateway.on("request.accepted")

0 commit comments

Comments
 (0)