Last active
August 4, 2020 20:08
-
-
Save baptx/c43dec50f13b9835dd5f4485255fc9e3 to your computer and use it in GitHub Desktop.
Twitter archive to CSV
This file contains hidden or 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
<script> | |
// copy tweets variable from tweets.js file of your Twitter archive | |
var tweets = []; | |
// Open this HTML file and execute the following JavaScript code in the web console (F12 or Ctrl+Shift+K shortcut) | |
// A textarea will appear so you can copy/paste to save data as a CSV file | |
/* | |
var out = []; | |
var length = tweets.length; | |
for (var i = 0; i < length; ++i) { | |
var name, id; | |
if (tweets[i].tweet.entities.user_mentions.length > 0) { | |
name = tweets[i].tweet.entities.user_mentions[0].screen_name; | |
id = tweets[i].tweet.entities.user_mentions[0].id_str; | |
} | |
else { | |
name = ""; | |
id = ""; | |
} | |
out[i] = tweets[i].tweet.created_at + '\t"' | |
+ tweets[i].tweet.full_text.replace(/"/g, '""') + '"\t"""' | |
+ tweets[i].tweet.id_str + '"""\t' | |
+ name + '\t"""' // backup name with user ID to make sure it is the correct account (in case the mention order is not sorted) | |
+ id + '"""'; // backup first mentionned user ID to track a user who deleted a tweet you retweeted / favorited (even if the user changed his username) | |
// CSV with tab separator: quote to allow multiline string; escape quote string delimiter with double quote; display large numbers correctly as string with triple quote | |
} | |
displayData(); | |
function displayData() | |
{ | |
var box = document.createElement("textarea"); | |
box.value = out.join('\n'); | |
document.body.appendChild(box); | |
} | |
*/ | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment