magic-wormhole/bin/send_text.py

23 lines
647 B
Python
Raw Normal View History

2015-02-11 09:18:31 +00:00
from __future__ import print_function
2015-02-11 00:50:32 +00:00
import sys, json
2015-02-20 08:32:48 +00:00
from wormhole.blocking.transcribe import Initiator, WrongPasswordError
2015-02-11 00:50:32 +00:00
APPID = "lothar.com/wormhole/text-xfer"
# we're sending
message = sys.argv[1]
data = json.dumps({"message": message,
2015-02-11 00:50:32 +00:00
}).encode("utf-8")
i = Initiator(APPID, data)
code = i.get_code()
print("On the other computer, please run: receive_text")
print("Wormhole code is: %s" % code)
2015-02-11 09:18:31 +00:00
print("")
2015-02-20 08:32:48 +00:00
try:
them_bytes = i.get_data()
except WrongPasswordError as e:
print("ERROR: " + e.explain(), file=sys.stderr)
sys.exit(1)
2015-02-11 00:50:32 +00:00
them_d = json.loads(them_bytes.decode("utf-8"))
print("them: %r" % (them_d,))