Skip to content

Instantly share code, notes, and snippets.

@keithcollins
Created January 15, 2016 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithcollins/df19f1faef29e4cd383e to your computer and use it in GitHub Desktop.
Save keithcollins/df19f1faef29e4cd383e to your computer and use it in GitHub Desktop.
var fs = require('fs');
var d3 = require('d3');
var Twit = require('twit')
var T = new Twit({
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
});
var csv = fs.readFileSync("./usinjuries/descs.csv", 'utf8');
var csvdata = d3.csv.parse(csv);
function getNarrative(count) {
var str = csvdata[count].narrative
.replace("YOF","-YR-OLD FEMALE")
.replace("YOM","-YR-OLD MALE");
var str2 = "";
str.split("").forEach(function(chr,i){
if (i < 140) str2 += chr;
});
doTweet(str2,csvdata[count].date);
}
function doTweet(narrative,date) {
T.post('statuses/update', { status: narrative }, function(error, data, response) {
if (error) {
if (error.code == 187) {
doTweet("@collinskeith check at count on "+date,date);
} else {
return console.log(error);
}
} else {
T.post('direct_messages/new', { screen_name: "collinskeith", text: date+": "+narrative }, function(error, data, response) {
if (error) return console.log("error sending dm log: "+error);
});
}
});
}
T.get('statuses/user_timeline', { screen_name: 'usinjuries', count: 1 }, function(err, data, response) {
var count = data[0].user.statuses_count;
getNarrative(count);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment