Commit 5400acd0 authored by Lysander Trischler's avatar Lysander Trischler

Add support for latest 42 items only

parent dae15f6e
......@@ -27,8 +27,8 @@ __copyright__ = "Copyright 2012, Lysander Trischler"
__license__ = "WTFPL"
__maintainer__ = "Lysander Trischler"
__email__ = "software@lyse.isobeef.org"
__version__ = "0.3"
__version_info__ = (0, 3)
__version__ = "0.4"
__version_info__ = (0, 4)
import os.path
import os
......@@ -55,7 +55,8 @@ DATA_DIR = path(os.getenv("XDG_DATA_HOME", "~/.local/share"), "yfav")
CONFIG_FILE = path(os.getenv("XDG_CONFIG_HOME", "~/.config"), "yfav")
INDEX_FILE = path(DATA_DIR, "index")
CONFIG = Config(CONFIG_FILE)
ATOM_FILE = path(CONFIG.get("atom", "path", "~/srv/yfav.atom"))
ATOM_FILE = path(CONFIG.get("atom", "path", "~/srv/yfav.atom"))
ATOM_42_FILE = path(CONFIG.get("atom", "path_42", "~/srv/yfav.42.atom"))
VIDEO_ID_LEN = 11
VIDEO_ID_URL = "http://youtube.com/watch?v="
......@@ -146,20 +147,20 @@ def gen_atom(max=None):
atom_dirname = os.path.dirname(ATOM_FILE)
if not os.path.exists(atom_dirname):
os.makedirs(atom_dirname)
with open(INDEX_FILE, "r") as index, open(ATOM_FILE, "w") as atom:
with open(INDEX_FILE, "r") as index, open(ATOM_FILE if max is None else ATOM_42_FILE, "w") as atom:
atom.write('<?xml version="1.0" encoding="utf-8"?>'
'<feed xmlns="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">'
'<link rel="self" type="application/atom+xml" href="' + CONFIG.get("atom", "url", "https://lyse.isobeef.org/yfav.atom") + '" />'
'<id>' + CONFIG.get("atom", "id", CONFIG.get("atom", "url", "https://lyse.isobeef.org/yfav.atom")) + '</id>'
'<title>' + CONFIG.get("atom", "title", "Lyse's YouTube videos catapult") + '</title>'
'<subtitle>' + CONFIG.get("atom", "subtitle", "Some awesome videos on YouTube which Lyse thinks are worth to spread. It's mainly a filtered best-of-youtube.com view. Normally updates every 1-2 days.") + '</subtitle>'
'<subtitle>' + CONFIG.get("atom", "subtitle", "Some awesome videos on YouTube which Lyse thinks are worth to spread. It's mainly a filtered best-of-youtube.com view. Normally updates every 1-2 days. Reduced feed with only latest 42 videos is here: https://lyse.isobeef.org/yfav.42.atom") + '</subtitle>'
'<sy:updatePeriod>' + CONFIG.get("atom", "updatePeriod", "daily") + '</sy:updatePeriod>'
'<sy:updateFrequency>' + CONFIG.get("atom", "updateFrequency", "1") + '</sy:updateFrequency>'
'<updated>' + now() + '</updated>'
'<generator>yfav/' + __version__ + '</generator>\n')
lines = reversed(index.readlines())
if max is not None:
lines = lines[:max]
lines = list(lines)[:max]
for line in lines:
video = Video(line=line)
atom.write('<entry><id>' + esc(video.url) + '</id>'
......@@ -208,3 +209,4 @@ if __name__ == "__main__":
for video_id in sys.stdin.readlines():
process(video_id.strip())
gen_atom()
gen_atom(42)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment