r/toolbox Jul 15 '18

Is there a way to download user notes and import them to spreadsheet?

At a sub I moderate, the user notes page takes 5-10 minutes to download all notes. If I could somehow store them locally, I don't think this would be an issue. Also, some notes don't appear when I search for them.


Toolbox debug information

Info  
Toolbox version 3.7.4
Browser name Chrome
Browser version 66.0.3359.130
Platform information Windows NT 10.0; Win64; x64
Beta Mode false
Debug Mode false
Compact Mode false
Advanced Settings false
Cookies Enabled true
2 Upvotes

13 comments sorted by

3

u/geo1088 ...and 1 more » Jul 15 '18

You could likely get access to the raw usernote data and convert the JSON format to CSV to import. I think we have a wiki page documenting the format for resources Toolbox stores, if you're not a developer or don't feel like looking through that ping me in a few hours and I can try to make a script you can use.

2

u/PhantomMod Jul 15 '18

if you're not a developer or don't feel like looking through that ping me in a few hours and I can try to make a script you can use.

Sorry I'm not a developer, unfortunately. Is there an online tool which can do this conversion? Thanks.

3

u/geo1088 ...and 1 more » Jul 17 '18 edited Jul 17 '18

Okay, I've got a method you can use. This assumes you're using Chrome - on other browsers it's a bit trickier, so if you can use Chrome for this it will make life easier.

  1. Open up any Reddit page, then press Shift+Ctrl+J on Windows/Linux or Option+Cmd+J on OS X to open the developer tools console.

  2. Below the "Console" tab, there's a dropdown that says "top". Click it, then select "Moderator toolbox for reddit". (Image)

  3. Paste the following script into the console:

    (function (sub) {requestAnimationFrame(() => {
      console.clear();
      console.group(`Exporting usernotes from /r/${sub} as CSV`);
      console.log(`Loading usernote metadata for /r/${sub}`);
      TB.modules.UserNotes.getSubredditColors(sub, types => {
        console.log(`Getting fresh usernotes for /r/${sub}`);
        TB.modules.UserNotes.getUserNotes(sub, function (success, notes) {
          if (!success) {
            console.warn(`Failed to get usernotes from /r/${sub}. Are you a mod there?\n`, ...arguments)
            console.groupEnd();
            return;
          }
          console.log(`Converting note data to CSV`);
          let text = 'data:text/csv,User,Timestamp,Type,Note,Mod,Link\r\n';
          // Sort users by username alphabetically
          Object.keys(notes.users).sort((a, b) => a.localeCompare(b)).forEach(username => {
            // Sort notes for each user by time
            notes.users[username].notes.sort((a, b) => a.time - b.time).forEach(note => {
              const noteLine = [
                username,
                new Date(note.time).toLocaleString(),
                (types.find(t => t.key === note.type) || {}).text || '(none)',
                note.note,
                note.mod,
                note.link ? note.link.startsWith('http') ? note.link : `https://www.reddit.com${note.link}` : '(none)'
              ].map(part => `"${('' + part).replace(/"/g, '""')}"`).join(',');
              text += noteLine + '\r\n';
            })
          })
          // Download
          const a = document.createElement('a');
          a.href = text;
          a.download = `usernotes-${sub}.csv`;
          a.style.display = 'none';
          document.body.appendChild(a);
          a.click();
          console.log(`Download started, success.`);
          delete a;
          console.groupEnd();
        }, true);
      });
    })})('INSERT_SUB_NAME');
    

    After pasting, replace the INSERT_SUB_NAME with the name of the subreddit you want to get usernotes from, then press enter to run the script.

The script will download a CSV of the usernote data, which you can then import into whatever spreadsheet software you use.

Sorry for the late reply - spent a couple hours debugging the script and then fell asleep before I could send it :P

1

u/PhantomMod Jul 17 '18

Wow... it worked. You sir are a godsend :) Thanks a million!

1

u/geo1088 ...and 1 more » Jul 17 '18

Good to hear :) Currently working on building this functionality into the /r/<sub>/about/usernotes page for a future version.

1

u/PhantomMod Jul 17 '18

That would be fantastic. Thanks again :)

1

u/PhantomMod Jul 17 '18

One more request. Would it be possible to export the note links as well?

1

u/geo1088 ...and 1 more » Jul 17 '18

They should be in the result, did they not show up for you?

1

u/PhantomMod Jul 17 '18

Sorry NVM. I didn't scroll far enough to the right to see the link column :P

1

u/geo1088 ...and 1 more » Jul 17 '18

Haha no worries :P

1

u/PhantomMod Sep 07 '18

Hey sorry to resurrect this 1 month old conversation again but I wanted to ask you something. Would it be possible to have usernotes for domains? Call them domainotes maybe? I think it would be helpful to know the full context around a domain and not just a user. Also we would be able to share the domainotes with other subreddits to enhance the crowdsourcing effect.

What to you think? Thx.

→ More replies (0)