Skip to content

Instantly share code, notes, and snippets.

@chrisallick
Created December 3, 2020 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisallick/474ce0071f31ba244e4c258d781aedc1 to your computer and use it in GitHub Desktop.
Save chrisallick/474ce0071f31ba244e4c258d781aedc1 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
var twilio = require('twilio');
var accountSid = '_snip_'; // enter
var authToken = '_snip_'; // enter
var your_zip_code = "90094"; // change
var twilio = require('twilio');
var client = new twilio(accountSid, authToken);
let url = "https://api.target.com/fulfillment_aggregator/v1/fiats/81114595?key=ff457966e64d5e877fdbad070f276d18ecec4a01&nearby="+your_zip_code+"&limit=1000&requested_quantity=1&radius=50&fulfillment_test_mode=grocery_opu_team_member_test";
let settings = { method: "Get" };
var _t;
function look() {
clearTimeout( _t );
console.log("fetching...");
fetch(url, settings)
.then(res => res.json())
.then((json) => {
//console.log( json.products[0].locations.length );
var found = false;
console.log("looking...");
for( var i = 0; i < json.products[0].locations.length; i++ ) {
// console.log( "store: " + json.products[0].locations[i].store_address );
// console.log( "in store: " + json.products[0].locations[i].order_pickup.availability_status );
// console.log( "in store: " + json.products[0].locations[i].in_store_only.availability_status );
// console.log("----");
if( json.products[0].locations[i].order_pickup.availability_status == "IN_STOCK" || json.products[0].locations[i].in_store_only.availability_status == "IN_STOCK" ) {
found = true;
client.messages.create({
body: "in stock: " + json.products[0].locations[i].store_address,
to: "_snip_your_phone_number_", // enter
from: '_snip_your_twilio_phone_number_' // enter
}).then((message) => console.log(message.sid));
}
}
if( !found ) {
console.log("not found. sleeping for 5 minutes...");
console.log("");
_t = setTimeout(look, 60 * 5 * 1000); // 60 seconds x 5 x 1000ms = 5 minutes
}
});
}
look();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment