麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發(fā)設計 > 正文

使用coffeescript定時任務下載服務器xml和plist文件解析為json

2019-11-14 10:29:53
字體:
供稿:網(wǎng)友
使用coffeescript定時每隔一個小時從服務器上下載xml和plist文件,存到本地并解析為json文件。
###* 每隔一個小時從服務器下載最新的xml和plist并解析為json###fs = require('fs')url = require('url')http = require('http')plist = require('plist')schedule = require('node-schedule')parseString = require('xml2js').parseStringinitConfig = ()->	initXMLConfig()	initPlistConfig()#下載xml并解析為Json文件initXMLConfig = () ->	file_url = "https://服務器地址/config.xml"	filepath = "./config.xml"	jsonFilepath = "./config.json"	rule = new schedule.RecurrenceRule()	#每小時的第0分鐘第1秒執(zhí)行	rule.second = 1	rule.minute = 0	rule.hour = [0..23]	schedule.scheduleJob(rule, ()->		options = {			host: url.parse(file_url).host,			port: 80,			path: url.parse(file_url).pathname		}		http.get(options, (res)->			if res.statusCode is 200				file = fs.createWriteStream(filepath)				res.on("data", (data)->					file.write(data)				).on("end", ()->					file.end()					file.on('finish', ()->						console.log(file_url + " downloaded success!")						xml = fs.readFileSync(filepath, 'utf-8')						if xml							parseString(xml, {explicitArray: false, ignoreAttrs: true, trim: true}, (err, result) ->								if not err									fs.writeFileSync(jsonFilepath, JSON.stringify(result), 'utf-8')									console.log("write to json success:#{jsonFilepath}")							)					)				)			else				console.log("access " + file_url + " is error, statusCode is #{res.statusCode}")		)	)#下載plist文件使用plist模塊解析為jsoninitPlistConfig = () ->	file_url = "https://服務器地址/config.plist"	filepath = "./config.plist"	jsonFilepath = "./config1.json"	rule = new schedule.RecurrenceRule()	#每小時的第0分鐘第10秒執(zhí)行	rule.second = 10	rule.minute = 0	rule.hour = [0..23]	schedule.scheduleJob(rule, ()->		options = {			host: url.parse(file_url).host,			port: 80,			path: url.parse(file_url).pathname		}		http.get(options, (res)->			if res.statusCode is 200				file = fs.createWriteStream(filepath)				res.on('data', (data)->					file.write(data)				).on('end', ()->					file.end()					file.on('finish', ()->						console.log(file_url + " downloaded success!")						xml = fs.readFileSync(filepath, 'utf-8')						if xml							result = plist.parse(xml)							fs.writeFileSync(jsonFilepath, JSON.stringify(result), 'utf-8')							console.log("write to json success:#{jsonFilepath}")					)				)			else				console.log("access " + file_url + " is error, statusCode is #{res.statusCode}")			)		)exports.initConfig = initConfig
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 免费看综艺策驰影院 | 欧美日韩在线视频一区 | 久久精品久久久久 | 成人精品久久久 | 亚洲精品日韩色噜噜久久五月 | 日韩视频一区二区在线观看 | 国产亚洲精品久久久久久久久 | 国产成人精品一区在线播放 | 性明星video另类hd | 国产精选91 | 久色伊人| 午夜av男人的天堂 | 毛片在线视频免费观看 | 久久综合一区 | 一级做人爱c黑人影片 | 美女性感毛片 | 久久精品一二三区 | 国产91对白叫床清晰播放 | 色阁五月 | 国产麻豆交换夫妇 | 国产精品久久久久久久久久妇女 | 毛片大全 | 美女视频黄a视频免费全过程 | 亚洲第一男人天堂 | 97中文| 国产porn在线 | 国产精品刺激对白麻豆99 | 久久久久久久一区二区 | 欧美亚洲啪啪 | 男人的天堂色偷偷 | 人成久久 | 男女羞羞视频在线观看免费 | 久久吊 | 九九热在线免费观看视频 | 亚洲成人综合网站 | 国产精品高潮99久久久久久久 | 精品国产一区二区三区四区阿崩 | 性生活视频软件 | 成人男女视频 | 逼片视频 | 97青青草视频 |