81 lines
2.3 KiB
HTML
81 lines
2.3 KiB
HTML
|
<!doctype html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<script src="https://cdn.jsdelivr.net/pyodide/v0.25.1/full/pyodide.js"></script>
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
|
<style>
|
||
|
body {
|
||
|
color: white;
|
||
|
background-color: black;
|
||
|
padding: 10px;
|
||
|
font-size: 20px;
|
||
|
}
|
||
|
|
||
|
a {
|
||
|
color: white;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
Pyodide rss feed gen test, rss code is rfeed from: <a href="https://github.com/svpino/rfeed">https://github.com/svpino/rfeed<a>, please wait while we generate some xml<br>
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
async function main(){
|
||
|
try {
|
||
|
let pyodide = await loadPyodide();
|
||
|
// Downloading a single file
|
||
|
await pyodide.runPythonAsync(`
|
||
|
from pyodide.http import pyfetch
|
||
|
response = await pyfetch("rfeed.py")
|
||
|
with open("rfeed.py", "wb") as f:
|
||
|
f.write(await response.bytes())
|
||
|
`)
|
||
|
alert("running");
|
||
|
|
||
|
let p = pyodide.runPython(`
|
||
|
import datetime
|
||
|
from rfeed import *
|
||
|
|
||
|
item1 = Item(
|
||
|
title = "First article",
|
||
|
link = "http://www.example.com/articles/1",
|
||
|
description = "This is the description of the first article",
|
||
|
author = "Santiago L. Valdarrama",
|
||
|
guid = Guid("http://www.example.com/articles/1"),
|
||
|
pubDate = datetime.datetime(2014, 12, 29, 10, 00))
|
||
|
|
||
|
item2 = Item(
|
||
|
title = "Second article",
|
||
|
link = "http://www.example.com/articles/2",
|
||
|
description = "This is the description of the second article",
|
||
|
author = "Santiago L. Valdarrama",
|
||
|
guid = Guid("http://www.example.com/articles/2"),
|
||
|
pubDate = datetime.datetime(2014, 12, 30, 14, 15))
|
||
|
|
||
|
feed = Feed(
|
||
|
title = "Sample RSS Feed",
|
||
|
link = "http://www.example.com/rss",
|
||
|
description = "This is an example of how to use rfeed to generate an RSS 2.0 feed",
|
||
|
language = "en-US",
|
||
|
lastBuildDate = datetime.datetime.now(),
|
||
|
items = [item1, item2])
|
||
|
def p():
|
||
|
return feed.rss()
|
||
|
p()
|
||
|
`);
|
||
|
let br = document.createElement('br');
|
||
|
document.body.appendChild(br);
|
||
|
let elemx = document.createElement('a');
|
||
|
elemx.href = 'data:text/xml;charset=utf-8,' + encodeURIComponent(p); // ! encodeURIComponent
|
||
|
elemx.download = "rss.xml";
|
||
|
elemx.innerHTML = "rss.xml"; document.body.appendChild(elemx);
|
||
|
|
||
|
|
||
|
} catch (e){
|
||
|
alert(e);
|
||
|
}
|
||
|
}
|
||
|
main();
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|