-
-
Save hhff/f577cc4421ce842b4e1eaf6205e654e8 to your computer and use it in GitHub Desktop.
Export Uber trips from https://riders.uber.com/trips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
var map = { | |
pickup: 1, | |
driver: 2, | |
fare: 3, | |
car: 4, | |
city: 5, | |
payment_method: 6 | |
}; | |
var mytrips = []; | |
function getTripStatus(target) { | |
if ($(target).find('.trip-expand--canceled').length) { | |
return 'Canceled'; | |
} | |
if ($(target).find('.trip-expand--completed').length) { | |
return 'Completed'; | |
} | |
return 'Unknown'; | |
} | |
function fetchPage(pageNumber){ | |
$.get('/trips?page='+pageNumber, function(result){ | |
var data = $(result).find('.trip-expand__origin'); | |
data.each(function(i, el){ | |
var _el = $(el); | |
var _eltd = _el.find('td'); | |
var _object = {}; | |
var _eltarget = _el.data('target'); | |
_object.trip_id = _eltarget.replace('#trip-', ''); | |
_object.trip_status = getTripStatus(_eltarget); | |
for(prop in map){ | |
_object[prop] = _eltd.eq(map[prop]).text(); | |
} | |
if (_object.trip_status == "Completed") { | |
var _eldetails = _el.next(); | |
_object.time_of_pickup = _eldetails.find(_eltarget + "-expand h6").eq(0).text(); | |
_object.pickup_location = _eldetails.find(_eltarget + "-expand .trip-address h6").eq(0).text(); | |
_object.time_of_arrival = _eldetails.find(_eltarget + "-expand .trip-address p.flush").eq(1).text(); | |
_object.destination = _eldetails.find(_eltarget + "-expand .trip-address h6").eq(1).text(); | |
_object.rating = _eldetails.find(_eltarget + "-ratings .tooltip").text(); | |
} | |
mytrips.push(_object); | |
}); | |
if(data.length > 0){ | |
return fetchPage(pageNumber+1); | |
} | |
}); | |
} | |
fetchPage(1); | |
// hackety-hack | |
window.trips = mytrips; | |
return mytrips; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment