Skip to content

Instantly share code, notes, and snippets.

@baptx
Last active August 4, 2020 20:08
Show Gist options
  • Select an option

  • Save baptx/c43dec50f13b9835dd5f4485255fc9e3 to your computer and use it in GitHub Desktop.

Select an option

Save baptx/c43dec50f13b9835dd5f4485255fc9e3 to your computer and use it in GitHub Desktop.

Revisions

  1. baptx revised this gist Aug 4, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion twitter_archive_to_csv.htm
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,8 @@
    // 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 to get your CSV file
    // 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;
  2. baptx revised this gist Aug 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion twitter_archive_to_csv.htm
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    var out = [];
    var length = tweets.length;
    for (var i = 0; i < length; ++i) {
    var id;
    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;
  3. baptx created this gist Aug 4, 2020.
    35 changes: 35 additions & 0 deletions twitter_archive_to_csv.htm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <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 to get your CSV file
    /*
    var out = [];
    var length = tweets.length;
    for (var i = 0; i < length; ++i) {
    var 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>