Changeset 75
- Timestamp:
- 03/30/08 18:36:36 (5 months ago)
- Files:
-
- sucrose/trunk/python/api/sucrose.py (modified) (2 diffs)
- sucrose/trunk/python/cardswipe.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sucrose/trunk/python/api/sucrose.py
r72 r75 34 34 return self.trays.filter_by(item_id=id).first().cur_price 35 35 36 def balance_from_uid(self, uid): 37 return self.users.filter_by(uid=uid).first().balance 38 36 39 def item_id_from_location(self, location): 37 40 if not ( ( location[0] in '12345' and location[1] in '1237' ) or … … 45 48 return self.items.filter_by(item_id=id).first().name 46 49 50 # def increment_consumed_item(self, item_id) 51 47 52 def __init__(self, db, dbonly=False): 48 53 session = db.session sucrose/trunk/python/cardswipe.py
r61 r75 18 18 normalized = "" 19 19 20 # Clear the MSB20 # Clear the most significant bit 21 21 for i in range(0,len(buffer)): 22 22 normalized += chr(ord(buffer[i]) & 0x7F) … … 25 25 # Get the uin from the card data using David's crazy regex voodoo 26 26 self.uin = re.search('^!A B\d{4}(\d{9})', normalized).group(1) 27 except Exception: 28 # In the case that we cannot get th UIN, return the empty string to 29 # indicate failure 27 except: 28 # In the case that we cannot get the UIN, return the empty string to indicate failure 30 29 return False 31 32 # Authenticate the UIN33 30 34 31 self.cardreader.timeout = 0.1 35 32 self.cardreader.read(100) 36 33 34 # Authenticate the UIN 37 35 return self.sucrose.netid_from_uin(self.uin) 38 36 39 40 37 def authenticate_purchase(self, location): 38 # We do this for now, since there are no real items in sucrose yet. 41 39 return True 42 40 41 user_id = self.sucrose.uid_from_uin(self.uin) 43 42 item_id = self.sucrose.item_id_from_location(location) 44 user_id = self.sucrose.uid_from_uin(self.uin)45 43 item_cost = self.sucrose.cost_from_id(item_id) 46 44 … … 49 47 50 48 try: 51 user_balance_sql = "SELECT balance FROM vending WHERE uid=" + user_id 52 sucrose.db.integrate.execute(user_balance_sql) 53 result = sucrose.db.integrate.fetchone() 54 user_balance = result[0] 49 user_balance = self.sucrose.balance_from_uid(user_id) 55 50 56 except Exception:51 except: 57 52 return False 58 53 59 54 if quantity <= 0 or user_balance < item_cost: 60 55 return False 61 56 62 57 return True 63 64 58 65 59 def record_purchase(self, location): … … 68 62 69 63 user_id = self.sucrose.uid_from_uin(self.uin) 70 item_id = self.sucrose.i d_from_location(location)64 item_id = self.sucrose.item_id_from_location(location) 71 65 item_cost = self.sucrose.cost_from_id(item_id) 72 66 73 if not ( user_id and item_id and item_cost):67 if not ( user_id and item_id and item_cost ): 74 68 return False 75 69 … … 82 76 sucrose.db.integrate.execute(transaction_sql) 83 77 84 except Exception:78 except: 85 79 return False 86 80 … … 91 85 self.sucrose = sucrose 92 86 self.uin = "" 87 return 93 88 89 def __del__(self): 90 self.cardreader.close() 91 return
