Created
May 10, 2017 17:35
-
-
Save rram/94d6c8e48c7ed70d7b350e03e75ad517 to your computer and use it in GitHub Desktop.
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
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet | |
version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:atom="http://www.w3.org/2005/Atom" | |
xmlns:xhtml="http://www.w3.org/1999/xhtml"> | |
<xsl:output method="text" /> | |
<xsl:param name="skip_self_posts" select="true()" /> | |
<xsl:template match="/"> | |
<xsl:variable name="subreddit" select="/atom:feed/atom:category/@term" /> | |
<xsl:for-each select="/atom:feed/atom:entry"> | |
<xsl:choose> | |
<xsl:when test="$skip_self_posts and starts-with(.//xhtml:a[text()='[link]']/@href, concat('https://www.reddit.com/r/', $subreddit))" > | |
<!-- This entry is a self post. Skip it --> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="atom:title" /> | |
% | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:for-each> | |
</xsl:template> | |
</xsl:stylesheet> |
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
#!/bin/bash | |
template="/usr/local/share/xml/misc/reddittitles.xsl" | |
fortunes="/usr/local/games/fortunes" | |
for sr in $@ | |
do | |
if [ 20 -lt ${#sr} ]; then | |
echo "Invalid subreddit: $sr" >&2 | |
continue | |
fi | |
tmp=$(mktemp --tmpdir redditfortune.$sr.XXX) | |
curl -Atardis-fortune-updater -s "https://www.reddit.com/r/$sr/.xml" | xsltproc -o $tmp $template - 2>/dev/null | |
if [ 0 -ne $? ]; then | |
echo "Processing /r/$sr failed!" >&2 | |
rm -f $tmp | |
continue | |
fi | |
strfile -s $tmp | |
chmod 644 $tmp | |
mv -f "$tmp" "$fortunes/$sr" | |
mv -f "$tmp.dat" "$fortunes/$sr.dat" | |
cd $fortunes | |
ln -s -f "$sr" "$sr.u8" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment