@dlutwuwei
2014-12-18T03:36:51.000000Z
字数 1696
阅读 650
工作业务
对图片托底素材的文件名进行统一处理,下面有一个nodejs的程序,可以很方便地完成。使用时需要根据实际情况替换图片存储路径和重命名名称。
var fs = require('fs');var path = 'C:\\Users\\admin360buyad\\Desktop\\M\\'; //托底图片文件目录var files = fs.readdirSync(path);for(var i=0; i<files.length; i++){console.log(files[i]);var name = files[i];var x = name.split('-');fs.rename(path + name, path + x[0]+"-"+x[1]+".jpg");//图片文件重命名位900-100.jpg高宽为名}
上传图片
192.168.129.122 admanager.jd.com, 进行备份操作。进行批量托底替换,下面是托底替换的nodejs脚本代码,替换时需要安装request模块。使用时注意不要一次性完成,先尝试10个,20个替换完成后进行检查,在尝试替换100-200个
var request = require('request');var ads = [518,519,521,522,523,524,525,526,527,528,529,530,531,532,533,534];//需要替换的广告位id号for (var i = 0; i < ads.length; i++) {var id = ads[i];(function(id) {request.get("http://admanager.jd.com/TemplateManager?adSeckill&type=searchRedis&adId=" + id + "&r=0.7934600890148431",function(err, httpResponse, body) {var res = JSON.parse(body);if (res.adSeckill == null || res.adSeckill == "") return;// 图片和链接替换// res.adSeckill = res.adSeckill.replace("http://static.360buyimg.com/ad/temp/img/td/", "http://static.360buyimg.com/ad/temp/img/td12/")// .replace("http://pinpaijie.jd.com", "http://sale.jd.com/act/YKirHPdQ2x8lqsR.html");res.adSeckill = res.adSeckill.replace("http://static.360buyimg.com/ad/temp/img/td12/","http://static.360buyimg.com/ad/temp/img/td/").replace("http://sale.jd.com/act/YKirHPdQ2x8lqsR.html", "http://pinpaijie.jd.com" );console.info(id, res.adSeckill);(function(id) {request.post({url: 'http://admanager.jd.com/TemplateManager?userid=1', //'http://test.adcollect.jd.com/NewTemplateServlet',form: {type: 'modifyRedis',adId: id,adSeckill: res.adSeckill}}, function(err, httpResponse, body) {console.log("ad" + id + ", post successed!");});})(id);});})(id);}