forked from retoor/devplacepy
feat: add plug-and-play devRant API client examples with Python and JavaScript
Add complete set of example scripts for the devRant REST protocol under examples/devrant/, including reusable client libraries, a rant poster, a live feed watcher with keyword-based auto-upvote, and an end-to-end smoke test that exercises every endpoint. Both Python (stdlib-only) and JavaScript (Node 18+ global fetch) implementations are provided.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import sys
|
||||
|
||||
from client import from_env
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if len(sys.argv) < 2:
|
||||
print("usage: DEVRANT_USERNAME=.. DEVRANT_PASSWORD=.. python post_rant.py <text> [tags]")
|
||||
raise SystemExit(1)
|
||||
text = sys.argv[1]
|
||||
tags = sys.argv[2] if len(sys.argv) > 2 else ""
|
||||
api = from_env()
|
||||
api.login()
|
||||
result = api.post_rant(text, tags)
|
||||
if result.get("success"):
|
||||
print(f"posted rant {result['rant_id']}")
|
||||
else:
|
||||
print(f"failed: {result.get('error')}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user