flight_circle.py
def update_checkout_dates(self, fbo_id, make_and_model, get_new_checkout_date_and_expiration_func):
        """
        Function calls get_new_checkout_date_and_expiration_func for every user with a valid checkout 
        recorded for make & model. 

        Args: 
            fbo_id: 
            make_and_model: 
            get_new_checkout_date_and_expiration_func: A reference to a function to be called to 
                get a new checkout date and expiration days
                def func(last_name, first_name, email, groups, checkout) returns ((timestamp)checkoutdate, (int) days_valid)
        """
        users = self.get_users(fbo_id)
        for user in users:
            if ('aircraft_checkouts' in user and user["aircraft_checkouts"] != None):
                checkouts = json.loads(user["aircraft_checkouts"])
                for checkout in checkouts:
                    if (checkout["Make_Model"] == make_and_model):
                        groups = None
                        if ('groups' in user):
                            groups = user['groups']
                        (checkout_date, days_valid) = get_new_checkout_date_and_expiration_func(user['last_name'], 
                                                                                                user['first_name'], 
                                                                                                user['email'], 
                                                                                                groups, 
                                                                                                checkout)
                        if (checkout_date != None and days_valid != None):
                            #print ("Update checkout date")
                            url = "%s/%s" % (FlightCircle.__users_url__, user["CustomerID"])
                            params = {"csrfToken": self.csrf_token,
                                      "FboID": fbo_id
                                     }
                            checkout_date = checkout_date.replace(hour=0, minute=0, second=0, microsecond=0)
                            expires_date = checkout_date + datetime.timedelta(days=days_valid)
                            checkout["checkout_expires_specfic"] = str(days_valid)
                            checkout["checkout_date"] = int(checkout_date.timestamp())
                            checkout["checkout_expires_date"] = expires_date.strftime("%Y-%m-%d 00:00:00")
                            checkout["checkout_expires"] = "Specify"

                            formated_checkout = str(checkouts)
                            formated_checkout = formated_checkout.replace("'", '\\"').replace(': ', ':').replace(', ', ',')
                            payload = "{\"aircraft_checkouts\":\"%s\"}" % (formated_checkout)
                            #print (url)
                            #print (params)
                            #print (payload)
                            r = self.session.put(url, 
                                                 headers=FlightCircle.__default_headers__, 
                                                 params = params, 
                                                 data = str(payload))
                            json_result = json.loads(r.text)
                            if ('status' in json_result and json_result['status'] != 200):
                                raise Exception("Unable to update checkout for %s %s" % (user['last_name'],user['first_name']))
                            if (len(json_result) != 1): 
                                raise Exception("Unable to update checkout for %s %s" % (user['last_name'],user['first_name']))

        Function calls get_new_checkout_date_and_expiration_func for every user with a valid checkout 
        recorded for make & model. 

        Args: 
            fbo_id: 
            make_and_model: 
            get_new_checkout_date_and_expiration_func: A reference to a function to be called to 
                get a new checkout date and expiration days
                def func(last_name, first_name, email, groups, checkout) returns ((timestamp)checkoutdate, (int) days_valid)
        
Function calls get_new_checkout_date_and_expiration_func for every user with a valid checkout
recorded for make & model.
Function calls get_new_checkout_date_and_expiration_func for every user with a valid checkout recorded for make & model .
def update_checkout_dates(self, fbo_id, make_and_model, get_new_checkout_date_and_expiration_func):
        users = self.get_users(fbo_id)
        for user in users:
            if ('aircraft_checkouts' in user and user["aircraft_checkouts"] != None):
                checkouts = json.loads(user["aircraft_checkouts"])
                for checkout in checkouts:
                    if (checkout["Make_Model"] == make_and_model):
                        groups = None
                        if ('groups' in user):
                            groups = user['groups']
                        (checkout_date, days_valid) = get_new_checkout_date_and_expiration_func(user['last_name'], 
                                                                                                user['first_name'], 
                                                                                                user['email'], 
                                                                                                groups, 
                                                                                                checkout)
                        if (checkout_date != None and days_valid != None):
                            url = "%s/%s" % (FlightCircle.__users_url__, user["CustomerID"])
                            params = {"csrfToken": self.csrf_token,
                                      "FboID": fbo_id
                                     }
                            checkout_date = checkout_date.replace(hour=0, minute=0, second=0, microsecond=0)
                            expires_date = checkout_date + datetime.timedelta(days=days_valid)
                            checkout["checkout_expires_specfic"] = str(days_valid)
                            checkout["checkout_date"] = int(checkout_date.timestamp())
                            checkout["checkout_expires_date"] = expires_date.strftime("%Y-%m-%d 00:00:00")
                            checkout["checkout_expires"] = "Specify"
                            formated_checkout = str(checkouts)
                            formated_checkout = formated_checkout.replace("'", '\\"').replace(': ', ':').replace(', ', ',')
                            payload = "{\"aircraft_checkouts\":\"%s\"}" % (formated_checkout)
                            r = self.session.put(url, 
                                                 headers=FlightCircle.__default_headers__, 
                                                 params = params, 
                                                 data = str(payload))
                            json_result = json.loads(r.text)
                            if ('status' in json_result and json_result['status'] != 200):
                                raise Exception("Unable to update checkout for %s %s" % (user['last_name'],user['first_name']))
                            if (len(json_result) != 1): 
                                raise Exception("Unable to update checkout for %s %s" % (user['last_name'],user['first_name']))
