Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Uber Price Estimates
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
You can’t perform that action at this time.