예제 #1
0
    def vehicle_price_estimate_from_pcs(self, conn, sessionid, vehicleid, start_time, end_time):
        host = self.__host
        path = self.__price_path
        connector = '&' if '?' in path else '?'

        start_stamp = to_timestamp(start_time)
        end_stamp = to_timestamp(end_time)
        
        query = 'mv_action=add&stack_pk=%s&start_stamp=%s&end_stamp=%s' % \
            (vehicleid, start_stamp, end_stamp)
        
        url = "http://%s%s%s%s" % (host, path, connector, query)
        method = 'GET'
        data = {}
        headers = {'Cookie': 'sid=%s' % sessionid}
        response = \
            conn.request(url, method, data, headers)
        
        return response.read(), response.getheaders()
예제 #2
0
 def request_vehicle_availability_from_pcs(self, conn, sessionid, vehicleid, start_time, end_time):
     if (sessionid, vehicleid, start_time, end_time) not in self._vehicle_cache:
         host = self.__host
         path = self.__vehicle_path
         # The PhillyCarShare servers do not take into account time zone 
         # information in their timestamp calculations, so we have to reverse
         # our timezone info.  However, we have to keep it in the first place
         # because Google's servers aren't necessarily on Eastern time (but 
         # PhillyCarShare always will be).
         start_stamp = to_timestamp(start_time)
         end_stamp = to_timestamp(end_time)
         
         url = 'http://%s%s' % (host, path)
         method = 'POST'
         data = urllib.urlencode({'mv_action':'add',
                 'default[stack_pk]':vehicleid,
                 'default[start_stamp]':str(int(start_stamp)),
                 'default[end_stamp]':str(int(end_stamp))})
         headers = { 'Cookie':'sid=%s' % sessionid }
         response = \
             conn.request(url, method, data, headers)
         
         self._vehicle_cache[(sessionid, vehicleid, start_time, end_time)] = (response.read(), response.getheaders())
     return self._vehicle_cache[(sessionid, vehicleid, start_time, end_time)]