-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchinadigital.js
More file actions
92 lines (65 loc) · 1.85 KB
/
chinadigital.js
File metadata and controls
92 lines (65 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"use strict";
var FeedParser = require('feedparser');
var request = require('request')
var coffeescript = require('coffee-script/register')
var feedparser = new FeedParser();
var BlogHelper = require("./bloghelper").BlogHelper;
var $ = require('jquery')(require("jsdom").jsdom().defaultView);
function extractBody(description){
var dom=$("<div>"+description+"</div>");
$("img",dom).remove();
$("iframe",dom).remove();
$("embed",dom).remove();
return dom.html()
}
function collectFunc(blogController){
console.log("collect func");
var req = request("http://chinadigitaltimes.net/chinese/category/level-2-article/feed/");
req.on('response',function(res){
if (res.statusCode!=200) {
console.log(" error done:",res.statusCode);
blogController.finish();
return;
}
res.pipe(feedparser);
});
feedparser.on('end',function(){
if(!blogController.changed){
console.log("unchanged");
blogController.finish();
return;
}
blogController.recycle(function(){
blogController.save();
})
});
feedparser.on('readable',function(){
var stream = this;
var article;
while(article=stream.read()){
if (blogController.alreadyHave(article.title)){
console.log("skip:",article.title);
continue;
}
blogController.addPost({
title:article.title,
date_published: blogController.toGMT8Sec(new Date(article.pubdate)),
body:"---\n"+extractBody(article.description),
tag:article.categories.filter(function(cat){
return cat.match(/Level.*Article/)==null
})
});
}
});
}
new BlogHelper(
{
addr:"147QaQk6nh6QwM5LJe6eNrTwxQgS1yVT6a",
host:"127.0.0.1",
port:43110,
proto:{
ws:"ws",
http:"http"
}
},
collectFunc);