Skip to content

Instantly share code, notes, and snippets.

@camtheman256
Created February 28, 2021 22:16
Show Gist options
  • Save camtheman256/3125e18ba20e90b6252678714e5102fd to your computer and use it in GitHub Desktop.
Save camtheman256/3125e18ba20e90b6252678714e5102fd to your computer and use it in GitHub Desktop.
Export when2meet data from JS console
function exportData() {
const peopleMap = {};
for(let i = 0; i < PeopleIDs.length; i++) {
peopleMap[PeopleIDs[i]] = PeopleNames[i];
}
nameAtSlot = AvailableAtSlot.map(e => e.map(i => peopleMap[i]));
timedNames = TimeOfSlot.map((e, i) => [e, nameAtSlot[i]]);
return JSON.stringify(timedNames);
}
@ProExpertProg
Copy link

ProExpertProg commented Feb 8, 2022

Here's a version that exports CSV with an availability table:

function getCSV() {
    result = "Time," + PeopleNames.join(",")+"\n"; 
    for(let i = 0; i < AvailableAtSlot.length; i++) {
        result += TimeOfSlot[i] + ",";
        result += PeopleIDs.map(id => AvailableAtSlot[i].includes(id) ? 1 : 0).join(",");
        result+= "\n";
    }
    return result;
}

@Severrinn
Copy link

@camtheman256 Thanks for sharing this. I ran the code in my browser and received "undefined". Also, a disclaimer here, I've never used js, so, I'm sure it's a user error. Any guidance would be appreciated.

@l-schuurman
Copy link

l-schuurman commented Sep 10, 2022

@Severrinn That is because you are only declaring the function in the console. You also need to call the function to get the result.

function getCSV() {
    result = "Time," + PeopleNames.join(",")+"\n"; 
    for(let i = 0; i < AvailableAtSlot.length; i++) {
        result += TimeOfSlot[i] + ",";
        result += PeopleIDs.map(id => AvailableAtSlot[i].includes(id) ? 1 : 0).join(",");
        result+= "\n";
    }
    return result;
}
getCSV()

Or I guess more simply avoid the function declaration all together.

result = "Time," + PeopleNames.join(",")+"\n"; 
for(let i = 0; i < AvailableAtSlot.length; i++) {
    result += TimeOfSlot[i] + ",";
    result += PeopleIDs.map(id => AvailableAtSlot[i].includes(id) ? 1 : 0).join(",");
    result+= "\n";
}
console.log(result)

@Severrinn
Copy link

@l-schuurman thanks, much appreciated!

@aculich
Copy link

aculich commented Sep 16, 2022

@Severrinn @l-schuurman building on everything above I added one more feature to extract the nice names from the onmouseover="" attributes to get Monday 09:00:00 AM instead of 279795600.

function getCSV() {
  result = "Time," + PeopleNames.join(",")+"\n"; 
  for(let i = 0; i < AvailableAtSlot.length; i++) {
      let slot = $x(`string(//div[@id="GroupTime${TimeOfSlot[i]}"]/@onmouseover)`);
      slot = slot.match(/.*"(.*)".*/)[1];
      result += slot + ",";
      result += PeopleIDs.map(id => AvailableAtSlot[i].includes(id) ? 1 : 0).join(",");
      result+= "\n";
  }
  console.log(result);
}
getCSV();

@j-nan
Copy link

j-nan commented Feb 2, 2023

@l-schuurman @aculich Thank you SOOO much!! This code has saved me SO much time! It works great!!

@dimpdash
Copy link

dimpdash commented Feb 27, 2023

Can also download as CSV directly using this

content = getCSV()

// Create element with <a> tag
const link = document.createElement("a");

// Create a blog object with the file content which you want to add to the file
const file = new Blob([content], { type: 'text/plain' });

// Add file content in the object URL
link.href = URL.createObjectURL(file);

// Add file name
link.download = "when2meet.csv";

// Add click event to <a> tag to save file.
link.click();
URL.revokeObjectURL(link.href);

ref https://www.tutorialspoint.com/how-to-create-and-save-text-file-in-javascript

@acbart
Copy link

acbart commented Sep 1, 2023

Just to put the whole thing together for those who are lazy like me:

function getCSV() {
  result = "Time," + PeopleNames.join(",")+"\n"; 
  for(let i = 0; i < AvailableAtSlot.length; i++) {
      let slot = $x(`string(//div[@id="GroupTime${TimeOfSlot[i]}"]/@onmouseover)`);
      slot = slot.match(/.*"(.*)".*/)[1];
      result += slot + ",";
      result += PeopleIDs.map(id => AvailableAtSlot[i].includes(id) ? 1 : 0).join(",");
      result+= "\n";
  }
  console.log(result);
  return result;
}
content = getCSV()

// Create element with <a> tag
const link = document.createElement("a");

// Create a blog object with the file content which you want to add to the file
const file = new Blob([content], { type: 'text/plain' });

// Add file content in the object URL
link.href = URL.createObjectURL(file);

// Add file name
link.download = "when2meet.csv";

// Add click event to <a> tag to save file.
link.click();
URL.revokeObjectURL(link.href);

And then as a bookmarklet:

javascript:(function()%7Bfunction%20getCSV()%20%7B%0A%20%20result%20%3D%20%22Time%2C%22%20%2B%20PeopleNames.join(%22%2C%22)%2B%22%5Cn%22%3B%20%0A%20%20for(let%20i%20%3D%200%3B%20i%20%3C%20AvailableAtSlot.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%20%20let%20slot%20%3D%20%24x(%60string(%2F%2Fdiv%5B%40id%3D%22GroupTime%24%7BTimeOfSlot%5Bi%5D%7D%22%5D%2F%40onmouseover)%60)%3B%0A%20%20%20%20%20%20slot%20%3D%20slot.match(%2F.*%22(.*)%22.*%2F)%5B1%5D%3B%0A%20%20%20%20%20%20result%20%2B%3D%20slot%20%2B%20%22%2C%22%3B%0A%20%20%20%20%20%20result%20%2B%3D%20PeopleIDs.map(id%20%3D%3E%20AvailableAtSlot%5Bi%5D.includes(id)%20%3F%201%20%3A%200).join(%22%2C%22)%3B%0A%20%20%20%20%20%20result%2B%3D%20%22%5Cn%22%3B%0A%20%20%7D%0A%20%20console.log(result)%3B%0A%20%20return%20result%3B%0A%7D%0Acontent%20%3D%20getCSV()%0A%0A%2F%2F%20Create%20element%20with%20%3Ca%3E%20tag%0Aconst%20link%20%3D%20document.createElement(%22a%22)%3B%0A%0A%2F%2F%20Create%20a%20blog%20object%20with%20the%20file%20content%20which%20you%20want%20to%20add%20to%20the%20file%0Aconst%20file%20%3D%20new%20Blob(%5Bcontent%5D%2C%20%7B%20type%3A%20'text%2Fplain'%20%7D)%3B%0A%0A%2F%2F%20Add%20file%20content%20in%20the%20object%20URL%0Alink.href%20%3D%20URL.createObjectURL(file)%3B%0A%0A%2F%2F%20Add%20file%20name%0Alink.download%20%3D%20%22when2meet.csv%22%3B%0A%0A%2F%2F%20Add%20click%20event%20to%20%3Ca%3E%20tag%20to%20save%20file.%0Alink.click()%3B%0AURL.revokeObjectURL(link.href)%3B%7D)()%3B

@ranakp
Copy link

ranakp commented Nov 7, 2023

Just to put the whole thing together for those who are lazy like me:

function getCSV() {
  result = "Time," + PeopleNames.join(",")+"\n"; 
  for(let i = 0; i < AvailableAtSlot.length; i++) {
      let slot = $x(`string(//div[@id="GroupTime${TimeOfSlot[i]}"]/@onmouseover)`);
      slot = slot.match(/.*"(.*)".*/)[1];
      result += slot + ",";
      result += PeopleIDs.map(id => AvailableAtSlot[i].includes(id) ? 1 : 0).join(",");
      result+= "\n";
  }
  console.log(result);
  return result;
}
content = getCSV()

// Create element with <a> tag
const link = document.createElement("a");

// Create a blog object with the file content which you want to add to the file
const file = new Blob([content], { type: 'text/plain' });

// Add file content in the object URL
link.href = URL.createObjectURL(file);

// Add file name
link.download = "when2meet.csv";

// Add click event to <a> tag to save file.
link.click();
URL.revokeObjectURL(link.href);

And then as a bookmarklet:

javascript:(function()%7Bfunction%20getCSV()%20%7B%0A%20%20result%20%3D%20%22Time%2C%22%20%2B%20PeopleNames.join(%22%2C%22)%2B%22%5Cn%22%3B%20%0A%20%20for(let%20i%20%3D%200%3B%20i%20%3C%20AvailableAtSlot.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%20%20let%20slot%20%3D%20%24x(%60string(%2F%2Fdiv%5B%40id%3D%22GroupTime%24%7BTimeOfSlot%5Bi%5D%7D%22%5D%2F%40onmouseover)%60)%3B%0A%20%20%20%20%20%20slot%20%3D%20slot.match(%2F.*%22(.*)%22.*%2F)%5B1%5D%3B%0A%20%20%20%20%20%20result%20%2B%3D%20slot%20%2B%20%22%2C%22%3B%0A%20%20%20%20%20%20result%20%2B%3D%20PeopleIDs.map(id%20%3D%3E%20AvailableAtSlot%5Bi%5D.includes(id)%20%3F%201%20%3A%200).join(%22%2C%22)%3B%0A%20%20%20%20%20%20result%2B%3D%20%22%5Cn%22%3B%0A%20%20%7D%0A%20%20console.log(result)%3B%0A%20%20return%20result%3B%0A%7D%0Acontent%20%3D%20getCSV()%0A%0A%2F%2F%20Create%20element%20with%20%3Ca%3E%20tag%0Aconst%20link%20%3D%20document.createElement(%22a%22)%3B%0A%0A%2F%2F%20Create%20a%20blog%20object%20with%20the%20file%20content%20which%20you%20want%20to%20add%20to%20the%20file%0Aconst%20file%20%3D%20new%20Blob(%5Bcontent%5D%2C%20%7B%20type%3A%20'text%2Fplain'%20%7D)%3B%0A%0A%2F%2F%20Add%20file%20content%20in%20the%20object%20URL%0Alink.href%20%3D%20URL.createObjectURL(file)%3B%0A%0A%2F%2F%20Add%20file%20name%0Alink.download%20%3D%20%22when2meet.csv%22%3B%0A%0A%2F%2F%20Add%20click%20event%20to%20%3Ca%3E%20tag%20to%20save%20file.%0Alink.click()%3B%0AURL.revokeObjectURL(link.href)%3B%7D)()%3B

This worked the best for me! Thank you so much for sharing

@fischman
Copy link

fischman commented May 4, 2024

FWIW when2meet also seems to support (at least now), a csv query param that will serve the data as CSV (though transposed from the versions above here in the gist).

Example: filled in a couple of peoples' responses in https://www.when2meet.com/?24892637-Evxyx and can get the CSV with a simple request (note the trailing &csv):

$ curl 'https://www.when2meet.com/?24892637-Evxyx&csv'
,Monday 09:00:00,Monday 09:15:00,Monday 09:30:00,Monday 09:45:00,Monday 10:00:00,Monday 10:15:00,Monday 10:30:00,Monday 10:45:00,Monday 11:00:00,Monday 11:15:00,Monday 11:30:00,Monday 11:45:00,Monday 12:00:00,Monday 12:15:00,Monday 12:30:00,Monday 12:45:00,Monday 13:00:00,Monday 13:15:00,Monday 13:30:00,Monday 13:45:00,Monday 14:00:00,Monday 14:15:00,Monday 14:30:00,Monday 14:45:00,Monday 15:00:00,Monday 15:15:00,Monday 15:30:00,Monday 15:45:00,Monday 16:00:00,Monday 16:15:00,Monday 16:30:00,Monday 16:45:00,Tuesday 09:00:00,Tuesday 09:15:00,Tuesday 09:30:00,Tuesday 09:45:00,Tuesday 10:00:00,Tuesday 10:15:00,Tuesday 10:30:00,Tuesday 10:45:00,Tuesday 11:00:00,Tuesday 11:15:00,Tuesday 11:30:00,Tuesday 11:45:00,Tuesday 12:00:00,Tuesday 12:15:00,Tuesday 12:30:00,Tuesday 12:45:00,Tuesday 13:00:00,Tuesday 13:15:00,Tuesday 13:30:00,Tuesday 13:45:00,Tuesday 14:00:00,Tuesday 14:15:00,Tuesday 14:30:00,Tuesday 14:45:00,Tuesday 15:00:00,Tuesday 15:15:00,Tuesday 15:30:00,Tuesday 15:45:00,Tuesday 16:00:00,Tuesday 16:15:00,Tuesday 16:30:00,Tuesday 16:45:00,Wednesday 09:00:00,Wednesday 09:15:00,Wednesday 09:30:00,Wednesday 09:45:00,Wednesday 10:00:00,Wednesday 10:15:00,Wednesday 10:30:00,Wednesday 10:45:00,Wednesday 11:00:00,Wednesday 11:15:00,Wednesday 11:30:00,Wednesday 11:45:00,Wednesday 12:00:00,Wednesday 12:15:00,Wednesday 12:30:00,Wednesday 12:45:00,Wednesday 13:00:00,Wednesday 13:15:00,Wednesday 13:30:00,Wednesday 13:45:00,Wednesday 14:00:00,Wednesday 14:15:00,Wednesday 14:30:00,Wednesday 14:45:00,Wednesday 15:00:00,Wednesday 15:15:00,Wednesday 15:30:00,Wednesday 15:45:00,Wednesday 16:00:00,Wednesday 16:15:00,Wednesday 16:30:00,Wednesday 16:45:00,Thursday 09:00:00,Thursday 09:15:00,Thursday 09:30:00,Thursday 09:45:00,Thursday 10:00:00,Thursday 10:15:00,Thursday 10:30:00,Thursday 10:45:00,Thursday 11:00:00,Thursday 11:15:00,Thursday 11:30:00,Thursday 11:45:00,Thursday 12:00:00,Thursday 12:15:00,Thursday 12:30:00,Thursday 12:45:00,Thursday 13:00:00,Thursday 13:15:00,Thursday 13:30:00,Thursday 13:45:00,Thursday 14:00:00,Thursday 14:15:00,Thursday 14:30:00,Thursday 14:45:00,Thursday 15:00:00,Thursday 15:15:00,Thursday 15:30:00,Thursday 15:45:00,Thursday 16:00:00,Thursday 16:15:00,Thursday 16:30:00,Thursday 16:45:00,Friday 09:00:00,Friday 09:15:00,Friday 09:30:00,Friday 09:45:00,Friday 10:00:00,Friday 10:15:00,Friday 10:30:00,Friday 10:45:00,Friday 11:00:00,Friday 11:15:00,Friday 11:30:00,Friday 11:45:00,Friday 12:00:00,Friday 12:15:00,Friday 12:30:00,Friday 12:45:00,Friday 13:00:00,Friday 13:15:00,Friday 13:30:00,Friday 13:45:00,Friday 14:00:00,Friday 14:15:00,Friday 14:30:00,Friday 14:45:00,Friday 15:00:00,Friday 15:15:00,Friday 15:30:00,Friday 15:45:00,Friday 16:00:00,Friday 16:15:00,Friday 16:30:00,Friday 16:45:00
"Alice",Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No
"Bob",No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment