Skip to content

Commit 31fa124

Browse files
committed
brought back registry-api
1 parent 8e6fecd commit 31fa124

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

registry-api/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# parts-registry-api
2+
3+
Usage
4+
5+
```bash
6+
node parts-registry-api.js rfp
7+
```

registry-api/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "igem-registry-json-api",
3+
"version": "1.0.0",
4+
"description": "Usage",
5+
"main": "parts-registry-api.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/igemsoftware/Toronto-2015.git"
12+
},
13+
"author": "iGEM UofT",
14+
"license": "MIT",
15+
"bugs": {
16+
"url": "https://github.com/igemsoftware/Toronto-2015/issues"
17+
},
18+
"homepage": "https://github.com/igemsoftware/Toronto-2015#readme",
19+
"dependencies": {
20+
"cheerio": "^0.19.0",
21+
"jquery": "^2.1.4",
22+
"request": "^2.61.0"
23+
}
24+
}

registry-api/parts-registry-api.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
var request = require('request'),
2+
cheerio = require('cheerio');
3+
4+
var SEARCH_URL = 'http://parts.igem.org/wiki/index.php?title=Special:Search&ns0=1&redirs=0&search='
5+
var SUFFIX_URL = '&limit=500&offset=0'
6+
7+
function queryRegistry(keyword, cb) {
8+
request({
9+
url: SEARCH_URL + keyword + SUFFIX_URL
10+
}, function(err, res, body) {
11+
if (!err && res.statusCode === 200) {
12+
$ = cheerio.load(body)
13+
// Now we basically have core jQuery through cheerio
14+
15+
// Experiment with inspect element and console logging
16+
links = $('li')
17+
18+
//Will obviously be an object in good version
19+
data = new Array()
20+
Object.keys(links).forEach(function(key) {
21+
22+
// for (var i = 0; i< links[key].children.length; i++){
23+
// if href
24+
// }
25+
// if (links[key] && links[key].children[0] && links[key].children[0].attribs && links[key].children[0].attribs.title)
26+
// console.log(links[key].children[0].attribs.title)
27+
// data.push(links[key].children[0].attribs.title)
28+
if (links[key] !== undefined && links[key].children !== undefined && links[key].children[0] !== undefined && links[key].children[0].attribs){
29+
s = links[key].children[0].attribs.title
30+
index = s.indexOf("BBa")
31+
if (index >= 0){
32+
s = s.slice(index)
33+
splitted = s.split(" ")
34+
s = splitted[0] + "_" + splitted[1]
35+
36+
if(s.indexOf(":")>=0)
37+
s = s.slice(0, s.indexOf(":"))
38+
data.push(s)
39+
}
40+
}
41+
42+
43+
44+
// console.log(links[key].children[0])
45+
// console.log("--------\n")
46+
// if (links[key].attribs)
47+
// data.push(links[key].attribs.href)
48+
})
49+
50+
51+
// Give nicely formatted json to callback
52+
cb(data);
53+
} else {
54+
console.log(err);
55+
console.log(res.statusCode);
56+
}
57+
});
58+
}
59+
60+
// ==== MAIN ====
61+
62+
var keyword = process.argv[2]
63+
queryRegistry(keyword, function(data) {
64+
console.log(data.length)
65+
})

0 commit comments

Comments
 (0)