Exemplo n.º 1
0
 def test_detect_mifare_absent(self):
     """Test that an absent card results in a None response.
     
     Either this test or the "present" test above will pass, but never both.
     """
     import nxppy
     self.assertIsNone(nxppy.read_mifare(), "Card UID is not None")
Exemplo n.º 2
0
 def test_detect_mifare_present(self):
     """Test that we can read the UID from a present Mifare card.
     
     Either this test or the "absent" test below will pass, but never both.
     """
     import nxppy
     self.assertIsInstance(nxppy.read_mifare(), str, "Card UID is not a string")
Exemplo n.º 3
0
 def ReadCard(self):
     id=nxppy.read_mifare()
     m = nxppy.Mifare()
     if id == None:
         return None
     else:
         if id not in self.people.keys():
             print "new ID :", id
             name=raw_input('Please enter your name:')
             self.people[id]={"name":name,"achievements":[]}
         else:
             for aid in self.achievements.keys():
                 if int(aid) not in self.people[id]['achievements']:
                     if self.achievements[aid]['question']==None:
                         self.people[id]['achievements'].append(aid)
                         print "Achievement unlocked!"
                     else:
                         print "Achievement available: answer the following question to win "+self.achievements[aid]["Description"]+":"
                         print self.achievements[aid]['question']
                         ans=[]
                         for a in range(len(self.achievements[aid]['answers'])):
                             answer=raw_input('Enter answer:')
                             ans.append(answer)
                         correct=0
                         for an in range(len(ans)):
                             found=False
                             for answ in self.achievements[aid]['answers']:
                                 if answ==ans[an]:
                                     found=True
                                     break
                             if not found:
                                 print "answer "+ans[an]+" incorrect!"
                             else:
                                 correct+=1
                         if correct == len(self.achievements[aid]['answers']):
                             print "achievement unlocked!"
                             self.people[id]['achievements'].append(aid)
         self.SavePeople()
         return self.people[id]