baptx

twitter_archive_to_csv

Aug 4th, 2020
1,932
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. // copy tweets variable from tweets.js file of your Twitter archive
  3. var tweets = [];
  4.  
  5. // Open this HTML file and execute the following JavaScript code in the web console (F12 or Ctrl+Shift+K shortcut)
  6. // A textarea will appear so you can copy/paste to save data as a CSV file
  7. /*
  8. var out = [];
  9. var length = tweets.length;
  10. for (var i = 0; i < length; ++i) {
  11.     var name, id;
  12.     if (tweets[i].tweet.entities.user_mentions.length > 0) {
  13.         name = tweets[i].tweet.entities.user_mentions[0].screen_name;
  14.         id = tweets[i].tweet.entities.user_mentions[0].id_str;
  15.     }
  16.     else {
  17.         name = "";
  18.         id = "";
  19.     }
  20.     out[i] = tweets[i].tweet.created_at + '\t"'
  21.         + tweets[i].tweet.full_text.replace(/"/g, '""') + '"\t"""'
  22.         + tweets[i].tweet.id_str + '"""\t'
  23.         + name + '\t"""' // backup name with user ID to make sure it is the correct account (in case the mention order is not sorted)
  24.         + id + '"""'; // backup first mentionned user ID to track a user who deleted a tweet you retweeted / favorited (even if the user changed his username)
  25.     // 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
  26. }
  27. displayData();
  28.  
  29. function displayData()
  30. {
  31.     var box = document.createElement("textarea");
  32.     box.value = out.join('\n');
  33.     document.body.appendChild(box);
  34. }
  35. */
  36. </script>
  37.  
RAW Paste Data