Last active
August 29, 2015 14:11
-
-
Save sgade/9a7069d69f760fe9d31d to your computer and use it in GitHub Desktop.
Get content and information about Workflows.
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
/* | |
* Workflow.js | |
* by: Sören Gade | |
* | |
* Extracts information from Workflow's share URLs. | |
* | |
* For more information, see their website: https://my.workflow.is/. | |
*/ | |
var http = require('http'), | |
https = require('https'), | |
util = require('util'); | |
var plist = require('bplist-parser'); | |
function getIdFromPage(page) { | |
var id = page.match(/workflows\/[a-z0-9]*$/)[0]; | |
id = id.replace(/workflows\//, ''); | |
return id; | |
} | |
function getURLFromPage(page) { | |
return 'https://workflow-gallery.s3.amazonaws.com/workflows/' + getIdFromPage(page) + '.wflow'; | |
} | |
(function main() { | |
var pageUrl = null; | |
if ( process.argv.length < 3 || !( pageUrl = process.argv[2] ) ) { | |
console.log("Please specify the ShareURL as parameter!"); | |
return; | |
} | |
var url = getURLFromPage(pageUrl); | |
var request = null; | |
if ( url.match(/^https/) ) { | |
request = https; | |
} else { | |
request = http; | |
} | |
console.log("Requesting \"" + url + "\" ..."); | |
request.get(url, function(res) { | |
res.on('data', function(data) { | |
var object = plist.parseBuffer(data); | |
var objectString = util.inspect(object, { | |
depth: null | |
}); | |
console.log(objectString); | |
var meta = object[0].WFWorkflowVariables[0]; | |
console.log("\n\nSummary:\n"); | |
console.log("Name: " + meta.Name); | |
console.log("UUID: " + meta.UUID); | |
console.log("Actions: " + object[0].WFWorkflowActions.length); | |
}); | |
}).end(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment