1 | # node-sitesampler
|
2 | [![npm version](http://img.shields.io/npm/v/sitesampler.svg)](https://www.npmjs.org/package/sitesampler)
|
3 | [![Build Status](http://img.shields.io/travis/alexlangberg/node-sitesampler.svg)](https://travis-ci.org/alexlangberg/node-sitesampler)
|
4 | [![Dependency Status](https://david-dm.org/alexlangberg/node-sitesampler.svg)](https://david-dm.org/alexlangberg/node-sitesampler)
|
5 | [![devDependency Status](https://david-dm.org/alexlangberg/node-sitesampler/dev-status.svg)](https://david-dm.org/alexlangberg/node-sitesampler#info=devDependencies)
|
6 |
|
7 | Data collection sometimes includes collecting the same data over time. This module enables you to collect the text content of websites in [goldwasher](https://www.npmjs.com/package/goldwasher) format over time and store them with the [chronostore](https://www.npmjs.com/package/chronostore) module, thus sampling sites. On top of storing the results as files, it also emits the results when collected, enabling you to further process the data, e.g. pushing the data to a database.
|
8 |
|
9 | A heavy emphasis is put on stability and logging. Everything, even the logging provided by [bunyan](https://www.npmjs.com/package/bunyan), is covered with tests. It also allows you to forward your logging to the console, [loggly](https://www.loggly.com), [logentries](https://logentries.com) and [slack](https://slack.com).
|
10 |
|
11 | Linted with ESLint, tested with tape and 100% coverage with covert.
|
12 |
|
13 | ## Installation
|
14 | ```
|
15 | npm install sitesampler
|
16 | ```
|
17 |
|
18 | ## Logging
|
19 | Logging is performed by bunyan and all logging is enabled with env vars. For instance, to run the example with logging turned on, run the command ```SITESAMPLER_LOG=1 node example.js```.
|
20 |
|
21 | ### loggly
|
22 | Logging can be posted to [loggly](https://www.loggly.com) by setting the following env vars:
|
23 |
|
24 | - ```SITESAMPLER_LOGGLY_SUBDOMAIN```: your loggly subdomain.
|
25 | - ```SITESAMPLER_LOGGLY_TOKEN```: your loggly token.
|
26 | - ```SITESAMPLER_LOGGLY_LEVEL```: the level to log. Defaults to ```info```.
|
27 |
|
28 | ### logentries
|
29 | Logging can be posted to [logentries](https://logentries.com) by setting the following env vars:
|
30 |
|
31 | - ```SITESAMPLER_LOGENTRIES_TOKEN```: your logentries token.
|
32 |
|
33 | ### slack
|
34 | Logging can be posted to [slack](https://slack.com) by setting the following env vars:
|
35 |
|
36 | - ```SITESAMPLER_SLACK_WEBHOOKURL```: your slack webhook url.
|
37 | - ```SITESAMPLER_SLACK_CHANNEL```: your slack channel. Defaults to the channel of the webhook.
|
38 | - ```SITESAMPLER_SLACK_LEVEL```: the level to log. Defaults to ```info```.
|
39 | - ```SITESAMPLER_SLACK_USERNAME```: the username to post with. Defaults to ```sitesampler```.
|
40 |
|
41 | ## Methods
|
42 | ### sitesampler(*[settings]*)
|
43 | When instantiating the sitesampler, it requires settings to work. Settings is thus either an object or a path to a json file containing the settings.
|
44 |
|
45 | ```settings``` (object | string): object with settings or path to settings. Defaults to ```./sitesampler.json```. Properties:
|
46 |
|
47 | - ```targets``` (object) - an array of targets for the [goldwasher-schedule](https://www.npmjs.com/package/goldwasher-schedule) module under the hood.
|
48 | - ```options``` (object) - default options that will be passed through to [goldwasher-schedule](https://www.npmjs.com/package/goldwasher-schedule). See example below or ```sitesampler.default.json```.
|
49 | - ```chronostore``` (object) - default options that will be passed through to [chronostore](https://www.npmjs.com/package/chronostore).
|
50 | - ```rethrowErrors``` (object) - whether sitesampler should rethrow eerrors from goldwasher and chronostore. Defaults to ```true```.
|
51 |
|
52 | ### sitesampler.start()
|
53 | Starts the sitesampler.
|
54 |
|
55 | ### sitesampler.stop()
|
56 | Stops the sitesampler.
|
57 |
|
58 | ## Events
|
59 | Sitesampler is an event emitter that will emit collected results or when an error is encountered. See the example below. Remember to handle errors or your program will crash if an error is encountered. This will, however, usually only happen if you point it at something that isn't HTML.
|
60 |
|
61 | ## Example
|
62 | ```javascript
|
63 | var sitesampler = require('sitesampler');
|
64 | var ss = sitesampler('sitesampler.default.json');
|
65 |
|
66 | ss.on('results', function(data) {
|
67 | console.log(data);
|
68 | });
|
69 |
|
70 | ss.on('error', function(error) {
|
71 | console.log(error);
|
72 | });
|
73 |
|
74 | ss.start();
|
75 | ```
|
76 |
|
77 | ## sitesampler.default.json
|
78 | ```javascript
|
79 | {
|
80 | "targets": [
|
81 | {
|
82 | "url": "http://www.github.com",
|
83 | "rule": { "second": [15, 35, 55] },
|
84 | "goldwasher": {
|
85 | "selector": "h1"
|
86 | }
|
87 | }
|
88 | ],
|
89 | "options": {
|
90 | "goldwasher": {
|
91 | "selector": "h1, h2, h3, h4, h5, h6"
|
92 | }
|
93 | },
|
94 | "chronostore": {
|
95 | "root": "./chronostore"
|
96 | }
|
97 | }
|
98 |
|
99 | ```
|