diff --git a/.gitignore b/.gitignore index 84603bb..95ac3a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules dest +tags +Session.vim diff --git a/README.md b/README.md index bb8a0fd..22aca1e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,14 @@ This is a helper software for Course Compass, which fetch syllabus data from Was ```bash -# under construction... +# 1. Search Gakubu you want to fetch +node app searchGakubu 基幹理工 + +# Or list all Gakubu(s) +node app listGakubu + +# 2. Get Page ID(pid)s to get clas details +node app fetchGakubu ???? > dest/g_????.txt ``` diff --git a/app.js b/app.js new file mode 100644 index 0000000..5557428 --- /dev/null +++ b/app.js @@ -0,0 +1,23 @@ +let gakubu = require('./lib/gakubu'); + +if (process.argv[2] == "searchGakubu" && process.argv[3]) { + let list = gakubu.search(process.argv[3]); + for (let item of list) { + console.log(item); + } +} else if (process.argv[2] == "listGakubu") { + let list = gakubu.search(null); + for (let item of list) { + console.log(item); + } +} else if (process.argv[2] == "fetchGakubu" && process.argv[3]) { + if (!gakubu.getPageIDList(process.argv[3], function(data){ + for (let record of data) console.log(record); + })) { + process.stderr.write("error: gakubu not found\n"); + } +} else { + console.log("node app searchGakubu "); + console.log("node app listGakubu"); + console.log("node app fetchGakubu "); +} diff --git a/get_id.js b/get_id.js deleted file mode 100644 index e2d2b4c..0000000 --- a/get_id.js +++ /dev/null @@ -1,116 +0,0 @@ -var request = require('request'); -var fs = require('fs'); - -function findData(m0, mp, me, env){ - var s, t; - env.p = env.text.indexOf(m0, env.p + 1) + m0.length - 1; - env.p = env.text.indexOf(mp, env.p + 1); - s = env.p + mp.length; - env.p = env.text.indexOf(me, env.p + 1); - t = env.p; - return env.text.substring(s, t); -} - -var opt = { - uri: 'https://www.wsl.waseda.jp/syllabus/JAA101.php', - form: { - "p_number": "50", - "p_page": "1", - "p_gakubu": "9S2013", - "pClsOpnSts": "123", - "ControllerParameters": "JAA103SubCon", - "pLng": "jp", - }, - json: true -}; - -/* -772 -773 -774 -775 -776 -777 -778 -779 -780 -781 -782 -783 -784 -785 -786 -787 -788 -789 -790 -791 -792 -793 -794 -795 -796 -797 -798 -799 -800 -801 -802 -803 -804 -805 -806 -807 -808 -809 -810 -811 -812 -813 -814 -815 -816 -*/ - -var idList = new Array(); - -function getPage(page){ - opt.form["p_page"] = "" + page; - console.log(page); - request.post(opt, function(error, res, body){ - if (!error && res.statusCode == 200) { - console.log("200 OK"); - var env = new Object(); - var endp; - var cList = new Array(); - var id; - env.text = body; - env.p = 0; - if(env.text.indexOf("ch-message") != -1){ - console.log("Out of Pages."); - console.log(JSON.stringify(idList, "", " ")); - fs.writeFile('2016_id_' + opt.form["p_gakubu"] + ".json", JSON.stringify(idList, "", " ")); - return; - } - env.p = env.text.indexOf("block_main_start", env.p + 1); - env.p = env.text.indexOf("", env.p + 1); - endp = env.text.indexOf("", env.p + 1); - for(;;){ - env.p = env.text.indexOf("", env.p + 1) + 1; - if(env.p == 0 || env.p > endp){ - break; - } - findData("", "<", env); - findData("", "<", env); - id = findData("", env.p + 1); + let endp = env.text.indexOf("", env.p + 1); + for(;;){ + env.p = env.text.indexOf("", env.p + 1) + 1; + if(env.p == 0 || env.p > endp){ + break; + } + findData("", "<", env); + findData("", "<", env); + let id = findData("", + "license": "MIT", + "bugs": { + "url": "https://github.com/yasuo-ozu/coursecompass-fetch/issues" + }, + "homepage": "https://github.com/yasuo-ozu/coursecompass-fetch#readme", + "dependencies": { + "fs": "0.0.1-security", + "request": "^2.81.0" + } +}