Last active
May 20, 2021 20:41
-
-
Save leoherzog/6b81ecc7eb89393e0dd80f7291c8c6c1 to your computer and use it in GitHub Desktop.
Export Classic Google Sites Attachments to Google Drive Folder
This file contains 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
// Go to script.google.com, click "New Project", copy and paste this code in, and click "▷ Run" in the toolbar | |
function run() { | |
let sites = SitesApp.getAllSites('example.com'); | |
console.log('Total number of sites: ' + sites.length); | |
sites = sites.filter(site => { | |
try { | |
return site.getOwners().map(owner => owner.getEmail()).includes('[email protected]') || | |
site.getEditors().map(editor => editor.getEmail()).includes('[email protected]') || | |
site.getViewers().map(viewer => viewer.getEmail()).includes('[email protected]'); | |
} | |
catch(e) { | |
return false; | |
} | |
}); | |
console.log('Sites you\'re a part of: ' + sites.length); | |
let root = DriveApp.createFolder('Sites Export ' + Utilities.formatDate(new Date(), 'America/Detroit', 'yyyy-MM-dd-hh-mm-ssz')); | |
for (let site of sites) { | |
console.log('Creating ' + site.getTitle().trim()); | |
let folder = DriveApp.createFolder(site.getTitle().trim()).moveTo(root); | |
let attachments = site.getAttachments(); | |
for (let attachment of attachments) { | |
DriveApp.createFile(attachment.getBlob()).moveTo(folder); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment