Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CommandBox Task Runner to download packages from RiaForge
/**
* Scrape all the binaries from RiaForge
*/
component {
property name="progressableDownloader" inject="ProgressableDownloader";
property name="progressBar" inject="ProgressBar";
function run() {
directoryCreate( resolvePath( 'downloads' ), true, true );
var projects = deserializeJSON( fileRead( 'http://riaforge.org/index.cfm?event=json.projects' ) );
var slugs = projects.data.urlname;
slugs.each( function( slug ) {
var downloadURL = 'http://#slug#.riaforge.org/index.cfm?event=action.download&doit=true';
var localPath = resolvePath( 'downloads/#slug#.zip' );
if( !fileExists( localPath ) ) {
print.greenLine( "Downloading #downloadURL#..." ).toConsole();
try{
progressableDownloader.download(
downloadURL,
localPath,
function( status ) {
progressBar.update( argumentCollection = status );
},
function( newURL ) {
// RiaForge packages with no download link redirect to this dead page with no zip file on the end
if( newURL.endsWith( '.riaforge.org/downloads/' ) ) {
throw( 'No Download URL present on RIAForge' );
}
print.yellowIndentedLine( newURL ).toConsole();
}
);
} catch( any var e ) {
if( e.message == 'UserInterruptException' ) { rethrow; }
print.redIndentedLine( "#e.message# #e.detail#" ).toConsole();
}
checkInterrupted();
}
} );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment