const http = require("http"); const fs = require("fs"); const events= require("events"); function post(path, json, cb) { let options = { host: "hr.amiaodaifu.com", port: 50000, path: `/1610/${path}`, method: "GET" }; let content = undefined; if(json!==null) { content = new Buffer(JSON.stringify(json)); options.method = "POST"; options.headers = { "Content-Type": "application/json; charset=utf-8", "Content-Length": content.length }; } let req = http.request(options, function(res) { let content = ""; res.on("data", (data) => content += data); res.on("end", () => cb( res.statusCode===200 ? JSON.parse(content) : null )); }); req.on("error", (e) => cb(null)); req.end(content); } function _new(cb) { post("new-question", {mail: "john.zhang@yishizhencang.com"}, cb); } function _get(questionId, id, cb) { post(`questions/${questionId}/get-children/${id}`, null, cb); } function _check(questionId, json, cb) { post(`questions/${questionId}/check`, {root: json}, cb); } function _submit(questionId, cb) { post(`questions/${questionId}/submit`, { name: "amiao", forFun: true, phone: 01234567890, sourceCode: fs.readFileSync(__filename, "utf-8") }, cb); } class p1610 extends events { constructor() { super(); _new((question) => { if(question===null) return; this.questionId = question.id; this.root = {id: question.rootId, children: []}; this.queue = [this.root]; this.tasks = 0; this.emit("get"); }); } run(father) { _get(this.questionId, father.id, (childrenId) => { if(childrenId===null) this.queue.push(father); else for(let i=0; i{ if(judge===null) return; if(judge.pass) this.emit("submit"); console.log(judge); }); } submit() { _submit(this.questionId, (message) => console.log(message)); } } let p = new p1610; p.on("get", p.get); p.on("check", p.check); p.on("submit", p.submit);
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/91103.html
阅读 1601·2021-11-02 14:48
阅读 3654·2019-08-30 15:56
阅读 2768·2019-08-30 15:53
阅读 3209·2019-08-30 14:09
阅读 3097·2019-08-30 12:59
阅读 2855·2019-08-29 18:38
阅读 2695·2019-08-26 11:41
阅读 2210·2019-08-23 16:45