Skip to content

Instantly share code, notes, and snippets.

@tadfmac
Created September 21, 2016 05:18
Show Gist options
  • Save tadfmac/3a6e9467ae2fb0bd7494e4c8a10552e5 to your computer and use it in GitHub Desktop.
Save tadfmac/3a6e9467ae2fb0bd7494e4c8a10552e5 to your computer and use it in GitHub Desktop.
githubのissueにDrag&Dropで貼り付けた画像をひっこ抜く
//////////////////////////////////////////////////////////////////////////
// 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);
@tadfmac
Copy link
Author

tadfmac commented Sep 21, 2016

ToDo: 重複チェックする

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