@grodno-city/alis-web-request
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -210,12 +210,11 @@ 'use strict'; | ||
function collectFields(table) { | ||
var fields = []; | ||
var data = table.children().toArray(); | ||
data.shift(); | ||
data.forEach(function (el) { | ||
fields.push({ | ||
tag: el.children[0].children[0].children[0].data, | ||
value: el.children[1].children[0].data | ||
}); | ||
}); | ||
function collectFields($, table) { | ||
var fields = table.find('tr').filter(function (i, tr) { | ||
return $('tr:nth-child(1) th:nth-child(1)', tr).text() !== 'Название'; | ||
}).map(function (i, tr) { | ||
return { | ||
tag: $('td:nth-child(1)', tr).text(), | ||
value: $('td:nth-child(2)', tr).text() | ||
}; | ||
}).get(); | ||
return fields; | ||
@@ -263,3 +262,3 @@ } | ||
references: references ? collectReferences(references) : [], | ||
fields: fields ? collectFields(fields) : [], | ||
fields: fields ? collectFields($, fields) : [], | ||
funds: funds ? collectFunds(funds) : [] | ||
@@ -266,0 +265,0 @@ }; |
@@ -0,0 +0,0 @@ { |
{ | ||
"name": "@grodno-city/alis-web-request", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"main": "./lib/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/grodno-city/alis-web-request.git", |
@@ -9,3 +9,3 @@ # alis-web-request | ||
``` | ||
npm install @grodno-city/alis-web-request --save-dev | ||
npm install @grodno-city/alis-web-request --save | ||
``` | ||
@@ -18,58 +18,16 @@ | ||
## API methods | ||
## Publishing public scoped package to npm registry | ||
* sendInitialQuery - make initial http query to alis library for get main page and cookie id. | ||
* getPage - get page body from the specified url. | ||
* getNumberedPageUrls - get firs ten numbered urls from main page. | ||
* getNextPageUrl - get next page url from the specified url. | ||
* processItems - to managements another functions getPage, getNextPageUrl, pushItemsToStream. | ||
* getItems - get id with title all books on the page. | ||
* run - run processItems function over queue with options. | ||
* ReadableStreamItems - readable stream for read items. | ||
update version in package.json | ||
``` | ||
"version": "1.1.1" -> "version": "1.1.2" | ||
``` | ||
## Example | ||
```js | ||
import Stream from 'stream'; | ||
import { sendInitialQuery, getNumberedPageUrls, run, processItems, parsePage, ReadableStreamItems } from '@grodno-city/alis-web-request'; | ||
const WritableStreamItems = new Stream.Writable({ objectMode: true }); | ||
ReadableStreamItems.pipe(WritableStreamItems); | ||
const initParams = { | ||
year: 2017, | ||
alisEndpoint: 'http://86.57.174.45', | ||
}; | ||
sendInitialQuery(initParams, (err, res) => { | ||
if (err) { | ||
return new Error(err); | ||
} | ||
const options = { | ||
alisEndpoint: initParams.alisEndpoint, | ||
jar: res.jar, | ||
}; | ||
const $ = parsePage(res.page); | ||
const firstNumberedPageUrls = getNumberedPageUrls($); | ||
run(processItems, firstNumberedPageUrls, options); | ||
}); | ||
const items = []; | ||
WritableStreamItems._write = (item, encoding, done) => { | ||
items.push(item); | ||
done(); | ||
}; | ||
run command | ||
``` | ||
npm publish --access public | ||
``` | ||
## Authors | ||
* **Vadim Demyanchik** - [GitHub](https://github.com/DemyanchikVadim) | ||
* **Pavel Zubkou** - [GitHub](https://github.com/irnc) | ||
## License | ||
[MIT License ](https://github.com/grodno-city/alis-web-request/blob/master/LICENSE) |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
110049
350
32