Skip to content

Commit d4ff469

Browse files
committed
Developed a way to ask for the categories of 4chan
1 parent 2e0c616 commit d4ff469

File tree

5 files changed

+105
-6
lines changed

5 files changed

+105
-6
lines changed

Diff for: app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var express = require('express');
22
var path = require('path');
33
var app = express();
44

5-
require('./routes.js')(app);
5+
var fourChanService = require('./services/fourChanService.js');
6+
require('./routes.js')(app, fourChanService);
67

78
app.set('port', process.env.PORT || 80);
89
app.set('views', './views');

Diff for: package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
"description": "A clone client of 4Chan website where the app display all categories and threads but you can makr threads in order to be monitored by the server side application to be downloading the images of marked threads.",
55
"main": "app.js",
66
"dependencies": {
7+
"cheerio": "^0.19.0",
78
"express": "^4.13.3",
8-
"jade": "^1.11.0"
9+
"htmlparser": "^1.7.7",
10+
"jade": "^1.11.0",
11+
"noodlejs": "^0.3.2",
12+
"osmosis": "0.0.8",
13+
"request": "^2.64.0",
14+
"soupselect": "^0.2.0",
15+
"x-ray": "^2.0.2"
916
},
1017
"devDependencies": {},
1118
"scripts": {

Diff for: routes.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
module.exports = function (app) {
1+
module.exports = function (app, fourChanService) {
22

33
app.get('/', function (req, res) {
4+
5+
fourChanService.getCategories(function (data) {
46

5-
res.render('index.jade');
6-
} );
7+
res.render('index.jade', { categories : data });
8+
});
9+
10+
});
711
};

Diff for: services/fourChanService.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
var fourChanService = {
2+
3+
getCategories : function (callback)
4+
{
5+
6+
var osmosis = require('osmosis');
7+
osmosis.get('http://www.4chan.org/')
8+
.set({
9+
'categories': ['a.boardlink'],
10+
'links': ['a.boardlink @href']
11+
})
12+
.data(function (results) {
13+
14+
for(var cont = 0, categories = [], element = {}; cont < results.categories.length; cont++) {
15+
16+
element.name = results.categories[cont];
17+
element.link = results.links[cont];
18+
categories.push(element);
19+
element = {};
20+
}
21+
categories.splice(-23, 23);
22+
callback(categories);
23+
});
24+
25+
26+
/*var noodle = require('noodlejs');
27+
noodle.query({
28+
url: 'http://www.4chan.org/',
29+
type: 'html',
30+
selector: 'a.boardlink',
31+
extract: 'href'
32+
})
33+
.then(function (data) {
34+
console.log(typeof(data.results));
35+
//data.results.splice(3 , 5, 'hola' );
36+
console.log('========');
37+
console.log(data.results);
38+
console.log('========');
39+
var keys = Object.keys(data.results);
40+
console.log(keys);
41+
});*/
42+
43+
44+
/*var Xray = require('x-ray');
45+
var x = Xray();
46+
47+
x('https://4chan.org/', {title:'.boardlink'})
48+
(function (err, result) {
49+
console.log(result)
50+
});*/
51+
52+
/*[{
53+
'title': '.boardlink a@title',
54+
'href': '.boardlink a@href',
55+
}]*/
56+
57+
58+
/* var request = require("request");
59+
var cheerio = require("cheerio");
60+
var url = 'http://4chan.org/';
61+
62+
request(url, function (error, response, body) {
63+
if (!error) {
64+
var $ = cheerio.load(body),
65+
temperature = $('.boardlink').html();
66+
67+
console.log("It’s " + temperature + " degrees Fahrenheit.");
68+
} else {
69+
console.log("We’ve encountered an error: " + error);
70+
}
71+
});*/
72+
73+
/*console.log('this.categories');
74+
console.log(this.categories);
75+
var data = {
76+
categories : ['uno', 'dos']
77+
};
78+
return data;*/
79+
}
80+
};
81+
82+
module.exports = fourChanService;

Diff for: views/index.jade

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ extends layouts/default
33
block content
44
div.jumbotron.text-center
55
h1 4Chan Monitor
6-
p This gonna be awsome!!
6+
p This gonna be awsome!!
7+
8+
div
9+
each category in categories
10+
div
11+
a(href='#{category.link}') #{category.name}

0 commit comments

Comments
 (0)