Created
August 5, 2018 22:28
-
-
Save flyingluscas/1036ffe15612e17b42249d76629b6724 to your computer and use it in GitHub Desktop.
Uber Price Estimates
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
const fetch = require('node-fetch') | |
const moment = require('moment') | |
const { delay } = require('bluebird') | |
const { find, pipe, prop, propEq } = require('ramda') | |
const estimateUberPrices = async () => { | |
const addresses = [ | |
{ | |
start_latitude: -23.631316, | |
start_longitude: -46.668384, | |
}, | |
{ | |
end_latitude: -23.597183, | |
end_longitude: -46.688650, | |
}, | |
] | |
const token = process.env.UBER_TOKEN | |
const estimateUrl = `https://api.uber.com/v1.2/estimates/price?start_latitude=${addresses[0].start_latitude}&start_longitude=${addresses[0].start_longitude}&end_latitude=${addresses[1].end_latitude}&end_longitude=${addresses[1].end_longitude}` | |
let estimate | |
const desiredPrice = 15 | |
while (estimate === undefined) { | |
const response = await fetch(estimateUrl, { | |
headers: { Authorization: `Token ${token}` }, | |
}) | |
const body = await response.json() | |
const uberX = pipe( | |
prop('prices'), | |
find(propEq('display_name', 'UberX')) | |
)(body) | |
console.log(moment().format('HH:mm:ss')) | |
console.log(`Uber Current Prices: ${uberX.estimate}`) | |
if (desiredPrice >= uberX.low_estimate && desiredPrice <= uberX.high_estimate) { | |
estimate = uberX.estimate | |
} | |
await delay(60000) | |
} | |
console.log(moment().format('HH:mm:ss')) | |
console.log(`Uber Desired Price: ${estimate}`) | |
} | |
estimateUberPrices() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment