Skip to content

Instantly share code, notes, and snippets.

@benjaminchodroff
Created June 30, 2022 13:55
Show Gist options
  • Save benjaminchodroff/f851b42e2c0cd23e824fae0eb89a1f83 to your computer and use it in GitHub Desktop.
Save benjaminchodroff/f851b42e2c0cd23e824fae0eb89a1f83 to your computer and use it in GitHub Desktop.
Turn a list of POAP claim URLs into a NXP TagWriter json-like format for iPhone NFC ntag213
import ndef
import sys
# The NXP app expects an exact format of the following, including whitespace and quotes
#[
# {
# "type" : "55",
# "mirrorparameters" : "",
# "date" : 1655959791718,
# "bytes" : "03504f41502e78797a2f636c61696d2f7075676a6173",
# "id" : 1,
# "tnf" : "01",
# "title" : ""
# }
#]
if(len(sys.argv) <= 1):
print("Must specify a POAP file")
sys.exit(1)
print("Opening POAP file:",sys.argv[1])
poapfile = open(sys.argv[1],'r')
nfcfile=open(sys.argv[1]+".json","w")
nfcfile.write("[\n ")
lines = poapfile.readlines()
first=True
for line in lines:
record1 = ndef.UriRecord(line.strip())
poaphex=record1.data.hex()
if(not first):
nfcfile.write(",\n ")
nfcfile.write("{\n \"type\" : \"55\",\n \"mirrorparameters\" : \"\",\n \"date\" : 1655959791718,\n \"bytes\" : \""+poaphex+"\",\n \"id\" : 1,\n \"tnf\" : \"01\",\n \"title\" : \"\"\n }")
first=False
nfcfile.write("\n]\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment