import nfc, nfc.snep import threading import argparse def send_uri(llc, uri): snep = nfc.snep.SnepClient(llc) snep.put(nfc.ndef.Message(nfc.ndef.UriRecord(uri))) class Main(object): def __init__(self): parser = argparse.ArgumentParser() parser.add_argument("address", help="bitcoin receiver address") parser.add_argument("amount", type=float, help="amount to send") args = parser.parse_args() self.uri = "bitcoin:{address}?amount={amount}".format( address=args.address, amount=args.amount) def on_connect(self, llc): threading.Thread(target=send_uri, args=(llc, self.uri)).start() return llc def run(self): clf = nfc.ContactlessFrontend('usb') clf.connect(llcp={'on-connect': self.on_connect}) if __name__ == '__main__': Main().run()