Skip to content

Instantly share code, notes, and snippets.

@charlesponti
Forked from chernjie/ubertrips.js
Created October 8, 2017 18:04
Show Gist options
  • Save charlesponti/156e046bd708e7103e7091f0678aa2fd to your computer and use it in GitHub Desktop.
Save charlesponti/156e046bd708e7103e7091f0678aa2fd to your computer and use it in GitHub Desktop.
Export Uber trips from https://riders.uber.com/trips
(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