route_distances/distances.py
def rate_limit(self):
        """ Handles rate limiting, holding up the script if necessary """

        self.requests_this_period += 1

        # Don't sleep on the first request
        if (self.period_start is None):
            self.period_start = time.time()
        else:
            time.sleep(self.request_delay)

        if (self.requests_this_period >= self.requests_per_period):
            next_period = self.period_start + self.period_length
            time_until_next_period = next_period - time.time()

            print("Reached max requests per period (%d >= %d)" % (
                self.requests_this_period, self.requests_per_period
            ))
            print("Sleeping %d seconds until next period (%s)" % (
                time_until_next_period,
                datetime.datetime.fromtimestamp(next_period).isoformat()
            ))

            time.sleep(time_until_next_period)

        if (time.time() >= self.period_start + self.period_length):
            self.period_start = time.time()
            self.requests_this_period = 0
 Handles rate limiting, holding up the script if necessary 
Handles rate limiting, holding up the script if necessary
Handles rate limiting holding up the script if necessary
def rate_limit(self):
        self.requests_this_period += 1
        if (self.period_start is None):
            self.period_start = time.time()
        else:
            time.sleep(self.request_delay)
        if (self.requests_this_period >= self.requests_per_period):
            next_period = self.period_start + self.period_length
            time_until_next_period = next_period - time.time()
            print("Reached max requests per period (%d >= %d)" % (
                self.requests_this_period, self.requests_per_period
            ))
            print("Sleeping %d seconds until next period (%s)" % (
                time_until_next_period,
                datetime.datetime.fromtimestamp(next_period).isoformat()
            ))
            time.sleep(time_until_next_period)
        if (time.time() >= self.period_start + self.period_length):
            self.period_start = time.time()
            self.requests_this_period = 0
def rate_limit ( self ) : self . requests_this_period += 1 if ( self . period_start is None ) : self . period_start = time . time ( ) else : time . sleep ( self . request_delay ) if ( self . requests_this_period >= self . requests_per_period ) : next_period = self . period_start + self . period_length time_until_next_period = next_period - time . time ( ) print ( "Reached max requests per period (%d >= %d)" % ( self . requests_this_period , self . requests_per_period ) ) print ( "Sleeping %d seconds until next period (%s)" % ( time_until_next_period , datetime . datetime . fromtimestamp ( next_period ) . isoformat ( ) ) ) time . sleep ( time_until_next_period ) if ( time . time ( ) >= self . period_start + self . period_length ) : self . period_start = time . time ( ) self . requests_this_period = 0
Handles rate limiting, holding up the script if necessary
Handles rate limiting holding up the script if necessary
""" Handles rate limiting, holding up the script if necessary """ # Don't sleep on the first request
self