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

首頁 > 學院 > 開發設計 > 正文

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

2019-11-14 10:27:03
字體:
來源:轉載
供稿:網友
使用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秒執行	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秒執行	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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品美女久久久免费 | 日本看片一区二区三区高清 | 涩涩操 | 精品在线免费播放 | 亚洲成人福利在线 | 少妇一级淫片免费放正片 | 精品无码久久久久久国产 | 成人免费福利网站 | 国产一级αv片免费观看 | 美女黄色毛片免费看 | 日日摸夜夜骑 | 国产精品视频成人 | 成人在线视频国产 | 男女一边摸一边做羞羞视频免费 | 把娇妻调教成暴露狂 | 麻豆传传媒久久久爱 | 小雪奶水翁胀公吸小说最新章节 | 羞羞答答影院 | 午夜视频久久 | 91短视频在线视频 | 国产亚洲小视频 | 久久情爱网 | 亚洲免费网站 | 久久我不卡 | 国产1区在线观看 | 欧美特黄特色视频 | 欧美一区二区三区中文字幕 | 国产成人观看 | 欧美大屁股精品毛片视频 | 97久久日一线二线三线 | 欧美激情天堂 | 久久中文一区 | 性少妇freeseⅹbbwhd | 色婷婷一区二区三区 | 激情久久精品 | 精品在线视频播放 | 他也色在线视频 | 最新中文字幕免费视频 | 精品一区二区三区四区在线 | 免费男女视频 | www.99av|