Skip to content

Instantly share code, notes, and snippets.

@tak-km
Created May 16, 2017 05:48
Show Gist options
  • Save tak-km/a77633a67a78837205711477b654e068 to your computer and use it in GitHub Desktop.
Save tak-km/a77633a67a78837205711477b654e068 to your computer and use it in GitHub Desktop.
readNFC
import binascii
import nfc
import pandas as pd
import urllib
import urllib2
class MyCardReader(object):
def on_connect(self, tag):
print "touched"
self.idm = binascii.hexlify(tag.idm)
return True
def read_id(self):
clf = nfc.ContactlessFrontend('usb')
try:
clf.connect(rdwr={'on-connect': self.on_connect})
finally:
clf.close()
if __name__ == '__main__':
cr = MyCardReader()
while True:
list_df = pd.read_csv('list.csv')
mode = raw_input()
if mode == "q":
break
else:
print "touch card:"
cr.read_id()
idlen = len(list_df[list_df["id"].str.contains(cr.idm)])
if idlen!=0:
exist = list_df[list_df["id"].str.contains(cr.idm)]
#print exist["name"].index[0]
name = exist["name"][exist["name"].index[0]]
#print exist["name"][0]
else:
name = cr.idm
print "released: " + name
url = "..."
params = { "comment" :name}
params = urllib.urlencode(params)
req = urllib2.Request(url)
req.add_data(params)
res = urllib2.urlopen(req)
r = res.read()
#print r
#print cr.idm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment