-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.js
executable file
·74 lines (64 loc) · 1.43 KB
/
misc.js
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
"use strict";
let nodebug = process.argv[2] === 'nodebug';
let request = require('request');
let $ = require('whacko');
let th = require('thunkify');
let _ = require('lodash');
let cfg = require('./cfg.js');
let loadPage = function(url, callback)
{
log.info('load url: %s', url);
request(url, function(err, response, html)
{
if(err)
return callback(err);
try
{
let $wh = $.load(html);
if(!$wh('#gm_content').length)
log.warn('can\'t find #gm_content');
callback(null, $wh)
}
catch(e)
{
callback(e);
}
});
};
let winston = require('winston');
global.log = new winston.Logger;
var logIntances =
[
{ kind: 'Console', cfg: { name: 'con', colorize: true, prettyPrint: true, } },
{ kind: 'File', cfg: { name: 'err', filename: 'logs/error.log', level: 'error', maxsize: 1024 * 1024 * 20 }, },
{ kind: 'File', cfg: { name: 'access', filename: 'logs/access.log', levels: 'info,warn', maxsize: 1024 * 1024 * 20 }, },
];
if(nodebug)
logIntances.shift();
_.each(logIntances, function(li)
{
let kind = winston.transports[li.kind];
log.add(kind, li.cfg);
});
let makeRss = function(offers)
{
let RSS = new require('rss');
let rss = new RSS(_.extend(cfg.rssFeed));
_.each(offers, function(item)
{
rss.item(
{
title: item.title,
description: item.html,
url: item.link,
guid: item.id,
date: item.date
});
});
return rss;
}
module.exports =
{
loadPage: th(loadPage),
makeRss: makeRss
};