Skip to content

Commit

Permalink
implemented class command
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuo-ozu committed Mar 20, 2017
1 parent 5d9f66b commit ea4c8d8
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 232 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ node app searchGakubu 基幹理工
node app listGakubu

# 2. Get Page ID(pid)s to get clas details
node app fetchGakubu ???? > dest/g_????.txt
node app fetchGakubu 111973 > dest/g_111973.txt

# 3. Preview JSON output
node app fetchClass 2600001002012017260000100226

# 4. dump all data
cat dest/g_111973.txt | node app fetchClass - > dest/o_111973.txt

```

Expand Down
46 changes: 44 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let gakubu = require('./lib/gakubu');
let classes = require('./lib/class');

if (process.argv[2] == "searchGakubu" && process.argv[3]) {
let list = gakubu.search(process.argv[3]);
Expand All @@ -21,7 +22,7 @@ if (process.argv[2] == "searchGakubu" && process.argv[3]) {
} else {
gidList = [process.argv[3]];
}
function loop() {
(function loop() {
let gid = gidList.shift();
process.stderr.write("fetching gakubu " + gid + "...\n");
if (!gakubu.getPageIDList(gid, function(data){
Expand All @@ -36,11 +37,52 @@ if (process.argv[2] == "searchGakubu" && process.argv[3]) {
})) {
process.stderr.write("error: " + gid + " not found\n");
}
})();
} else if (process.argv[2] == "fetchClass" && process.argv[3]) {
let pidList = [];
let res = [];
let loop = function loop() {
let pid = pidList.shift();
process.stderr.write("fetching page " + pid + "...\n");
classes.fetch(pid, function(data){
if (data) {
res.push(data);
if (pidList.length) {
loop();
} else {
process.stdout.write(JSON.stringify(res));
}
} else {
process.stderr.write("error: some error occurs when fetching or parsing " + pid + "\n");
}
});
};
if (process.argv[3] == "-") {
process.stdin.resume();
let str = "", ind;
process.stdin.on('data', function(chunk) {
str += chunk;
if (ind = str.indexOf("\n") > -1) {
let line = str.splice(0, ind);
str.splice(0, 1);
pidList.push(line);
}
});
process.stdin.on('end', function() {
if (str) {
pidList.push(str);
}
loop();
});
} else {
pidList = [process.argv[3]];
loop();
}
loop();
} else {
console.log("node app searchGakubu <keyword>");
console.log("node app listGakubu");
console.log("node app fetchGakubu <gid>");
console.log("node app fetchGakubu '*'");
console.log("node app fetchClass <pid>");
console.log("node app fetchClass -");
}
118 changes: 0 additions & 118 deletions convert.js

This file was deleted.

102 changes: 0 additions & 102 deletions get_gakubu.js

This file was deleted.

Loading

0 comments on commit ea4c8d8

Please sign in to comment.