Last active
October 10, 2017 15:42
-
-
Save ivanfgm/b2e33c0d3aac48957bfc668d0d8fb948 to your computer and use it in GitHub Desktop.
Scrap responses to a tweet directly off twitter html
This file contains 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
function paddy(n, p, c) { | |
var pad_char = typeof c !== 'undefined' ? c : '0'; | |
var pad = new Array(1 + p).join(pad_char); | |
return (pad + n).slice(-pad.length); | |
} | |
function formatted_date () { | |
var formattedDate = new Date(); | |
var d = paddy(formattedDate.getDate(), 2); | |
var m = paddy(formattedDate.getMonth()+1, 2); // JavaScript months are 0-11 | |
var y = formattedDate.getFullYear(); | |
return d+"-"+m+"-"+y; | |
} | |
function s (str) { | |
return "\""+str.trim().replace(/"/g, "'")+"\""; | |
} | |
var text = "data:text/csv;charset=UTF-8,"; | |
var replies_to = s($("#permalink-overlay-dialog .js-original-tweet .permalink-header .username").first().text()); | |
var tweet = s($("[role=main] .permalink-tweet-container .permalink-tweet .js-tweet-text-container").text()); | |
text += "Sistema Básico de Monitoreo\n"; | |
text += "Consulta: "+formatted_date()+"\n"; | |
text += "Cliente: Respuestas "+replies_to+"\n"; | |
text += "\n"; | |
text += s(tweet)+"\n"; | |
text += "Cuenta,Usuario,Fecha,Respuesta,Sentimiento,URL\n"; | |
$("#stream-items-id .tweet").each(function (el) { | |
var link = s("https://twitter.com"+$(this)[0].dataset["permalinkPath"]); | |
var user = s($(this)[0].dataset["screenName"]); | |
var name = s($(this)[0].dataset["name"]); | |
var date = s($(this).find(".js-short-timestamp").first().text()); | |
var content = s($(this).find(".js-tweet-text").first().text()); | |
text += [user,name,date,content,"",link].join(","); | |
text += "\n"; | |
}); | |
var encoded = encodeURI(text); | |
window.open(encoded); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment