adding real time report
This commit is contained in:
parent
a7cfeffc2e
commit
a75903bc07
|
@ -0,0 +1,40 @@
|
|||
config = {
|
||||
"r/DankMemes": {
|
||||
"link":"https://reddit.com/r/dankmemes/.rss?sort=hot",
|
||||
"limit": 5
|
||||
},
|
||||
"BuzzFeed - India": {
|
||||
"link":"https://www.buzzfeed.com/in.xml",
|
||||
"limit": 5
|
||||
},
|
||||
"New Yorker":{
|
||||
"link":"http://www.newyorker.com/feed/news",
|
||||
"limit": 5
|
||||
},
|
||||
"Vox":{
|
||||
"link":"https://www.vox.com/rss/index.xml",
|
||||
"limit": 3
|
||||
},
|
||||
"The Hindu: Sports":{
|
||||
"link":"https://www.thehindu.com/sport/feeder/default.rss",
|
||||
"limit":5
|
||||
},
|
||||
"The Hindu: National News":{
|
||||
"link":"https://www.thehindu.com/news/national/feeder/default.rss",
|
||||
"limit": 5
|
||||
},
|
||||
"r/Jokes":{
|
||||
"link":"https://reddit.com/r/Jokes/hot/.rss?sort=hot",
|
||||
"limit":5
|
||||
}
|
||||
}
|
||||
|
||||
config_extra = {
|
||||
"Responsive-Images": true,
|
||||
"direct-link": true,
|
||||
"show-date":true,
|
||||
"left-column":true,
|
||||
"defaults": {
|
||||
"limit": 5
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,176 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>
|
||||
News Now
|
||||
</title>
|
||||
<!--
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">-->
|
||||
<link rel="stylesheet" href="./css/bootstrap.min.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1 align="center" class="display-1">News Now</h1>
|
||||
<main>
|
||||
<div class="container">
|
||||
<div class="list-group pb-4" id="contents"></div>
|
||||
|
||||
<div id="feed">
|
||||
<!--
|
||||
<div class="card bg-dark text-white">
|
||||
<img class="card-img" src=".../100px270/#55595c:#373a3c/text:Card image" alt="Card image">
|
||||
<div class="card-img-overlay">
|
||||
<h5 class="card-title">Card title</h5>
|
||||
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
|
||||
<p class="card-text">Last updated 3 mins ago</p>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
</div></div>
|
||||
</main>
|
||||
<script type="text/javascript" src="./config.json"></script>
|
||||
<script src="./js/rss-parser.js"></script>
|
||||
<script>
|
||||
|
||||
const feeds = config // Edit config.json
|
||||
|
||||
// Note: some RSS feeds can't be loaded in the browser due to CORS security.
|
||||
// To get around this, you can use a proxy
|
||||
const CORS_PROXY = "https://cors-anywhere.herokuapp.com/"
|
||||
|
||||
//let parser = new RSSParser();
|
||||
var contents_title = document.createElement("h2")
|
||||
contents_title.textContent = "Contents"
|
||||
contents_title.classList.add("pb-1")
|
||||
document.getElementById("contents").appendChild(contents_title)
|
||||
|
||||
async function myfunc(key){
|
||||
var contents = document.createElement("a")
|
||||
contents.href = "#" + key
|
||||
contents.classList.add("list-group-item","list-group-item-action")
|
||||
contents.textContent = key
|
||||
document.getElementById("contents").appendChild(contents)
|
||||
var feed_div = document.createElement("div")
|
||||
feed_div.id = key
|
||||
feed_div.setAttribute("id", key);
|
||||
var title = document.createElement("h2");
|
||||
title.textContent = "From " + key;
|
||||
title.classList.add("pb-1")
|
||||
feed_div.appendChild(title)
|
||||
document.getElementById("feed").appendChild(feed_div)
|
||||
var parser = new RSSParser();
|
||||
var countPosts = 0
|
||||
parser.parseURL(feeds[key]["link"], function(err, feed) {
|
||||
if (err) throw err;
|
||||
feed.items.forEach(function(entry) {
|
||||
if (countPosts < feeds[key]["limit"]) {
|
||||
var node = document.createElement("div");
|
||||
node.classList.add("card","mb-3");
|
||||
var row = document.createElement("div")
|
||||
row.classList.add("row","no-gutters")
|
||||
|
||||
if (config_extra["left-column"]){
|
||||
var left_col = document.createElement("div")
|
||||
left_col.classList.add("col-md-2")
|
||||
var left_col_body = document.createElement("div")
|
||||
left_col_body.classList.add("card-body")
|
||||
}
|
||||
|
||||
var right_col = document.createElement("div")
|
||||
if (config_extra["left-column"]){
|
||||
right_col.classList.add("col-md-10")
|
||||
}
|
||||
var node_title = document.createElement("h5")
|
||||
|
||||
node_title.classList.add("card-header")
|
||||
node_title.innerHTML = entry.title
|
||||
|
||||
node_body = document.createElement("div")
|
||||
node_body.classList.add("card-body")
|
||||
|
||||
node_content = document.createElement("p")
|
||||
node_content.innerHTML = entry.content
|
||||
node_content.classList.add("card-text")
|
||||
|
||||
if (config_extra["direct-link"]){
|
||||
node_link = document.createElement("p")
|
||||
node_link.classList.add("card-text")
|
||||
node_link.innerHTML = "<b>Link:</b> <a href='" + entry.link +"'>Direct Link</a>"
|
||||
if (config_extra["left-column"]){
|
||||
left_col_body.appendChild(node_link)
|
||||
} else {
|
||||
node_content.appendChild(node_link)
|
||||
}
|
||||
}
|
||||
|
||||
if (config_extra["show-date"]){
|
||||
node_date = document.createElement("p")
|
||||
node_date.classList.add("card-text")
|
||||
node_date.innerHTML = "<p><b>Date: </b>" + entry.pubDate + "</p>"
|
||||
if (config_extra["left-column"]){
|
||||
left_col_body.appendChild(node_date)
|
||||
} else {
|
||||
node_content.appendChild(node_date)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
node.appendChild(node_title)
|
||||
|
||||
node_body.appendChild(node_content)
|
||||
|
||||
right_col.appendChild(node_body)
|
||||
|
||||
if (config_extra["left-column"]){
|
||||
left_col.appendChild(left_col_body)
|
||||
row.appendChild(left_col)
|
||||
}
|
||||
|
||||
row.appendChild(right_col)
|
||||
|
||||
node.appendChild(row)
|
||||
//node_body.appendChild(node_date)
|
||||
//node.appendChild(node_body)
|
||||
document.getElementById(key).appendChild(node)
|
||||
/*console.log(entry.title + ':' + entry.link);
|
||||
console.log(entry.pubDate)*/
|
||||
//console.log(entry.author)
|
||||
|
||||
|
||||
|
||||
countPosts+=1
|
||||
}
|
||||
})
|
||||
|
||||
if (config_extra["Responsive-Images"]){
|
||||
var inputs = document.getElementsByTagName('img')
|
||||
console.log(inputs)
|
||||
for(var i = 0; i < inputs.length; i++) {
|
||||
inputs[i].classList.add("img-fluid")
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
(async () => {
|
||||
for(var key in feeds) {
|
||||
let result = await myfunc(key);
|
||||
console.log(result)
|
||||
}})();
|
||||
|
||||
/*
|
||||
var inputs = document.getElementsByTagName('img');
|
||||
for(var i = 0; i < inputs.length; i++) {
|
||||
inputs[i].classList.add("img-fluid")
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
</script>
|
||||
<noscript>Uh Oh! Your browser does not support JavaScript or JavaScript is currently disabled. Please enable JavaScript or switch to a different browser.</noscript>
|
||||
</body></html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue