Created
January 10, 2017 12:12
-
-
Save kudarisenmon/65195ae9b076098a47ff4cba0101bb02 to your computer and use it in GitHub Desktop.
nfcpy を使用してLuLuCaの残高を表示する
This file contains hidden or 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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import struct | |
| import nfc | |
| service_code = 0x008b | |
| def connected(tag): | |
| if isinstance(tag, nfc.tag.tt3.Type3Tag): | |
| try: | |
| sc = nfc.tag.tt3.ServiceCode(service_code >> 6, service_code & 0x3f) | |
| bc = nfc.tag.tt3.BlockCode(1, service = 0) | |
| data = tag.read_without_encryption([sc], [bc]) | |
| d = struct.unpack('>cccHcccHcccccc', data) | |
| print "%d" % d[3] | |
| except Exception as e: | |
| print "error: %s" % e | |
| else: | |
| print "error: tag isn't Type3Tag" | |
| if __name__ == "__main__": | |
| clf = nfc.ContactlessFrontend('usb') | |
| clf.connect(rdwr={'on-connect': connected}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment