initial commit
This commit is contained in:
commit
ec2ad40744
10 changed files with 135994 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
media/
|
67911
chompers.rss
Normal file
67911
chompers.rss
Normal file
File diff suppressed because it is too large
Load diff
82
download.py
Normal file
82
download.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
import xml.etree.ElementTree as ET
|
||||
from email.utils import parsedate_to_datetime
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import json
|
||||
from urllib.parse import urlparse
|
||||
import os
|
||||
|
||||
|
||||
def parseXML(xmlfile):
|
||||
tree = ET.parse(xmlfile)
|
||||
|
||||
root = tree.getroot()
|
||||
|
||||
episodes = []
|
||||
|
||||
for item in root.findall('./channel/item'):
|
||||
episode = {}
|
||||
|
||||
for child in item:
|
||||
if child.tag == 'enclosure':
|
||||
episode['download_url'] = child.attrib['url']
|
||||
if child.tag == 'pubDate':
|
||||
date = child.text
|
||||
episode['date'] = parsedate_to_datetime(date).isoformat()
|
||||
if child.tag == "title":
|
||||
episode['title'] = child.text
|
||||
if child.tag == "description":
|
||||
episode['summary'] = child.text.rstrip("Learn more about your ad choices. Visit podcastchoices.com/adchoices")
|
||||
|
||||
episodes.append(episode)
|
||||
|
||||
return episodes
|
||||
|
||||
def save_json(episodes):
|
||||
json_store = {}
|
||||
json_store["episodes"] = episodes
|
||||
json_data = json.dumps(json_store)
|
||||
|
||||
with open("episodes.json", mode="wb") as file:
|
||||
file.write(json_data.encode("UTF-8"))
|
||||
|
||||
|
||||
def download_episodes(episodes):
|
||||
|
||||
downloaded = []
|
||||
|
||||
for episode in episodes:
|
||||
download = {}
|
||||
filename = os.path.basename(urlparse(episode["download_url"]).path)
|
||||
download["date"] = episode["date"]
|
||||
download["title"] = episode["title"]
|
||||
download["summary"] = episode["summary"]
|
||||
download["filename"] = filename
|
||||
print(download["date"], download["filename"])
|
||||
|
||||
# response = requests.get(episode["download_url"])
|
||||
|
||||
# with open("media/"+download["filename"], mode="wb") as file:
|
||||
# file.write(response.content)
|
||||
|
||||
downloaded.append(download)
|
||||
|
||||
return downloaded
|
||||
|
||||
def main():
|
||||
to_download = parseXML('chompers.rss')
|
||||
|
||||
# for episode in to_download:
|
||||
# print(episode['date'], ": ", episode['download_url'])
|
||||
|
||||
downloaded_episodes = download_episodes(to_download)
|
||||
|
||||
# for episode in downloaded_episodes:
|
||||
# print(episode['date'], ": ", episode['filename'])
|
||||
|
||||
save_json(downloaded_episodes)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
1
episodes.json
Normal file
1
episodes.json
Normal file
File diff suppressed because one or more lines are too long
88
index.html
Normal file
88
index.html
Normal file
|
@ -0,0 +1,88 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Chompers Rewind</title>
|
||||
<link rel="apple-touch-icon" href="logo_180.jpg" />
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<div style="text-align:center;width:100%;font-family: sans-serif;">
|
||||
<h1>Chompers Rewind</h1>
|
||||
<p>Playing through the best <span id="episode_count"></span> episodes of Chompers on a four year delay.</p>
|
||||
|
||||
<p><strike>Today's</strike> Our pretend date is <span id="past"></span>.</p>
|
||||
<div style="float:left;width:350px;height:100%;padding:20px;">
|
||||
<p>
|
||||
<a onclick="document.getElementById('player').play();">
|
||||
<img src="logo_1024.jpg" style="max-width:300;" />
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<div style="float:left:width:50%;padding:20px;">
|
||||
|
||||
|
||||
<h2>Today's Episode:</h2>
|
||||
<h3><span id="title"></span></h3>
|
||||
<p>Originally published: <span id="epDate"></span></h2>
|
||||
<p style="margin:0em auto;"><span id="summary"></span></p>
|
||||
|
||||
<p style="display:none"><span id="epFilename"></span></p>
|
||||
|
||||
<p><audio id="player" controls="controls">
|
||||
<source id="srcID" src=""></source>
|
||||
</audio></p>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
|
||||
function GetJson(url) {
|
||||
var httpreq = new XMLHttpRequest();
|
||||
httpreq.open("GET", url, false);
|
||||
httpreq.send(null);
|
||||
jsonobj = JSON.parse(httpreq.responseText);
|
||||
return jsonobj;
|
||||
}
|
||||
|
||||
function nearestEpisode(episodes, target) {
|
||||
let minDifference = Infinity;
|
||||
let closestEpisode = {};
|
||||
|
||||
episodes.forEach(function (episode, index) {
|
||||
let difference = Math.abs(Date.parse(episode.date) - target);
|
||||
if ( difference < minDifference ) {
|
||||
minDifference = difference;
|
||||
closestEpisode = episode;
|
||||
}
|
||||
});
|
||||
|
||||
return closestEpisode;
|
||||
|
||||
}
|
||||
|
||||
var jsonobj = GetJson("episodes.json");
|
||||
|
||||
var past = new Date(new Date().setFullYear(new Date().getFullYear() - 4));
|
||||
|
||||
document.getElementById("episode_count").textContent = jsonobj.episodes.length;
|
||||
|
||||
document.getElementById("past").textContent = past.toLocaleTimeString('en-us', { weekday:"long", year:"numeric", month:"short", day:"numeric", hour:"2-digit", minute:"2-digit"})
|
||||
|
||||
let todaysEpisode = nearestEpisode(jsonobj.episodes, past);
|
||||
|
||||
document.getElementById("title").textContent = todaysEpisode.title;
|
||||
|
||||
document.getElementById("epDate").textContent = new Date(Date.parse(todaysEpisode.date)).toLocaleTimeString('en-us', { weekday:"long", year:"numeric", month:"short", day:"numeric", hour: "2-digit", minute: "2-digit" });
|
||||
|
||||
document.getElementById("summary").textContent = todaysEpisode.summary;
|
||||
|
||||
document.getElementById("epFilename").textContent = todaysEpisode.filename;
|
||||
|
||||
document.getElementById("srcID").setAttribute("src", "https://minio.andr3w.net/chompers/media/" + todaysEpisode.filename);
|
||||
|
||||
document.getElementById("player").load();
|
||||
document.getElementById("player").play();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
BIN
logo.jpg
Normal file
BIN
logo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 MiB |
BIN
logo_1024.jpg
Normal file
BIN
logo_1024.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 136 KiB |
BIN
logo_1024.jpg~
Normal file
BIN
logo_1024.jpg~
Normal file
Binary file not shown.
After Width: | Height: | Size: 136 KiB |
BIN
logo_180.jpg
Normal file
BIN
logo_180.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
67911
original chompers.rss
Normal file
67911
original chompers.rss
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue