88 lines
1.7 KiB
JavaScript
88 lines
1.7 KiB
JavaScript
/**
|
|
* Created by WebStorm.
|
|
* User: martin
|
|
* Date: 16/04/2020
|
|
* Time: 16:46
|
|
|
|
*/
|
|
|
|
const Parser = require('rss-parser');
|
|
|
|
class MasterReader {
|
|
constructor() {
|
|
this.url = '';
|
|
this.items = [];
|
|
this.feeditems = [];
|
|
this.currentPage = null;
|
|
this.hosturl = '';
|
|
this.siteid = '';
|
|
this.requestOptions = {
|
|
'url' : '',
|
|
'proxy' : 'http://uk.proxymesh.com:31280',
|
|
'tunnel' : true
|
|
};
|
|
}
|
|
|
|
getContent(url) {
|
|
// return new pending promise
|
|
return new Promise((resolve, reject) => {
|
|
// select http or https module, depending on reqested url
|
|
// const lib = url.startsWith('https') ? require('https') : require('http');
|
|
const options = Object.assign({}, this.requestOptions);
|
|
console.log(options);
|
|
options.url = url;
|
|
|
|
console.log(options);
|
|
|
|
request(options, (err, _res, body) => {
|
|
if (!err)
|
|
resolve(body);
|
|
else
|
|
|
|
reject(err);
|
|
});
|
|
});
|
|
};
|
|
|
|
setFeed(newUrl) {
|
|
this.url = newUrl;
|
|
}
|
|
|
|
async getFeed() {
|
|
console.log('>> getFeed: fetching', this.url);
|
|
|
|
const parser = new Parser();
|
|
const feed = await parser.parseURL(this.url);
|
|
|
|
|
|
console.log(feed);
|
|
|
|
this.feeditems = [...feed.items];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class JobserveReader extends MasterReader {
|
|
constructor(props) {
|
|
super(props);
|
|
this.hosturl = 'https://jobserve.com';
|
|
this.siteid = 'jobserve';
|
|
}
|
|
|
|
async processFeed() {
|
|
await this.getFeed();
|
|
if (this.feeditems.length > 0) {
|
|
|
|
} else {
|
|
console.log('Nothing to process');
|
|
}
|
|
}
|
|
}
|
|
|
|
const jobServeReader = new JobserveReader();
|
|
|
|
jobServeReader.setFeed('https://www.jobserve.com/MySearch/846CDA8658FF93A3.rss');
|
|
|
|
jobServeReader.processFeed();
|