Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/baudtack/urlock-py
https://github.com/baudtack/urlock-py
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/baudtack/urlock-py
- Owner: baudtack
- License: mit
- Created: 2020-06-02T00:30:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-04T17:44:27.000Z (almost 4 years ago)
- Last Synced: 2024-10-01T07:11:30.452Z (3 months ago)
- Language: Python
- Size: 5.86 KB
- Stars: 28
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-urbit - Python
README
# Urlock-py
Urlock-py is a python library for connecting to a running urbit ship.
It consists of a single class `Urlock`. Methods are below.
`__init__(url, code)`
Constructor
`url` - url to the http interface of the running ship
`code` - the `+code` of the ship, should never be published
`connect()`
Connect to the running ship
`poke(ship, app, mark, j)`
`ship` - ship to send the poke
`app` - gall application to send the poke to
`mark` - mark of data sent to the gall application
`j` - json poke data
`ack(eventId)`
Send an acknowledgment of receipt of a message so it's cleared from the ship's queue
`eventId` - id of the event to acknowledge
`sse_pipe()`
returns the sseclient object
`subscribe(ship, app, path)`
`ship` - ship on which the gall application lives
`app` - gall application to subscribe to
`path` - path to subscribe on
Follows is a simple script to send a message and subscribe to a chat channel. The specifics require an understanding of the `chat-store` and `chat-hook` interfaces.
```
#!/usr/bin/python3import urlock
import baseconvert
import time
import random
import dumperzod = urlock.Urlock("http://localhost:8080", "lidlut-tabwed-pillex-ridrup")
r = zod.connect()
s = zod.subscribe("zod", "chat-store", "/mailbox/~/~zod/mc")pipe = zod.sse_pipe()
s = baseconvert.base(random.getrandbits(128), 10, 32, string=True).lower()
uid = '0v' + '.'.join(s[i:i+5] for i in range(0, len(s), 5))[::-1]p = zod.poke("zod", "chat-hook", "json", {"message": {"path": "/~/~zod/mc",
"envelope": {"uid": uid,
"number": 1,
"author": "~zod",
"when": int(time.time() * 1000),
"letter": {"text": "hello world!"}}}})for m in pipe.events():
dumper.dump(m)
dumper.dump(zod.ack(int(m.id)))
```