Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
39 changes: 17 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
# README for Service Adapter Assignment on IF4050 2015

##Instruction
1. Fork this repository https://github.com/if-itb/if4050-2015-ServiceAdapter.git
2. Work on your fork --> commit --> push [as many as you want]
3. [When you are done OR the deadline] create pull request
##Personal Data:
* NIM = 13512047
* Name = Fahmi Dumadi
* GithubID = fahmidumadi

Each participnats should indicate clearly the following data:
* NIM = 1[35|82]+XXYYY
* Name = XXXXXXX
* GithubID = YYYY

Requreiments:
* ....
* ....
*

How to Deploy
1. .....
2. .....
3. .....
4.
##Requirements:
* Node JS 4.0.0

How to Run
1. .....
2. .....
##How to Deploy
1. install dependencies using "npm install" command
2. run adapter.js with command "node adapter.js"
3. access through localhost:3000

##How to Run
1. The required parameter are
* 'ps': major code
* 'kode': course code
* 'kelas': class number
2. Example of a full request: localhost:3000/?ps=101&kode=MA1101&kelas=01
3. The response from this adapter is JSON containing information with status code
92 changes: 92 additions & 0 deletions adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
var request = require("request"),
cheerio = require("cheerio"),
express = require("express"),
app = express();

app.get('/', function(req,resp){
var prodi = req.query.ps,
kode_kuliah = req.query.kode,
kelas = req.query.kelas,
url = "https://six.akademik.itb.ac.id/publik/daftarkelas.php?ps="+prodi+"&semester=1&tahun=2015&th_kur=2013";
//function getResponse(callback){
if( prodi != null && kode_kuliah != null && kelas != null){
request(url, function (error, response, body) {
if (!error) {
var $ = cheerio.load(body),
getURL = $('li:contains("'+kode_kuliah+'")').find('li:contains("'+kelas+'")').find('a').attr('href');
newURL = 'https://six.akademik.itb.ac.id/publik/' + getURL;

request(newURL, function (error, response, body) {
if (!error) {
if(getURL == null){
var json = {};
json.error = "Tidak ditemukan kelas dengan kode "+kode_kuliah;
console.log("Status Code: 404");
resp.status(404).send(json);
//callback(json);
}else{
var $ = cheerio.load(body),
data = $('pre').text().split('\n'),
json = {};
json.fakultas = data[0];
json.prodi = data[1].substr(17);
json.semester = data[2].substr(12,1);
json.tahun = "20" + data[2].substr(14);
json.kode = data[4].substr(19,6);

var mata_kuliah = data[4].substr(28).split(',');
json.mata_kuliah = mata_kuliah[0];
json.sks = mata_kuliah[1].substr(1,1);

json.kelas = data[5].substr(19,2);
json.dosen = data[5].substr(24);
json.jumlah_peserta = data[data.length-2].substr(16);

var peserta_kelas = [];
for(i = 0; i < json.jumlah_peserta; i++){
jsonPK = {};
jsonPK.nim = data[10+i].substr(4,8);
jsonPK.nama = data[10+i].substr(15);
peserta_kelas.push(jsonPK);
}
json.peserta = peserta_kelas;
console.log("Status Code: 200");
resp.status(200).send(json);
//callback(json);
}
} else {
var json = {};
json.error = "Terjadi kesalahan pada server";
console.log("Status Code: 500");
resp.status(500).send(json);
//callback(json);
}
});

} else {
var json = {};
json.error = "Terjadi kesalahan pada server";
console.log("Status Code: 500");
resp.status(500).send(json);
//callback(json);
}
});
}
else{
var json = {};
json.error = "Request tidak sesuai format";
console.log("Status Code: 400");
resp.status(400).send(json);
//callback(json);
}
//}
/*getResponse(function (hasil){
resp.send(hasil);
});*/
});

var server = app.listen(3000, function(){
var host = server.address().address;
var port = server.address().port;
console.log("listening on port: " + port);
});
10 changes: 10 additions & 0 deletions node_modules/cheerio/.jshintrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/cheerio/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/cheerio/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions node_modules/cheerio/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading