Created
September 5, 2020 15:14
-
-
Save scripting/15d68e91138623715d17bebcdef15a2e to your computer and use it in GitHub Desktop.
Reading BingeWorthy's RSS feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const urlfeed = "http://bingeworthy.io/rss.xml"; | |
function httpRequest (url, timeout, headers, callback) { | |
timeout = (timeout === undefined) ? 30000 : timeout; | |
var jxhr = $.ajax ({ | |
url: url, | |
dataType: "text", | |
headers, | |
timeout | |
}) | |
.success (function (data, status) { | |
callback (undefined, data); | |
}) | |
.error (function (status) { | |
var err = { | |
code: status.status, | |
message: JSON.parse (status.responseText).message | |
}; | |
callback (err); | |
}); | |
} | |
function readFeed (url, callback) { | |
httpRequest (url, undefined, undefined, function (err, xmltext) { | |
if (err) { | |
console.log ("readFeed: err.message == " + err.message); | |
callback (err); | |
} | |
else { | |
var xstruct = $($.parseXML (xmltext)); | |
var adrchannel = xmlGetAddress (xstruct, "channel"); | |
function getChannelValue (name) { | |
var val = xmlGetValue (adrchannel, name); | |
return (val); | |
} | |
var theFeed = { | |
title: getChannelValue ("title"), | |
link: getChannelValue ("link"), | |
description: getChannelValue ("description"), | |
pubDate: getChannelValue ("pubDate"), | |
language: getChannelValue ("language"), | |
generator: getChannelValue ("generator"), | |
docs: getChannelValue ("docs"), | |
lastBuildDate: getChannelValue ("lastBuildDate"), | |
items: new Array () | |
} | |
$(adrchannel).children ("item").each (function () { | |
var item = this; | |
function getItemValue (name) { | |
var val = undefined; | |
$(item).children (name).each (function () { | |
val = $(this).text (); | |
}); | |
return (val); | |
} | |
theFeed.items.push ({ | |
title: getItemValue ("title"), | |
description: getItemValue ("description"), | |
pubDate: getItemValue ("pubDate"), | |
guid: getItemValue ("guid") | |
}); | |
}); | |
console.log ("readFeed: theFeed == " + jsonStringify (theFeed)); | |
callback (undefined, theFeed); | |
} | |
}); | |
} | |
function viewFeed (theFeed) { | |
const xmlviewerLink = "http://xmlviewer.scripting.com/?url=" + urlfeed; | |
var htmltext = "", indentlevel = 0; | |
function add (s) { | |
htmltext += filledString ("\t", indentlevel) + s + "\n"; | |
} | |
add ("<div class=\"divFeedTitle\"><a href=\"" + xmlviewerLink + "\">" + theFeed.title + "</a></div>"); | |
add ("<div class=\"divFeedDescription\">" + theFeed.description + "</div>"); | |
add ("<div class=\"divFeedLink\"><a href=\"" + theFeed.link + "\">" + theFeed.link + "</a></div>"); | |
add ("<div class=\"divFeedPubDate\">Updated: " + theFeed.pubDate + "</div>"); | |
add ("<div class=\"divFeedGenerator\">Generator: " + theFeed.generator + "</div>"); | |
add ("<table class=\"table divFeedViewerTable\""); indentlevel++; | |
theFeed.items.forEach (function (item) { | |
add ("<tr>"); indentlevel++; | |
add ("<td><div class=\"divItemTitle\">" + item.title + "</div></td>"); | |
add ("<td><div class=\"divPubDate\">" + getFacebookTimeString (item.pubDate) + "</div></td>"); | |
add ("</tr>"); indentlevel--; | |
}); | |
add ("</table>"); indentlevel--; | |
$("#idFeedViewer").html (htmltext); | |
} | |
function startup () { | |
readFeed (urlfeed, function (err, theFeed) { | |
if (err) { | |
} | |
else { | |
viewFeed (theFeed); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>BingeWorthy feed viewer</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script src="//s3.amazonaws.com/scripting.com/code/includes/jquery-1.9.1.min.js"></script> | |
<link href="//s3.amazonaws.com/scripting.com/code/includes/bootstrap.css" rel="stylesheet"> | |
<script src="//s3.amazonaws.com/scripting.com/code/includes/bootstrap.min.js"></script> | |
<link rel="stylesheet" href="//s3.amazonaws.com/scripting.com/code/fontawesome/css/all.css"> | |
<link href="//fonts.googleapis.com/css?family=Ubuntu:400,500i,700" rel="stylesheet"> | |
<link href="//fonts.googleapis.com/css?family=Rancho" rel="stylesheet"> | |
<script src="//s3.amazonaws.com/scripting.com/code/includes/basic/code.js"></script> | |
<link href="//s3.amazonaws.com/scripting.com/code/includes/basic/styles.css" rel="stylesheet" type="text/css"> | |
<script src="http://fargo.io/code/shared/xml.js"></script> | |
<script src="code.js"></script> | |
<link href="styles.css" rel="stylesheet" type="text/css"> | |
</head> | |
<body> | |
<div class="divPageBody"> | |
<div class="divFeedViewer" id="idFeedViewer"> | |
</div> | |
</div> | |
<script> | |
$(document).ready (function () { | |
startup (); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: Ubuntu; | |
font-size: 18px; | |
} | |
.divPageBody { | |
margin-top: 60px; | |
width: 60%; | |
margin-left: auto; | |
margin-right: auto; | |
} | |
.divFeedTitle { | |
font-size: 32px; | |
font-weight: bold; | |
margin-bottom: .5em; | |
} | |
.divFeedTitle a { | |
color: black; | |
cursor: pointer; | |
} | |
.divFeedLink { | |
font-size: 18px; | |
margin-bottom: .3em; | |
} | |
.divFeedDescription { | |
font-size: 18px; | |
margin-bottom: .3em; | |
} | |
.divFeedPubDate { | |
font-size: 18px; | |
margin-bottom: .3em; | |
} | |
.divFeedGenerator { | |
font-size: 18px; | |
margin-bottom: 1em; | |
} | |
.divItemTitle, .divPubDate { | |
} | |
.divFeedViewerTable td { | |
padding: 3px; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment