-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (59 loc) · 1.52 KB
/
index.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
75
76
const cheerio = require('cheerio');
const fetch = require('node-fetch');
const ffeed = require('feed').Feed;
const express = require('express')
var fs = require('fs');
const app = express()
const PORT = process.env.PORT || 5000;
//const port = 3000
var xx2;
app.get('/', (req, res) => {
xy();
//res.send('Hello World!')
res.send(xx2)
})
app.listen(PORT, () => {
console.log(`Example app listening on port ${PORT}`)
})
var dirPath = __dirname + "/rssfeed.xml";
async function xy(){
const url = 'http://www.ptinews.com/home.aspx';
const response = await fetch(url);
const body = await response.text();
//create new feed
const feed = new ffeed({
title: 'PTI News',
description: 'PTI News',
id: 'http://www.ptinews.com/home.aspx',
link: 'http://www.ptinews.com/home.aspx',
image: 'http://www.ptinews.com/images/logo.png',
});
let $ = cheerio.load(body);
let title = $('title');
console.log(title.text());
//let xy1 = $('a[class=catLatestHeadli]').();
$('a[class=catLatestHeadli]').each((_, e) => {
let row = $(e).text();
console.log(`${row}`);
console.log(row);
date = new Date()
feed.addItem({
title: row,
id: row,
link: row,
description: row,
content: row,
date: date
});
});
var rssdoc = feed.rss2();
xx2=rssdoc;
fs.writeFile(dirPath, rssdoc, function(err) {
if(err) {
return console.log(err);
}
});
// res.render('index');
//console.log(xy1);
}
//xy();