Created
September 21, 2016 05:18
-
-
Save tadfmac/3a6e9467ae2fb0bd7494e4c8a10552e5 to your computer and use it in GitHub Desktop.
githubのissueにDrag&Dropで貼り付けた画像をひっこ抜く
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
////////////////////////////////////////////////////////////////////////// | |
// github image downloader | |
// | |
// dependencies : wget | |
// | |
// CC 2016 by D.F.Mac. (H.Kodama) | |
// | |
// Usage: | |
// $ node getimages.js | |
// | |
// Version: | |
// v0.0 : 2016.09.21 : WIP | |
// | |
////////////////////////////////////////////////////////////////////////// | |
// dependencies | |
var fs = require('fs'); | |
var execSync = require('child_process').execSync; | |
var path = "./issueList.json"; // test | |
function collectImages(checkpath){ | |
var buf = fs.readFileSync(checkpath); | |
var str = buf.toString(); | |
var json = JSON.parse(str); | |
for(var cnt=0;cnt < json.length; cnt++){ | |
var bodydata = json[cnt].body; | |
if(json[cnt].comments > 0){ | |
for(var cnt2 = 0;cnt2 < json[cnt].commentsArr.length; cnt2 ++){ | |
bodydata+= json[cnt].commentsArr[cnt2].body; | |
} | |
} | |
var regPat = /\!\[(.*)\]\(https\:\/\/cloud\.githubusercontent\.com(.*)\)/gm; | |
for(;;){ | |
var urls = regPat.exec(bodydata); | |
if(!urls){ | |
break; | |
} | |
var urlstr = 'https://cloud.githubusercontent.com'+urls[urls.length-1]; | |
console.log(urlstr); | |
var param = "wget " + urlstr; | |
execSync(param); | |
} | |
} | |
} | |
collectImages(path); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ToDo: 重複チェックする