all repos — site @ b4dedd7569c3f89d5e16371d49bd315b7094cf2c

source for my site, found at icyphox.sh

Move openring.py back to bin

Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Anirudh Oppiliappan x@icyphox.sh
Tue, 26 May 2020 19:07:25 +0530
commit

b4dedd7569c3f89d5e16371d49bd315b7094cf2c

parent

48d4846a63739c24703e979815eb6266039b793e

3 files changed, 54 insertions(+), 4 deletions(-)

jump to
D .gitmodules

@@ -1,3 +0,0 @@

-[submodule "bin/openring"] - path = bin/openring - url = https://github.com/icyphox/openring.py
A bin/openring.py

@@ -0,0 +1,53 @@

+#!/usr/bin/env python3 +# openring.py - generate a webring from rss feeds + +import feedparser +import arrow +import jinja2 +import random +import sys +from lxml import html +from jinja2 import DebugUndefined + +def jinja_render(html, tmpl): + template_loader = jinja2.FileSystemLoader("./") + env = jinja2.Environment(loader=template_loader, undefined=DebugUndefined) + try: + template = env.get_template(tmpl) + except jinja2.exceptions.TemplateNotFound: + print("error: template not found") + + out = template.render(feeds=html) + return out + + +with open("feeds.txt") as f: + feeds = f.readlines() + +html_out = [] + +for f in random.sample(feeds, 3): + fp = feedparser.parse(f) + feed_link = fp.feed.link + feed_title = fp.feed.title + print(feed_title) + full_summ = str(html.fromstring(fp.entries[0].summary).text_content()) + trunc_summ = full_summ[:256] + "…" + pub_date = fp.entries[0].published + pretty_date = arrow.get(pub_date, "ddd, DD MMM YYYY HH:mm:ss Z").format("MMM DD, YYYY") + post_link = fp.entries[0].link + post_title = fp.entries[0].title + + html_out.append(f"""<div class="openring-feed"> + <h4><a href="{post_link}">{post_title}</a></h4> + <p>{trunc_summ}</p> + + <p>via <a href="{feed_link}">{feed_title}</a></p> + {pretty_date} + </div> + """ + ) + +rendered = jinja_render(html_out, "templates/openring.html") +with open("templates/text.html", "w") as t: + t.write(rendered)
M config.pyconfig.py

@@ -54,5 +54,5 @@ </a>

</div> """ template = 'text.html' # default is index.html -pre_build = ['/home/icy/code/openring/openring.py'] +pre_build = ['./bin/openring.py'] post_build = ['./bin/rss.py', './bin/update_index.py']