def update_checkout_dates ( self , fbo_id , make_and_model , get_new_checkout_date_and_expiration_func ) : users = self . get_users ( fbo_id ) for user in users : if ( 'aircraft_checkouts' in user and user [ "aircraft_checkouts" ] != None ) : checkouts = json . loads ( user [ "aircraft_checkouts" ] ) for checkout in checkouts : if ( checkout [ "Make_Model" ] == make_and_model ) : groups = None if ( 'groups' in user ) : groups = user [ 'groups' ] ( checkout_date , days_valid ) = get_new_checkout_date_and_expiration_func ( user [ 'last_name' ] , user [ 'first_name' ] , user [ 'email' ] , groups , checkout ) if ( checkout_date != None and days_valid != None ) : url = "%s/%s" % ( FlightCircle . __users_url__ , user [ "CustomerID" ] ) params = { "csrfToken" : self . csrf_token , "FboID" : fbo_id } checkout_date = checkout_date . replace ( hour = 0 , minute = 0 , second = 0 , microsecond = 0 ) expires_date = checkout_date + datetime . timedelta ( days = days_valid ) checkout [ "checkout_expires_specfic" ] = str ( days_valid ) checkout [ "checkout_date" ] = int ( checkout_date . timestamp ( ) ) checkout [ "checkout_expires_date" ] = expires_date . strftime ( "%Y-%m-%d 00:00:00" ) checkout [ "checkout_expires" ] = "Specify" formated_checkout = str ( checkouts ) formated_checkout = formated_checkout . replace ( "'" , '\\"' ) . replace ( ': ' , ':' ) . replace ( ', ' , ',' ) payload = "{\"aircraft_checkouts\":\"%s\"}" % ( formated_checkout ) r = self . session . put ( url , headers = FlightCircle . __default_headers__ , params = params , data = str ( payload ) ) json_result = json . loads ( r . text ) if ( 'status' in json_result and json_result [ 'status' ] != 200 ) : raise Exception ( "Unable to update checkout for %s %s" % ( user [ 'last_name' ] , user [ 'first_name' ] ) ) if ( len ( json_result ) != 1 ) : raise Exception ( "Unable to update checkout for %s %s" % ( user [ 'last_name' ] , user [ 'first_name' ] ) )
Function calls get_new_checkout_date_and_expiration_func for every user with a valid checkout
recorded for make & model.
Function calls get_new_checkout_date_and_expiration_func for every user with a valid checkout recorded for make & model .
"""
        Function calls get_new_checkout_date_and_expiration_func for every user with a valid checkout 
        recorded for make & model. 

        Args: 
            fbo_id: 
            make_and_model: 
            get_new_checkout_date_and_expiration_func: A reference to a function to be called to 
                get a new checkout date and expiration days
                def func(last_name, first_name, email, groups, checkout) returns ((timestamp)checkoutdate, (int) days_valid)
        """ #print ("Update checkout date") #print (url) #print (params) #print (payload)
self
fbo_id
None
make_and_model
None
get_new_checkout_date_and_expiration_func
A reference to a function to be called to
get a new checkout date and expiration days
def func(last_name, first_name, email, groups, checkout) returns ((timestamp)checkoutdate, (int) days_valid)
A reference to a function to be called to get a new checkout date and expiration days def func ( last_name first_name email groups checkout ) returns (( timestamp ) checkoutdate ( int ) days_valid )