Skip to content

Instantly share code, notes, and snippets.

@yitznewton
Last active October 17, 2023 05:55
Show Gist options
  • Save yitznewton/7d3aa31ef5009c2992f6c318a513f895 to your computer and use it in GitHub Desktop.
Save yitznewton/7d3aa31ef5009c2992f6c318a513f895 to your computer and use it in GitHub Desktop.
let datetime = (date) => {
return [
date.getMonth() + 1,
'/',
date.getDate(),
'/',
date.getFullYear(),
' ',
date.getHours(),
':',
date.getMinutes(),
':',
date.getSeconds()
].join('')
};
let geolocation = (data, status) => {
return data.route.breakdown.reduce((ret, current) => {
if (current.status == status) {
return [current.lat, current.lng];
}
return ret;
}, []);
};
let uberExtract = (raw) => {
let tripData = JSON.parse(raw).data.tripDetails;
let fields = [
'Uber',
tripData.total,
tripData.duration,
tripData.distance,
datetime(new Date(tripData.requestAt * 1000)),
tripData.pickupAddress,
tripData.dropoffAddress,
tripData.totalToll
];
window.prompt('Copy it', fields.join("\t"));
};
let lyftExtract = (string) => {
let data = JSON.parse(string);
let tripData = data.order;
let fields = [
'Lyft',
tripData.payment_breakdown[tripData.payment_breakdown.length - 1].amount / 100,
tripData.duration_seconds,
tripData.route_distance.value,
datetime(new Date(tripData.first_request_timestamp_ms)),
'',
'',
tripData.payment_breakdown.reduce((ret, current) => {
if (current.description == 'Tolls') {
return current.amount / 100;
}
return ret;
}, 0) || '',
'',
geolocation(data, 'pickedUp')[0],
geolocation(data, 'pickedUp')[1]
];
window.prompt('Copy it', fields.join("\t"));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment