Skip to content

Instantly share code, notes, and snippets.

@brampersandon
Last active April 6, 2016 03:42
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 brampersandon/fe76020f4c743c641db78d910abc0223 to your computer and use it in GitHub Desktop.
Save brampersandon/fe76020f4c743c641db78d910abc0223 to your computer and use it in GitHub Desktop.
Tweet about Apple devices that are coming your way.
var shipit = require('shipit');
var Twit = require ('twit');
var thingToTrack = 'YOUR TRACKING NUMBER HERE';
var ups = new shipit.UpsClient({
licenseNumber: 'LICENSE',
userId: 'USERNAME',
password: 'PASSWORD'
});
var t = new Twit(TWIT_CONFIG_OBJECT);
var last;
function check(){
ups.requestData({trackingNumber: thingToTrack}, function(err, result){
console.log("checked " + Date());
loc = result.activities[0].location;
update(err, loc);
});
}
function update(err, loc){
try {
if (err){
throw err;
} else {
if (last == 'I\'m in the US' ) {
stat = pickApplePlatitude();
} else {
stat = "I'm in " + the(loc) + loc;
updateLocation(loc);
}
t.post('statuses/update', { status: stat }, function(err, data, response) {
console.log(data);
last = data.status.text;
});
}
} catch(e) {
console.error(e.stack);
}
}
function the(loc) {
if (loc.length < 3){
return "the ";
}
return '';
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function pickApplePlatitude(){
var words = "Here's to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes... the ones who see things differently -- they're not fond of rules... You can quote them, disagree with them, glorify or vilify them, but the only thing you can't do is ignore them because they change things... they push the human race forward, and while some may see them as the crazy ones, we see genius, because the ones who are crazy enough to think that they can change the world, are the ones who do.".split(' ');
var start = getRandomInt(0,words.length);
var end = start + 6;
return words.slice(start,end).reduce(function(prev, current, item, arr){
return prev + ' ' + current;
});
}
function updateLocation(location){
t.post('account/update_profile', {location: location}, function(err, data, response) {
console.log(data);
last = data.status.text;
});
}
check();
setInterval(check, 3600000);
{
"name": "shippingbot",
"version": "0.0.1",
"description": "a twitter bot for shipping purposes",
"main": "app.js",
"dependencies": {
"shipit": "^0.1.16",
"twit": "^1.1.20"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment