-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from n0-computer/arqu/python
feat(py): added basic example
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,5 +105,7 @@ docs/_build/ | |
.python-version | ||
|
||
# Go | ||
go/iroh-node-go | ||
|
||
go/iroh-node-go | ||
# Python | ||
python/iroh-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import iroh | ||
|
||
import argparse | ||
import os | ||
import time | ||
|
||
IROH_DATA_DIR = "./iroh-data" | ||
|
||
if __name__ == "__main__": | ||
|
||
# parse arguments | ||
parser = argparse.ArgumentParser(description='Python Iroh Node Demo') | ||
parser.add_argument('--ticket', type=str, help='ticket to join a document') | ||
|
||
args = parser.parse_args() | ||
|
||
if not args.ticket: | ||
print("Please provide a ticket to join a document") | ||
exit() | ||
|
||
# create iroh data dir if it does not exists | ||
if not os.path.exists(IROH_DATA_DIR): | ||
os.mkdir(IROH_DATA_DIR) | ||
|
||
# create iroh node | ||
node = iroh.IrohNode(IROH_DATA_DIR) | ||
print("Started Iroh node: {}".format(node.node_id())) | ||
|
||
# join doc | ||
doc_ticket = iroh.DocTicket.from_string(args.ticket) | ||
doc = node.doc_join(doc_ticket) | ||
print("Joined doc: {}".format(doc.id())) | ||
|
||
# sync & print | ||
print("Waiting 5 seconds to let stuff sync...") | ||
time.sleep(5) | ||
keys = doc.keys() | ||
print("Data:") | ||
for key in keys: | ||
content = doc.get_content_bytes(key) | ||
print("{} : {} (hash: {})".format(key.key(), content.decode("utf8"), key.hash().to_string())) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
iroh==0.2.0 |