import nfc from time import sleep import sys from datetime import datetime def writeUID(UID): if len(sys.argv) >= 2: filename = str(sys.argv[1]) else: filename = "nfclog.txt" f = open(filename, "a") todayandnow = datetime.now() f.write(todayandnow.strftime('%Y-%m-%d %H:%M:%S') + " " + UID + "\n") f.flush() def connected(tag): #print(tag.type) if isinstance(tag, nfc.tag.tt1.Type1Tag): writeUID(str(tag.uid).encode("hex")) elif isinstance(tag, nfc.tag.tt2.Type2Tag): writeUID(str(tag.uid).encode("hex")) elif isinstance(tag, nfc.tag.tt3.Type3Tag): writeUID(str(tag.idm).encode("hex")) elif isinstance(tag, nfc.tag.tt4.Type4Tag): writeUID(str(tag.uid).encode("hex")) else: print("Error, unknown tag type or false read") clf = nfc.ContactlessFrontend('usb') clf.connect(rdwr={'on-connect': connected})