Changeset 75

Show
Ignore:
Timestamp:
03/30/08 18:36:36 (5 months ago)
Author:
wriewra2
Message:

Stufffsf

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sucrose/trunk/python/api/sucrose.py

    r72 r75  
    3434                return self.trays.filter_by(item_id=id).first().cur_price 
    3535 
     36        def balance_from_uid(self, uid): 
     37                return self.users.filter_by(uid=uid).first().balance 
     38 
    3639        def item_id_from_location(self, location): 
    3740                if not ( ( location[0] in '12345' and location[1] in '1237' ) or 
     
    4548                return self.items.filter_by(item_id=id).first().name 
    4649 
     50#       def increment_consumed_item(self, item_id) 
     51 
    4752        def __init__(self, db, dbonly=False): 
    4853                session = db.session 
  • sucrose/trunk/python/cardswipe.py

    r61 r75  
    1818                normalized = "" 
    1919 
    20                 # Clear the MSB 
     20                # Clear the most significant bit 
    2121                for i in range(0,len(buffer)): 
    2222                        normalized += chr(ord(buffer[i]) & 0x7F) 
     
    2525                        # Get the uin from the card data using David's crazy regex voodoo 
    2626                        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 
    3029                        return False 
    31  
    32                 # Authenticate the UIN 
    3330 
    3431                self.cardreader.timeout = 0.1 
    3532                self.cardreader.read(100) 
    3633 
     34                # Authenticate the UIN 
    3735                return self.sucrose.netid_from_uin(self.uin) 
    3836 
    39  
    4037        def authenticate_purchase(self, location): 
     38                # We do this for now, since there are no real items in sucrose yet. 
    4139                return True 
    4240 
     41                user_id = self.sucrose.uid_from_uin(self.uin) 
    4342                item_id = self.sucrose.item_id_from_location(location) 
    44                 user_id = self.sucrose.uid_from_uin(self.uin) 
    4543                item_cost = self.sucrose.cost_from_id(item_id) 
    4644                 
     
    4947 
    5048                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) 
    5550 
    56                 except Exception
     51                except
    5752                        return False 
    5853 
    5954                if quantity <= 0  or user_balance < item_cost: 
    6055                        return False 
    61                                  
     56 
    6257                return True 
    63  
    6458 
    6559        def record_purchase(self, location): 
     
    6862 
    6963                user_id = self.sucrose.uid_from_uin(self.uin) 
    70                 item_id = self.sucrose.id_from_location(location) 
     64                item_id = self.sucrose.item_id_from_location(location) 
    7165                item_cost = self.sucrose.cost_from_id(item_id) 
    7266         
    73                 if not (user_id and item_id and item_cost): 
     67                if not ( user_id and item_id and item_cost ): 
    7468                        return False 
    7569 
     
    8276                        sucrose.db.integrate.execute(transaction_sql) 
    8377 
    84                 except Exception
     78                except
    8579                        return False 
    8680 
     
    9185                self.sucrose = sucrose 
    9286                self.uin = "" 
     87                return 
    9388 
     89        def __del__(self): 
     90                self.cardreader.close() 
     91                return