Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSS feed that will publish all papers whose updated datetime is newer than yesterday. #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import pickle
import argparse
import datetime
import dateutil.parser
from random import shuffle, randrange, uniform

Expand Down Expand Up @@ -205,9 +206,47 @@ def encode_json(ps, n=10, send_images=True, send_abstracts=True):
ret.append(struct)
return ret

# -----------------------------------------------------------------------------
# A class to store values for RSS feed
# -----------------------------------------------------------------------------

class RssValues(object):
def __init__(self, title, link, summary):
self.title = title
self.link = link
self.summary = summary
def __repr__(self):
return "%s at %s" % (self.title, self.link)

# -----------------------------------------------------------------------------
# flask request handling
# -----------------------------------------------------------------------------
@app.route("/recent_rss.xml")
def recent_rss():
vstr = request.args.get('vfilter', 'all')
papers = [db[pid] for pid in DATE_SORTED_PIDS] # precomputed
papers = papers_filter_version(papers, vstr)
render_paper = []
for paper in papers:
if 'updated' in paper:
updated_dt = datetime.datetime.strptime(paper['updated'], "%Y-%m-%dT%H:%M:%SZ")
yesterday_dt = datetime.datetime.today() - datetime.timedelta(days=1)
if updated_dt > yesterday_dt:
continue
summary = ''
title = ''
link = ''
if 'link' in paper:
link = paper['link']
else:
continue # if link does not exist, do not add to list
if 'summary' in paper:
summary = paper['summary']
if 'title' in paper:
title = paper['title']
render_paper.append(RssValues(title, link, summary))
print("render_paper=", render_paper)
return render_template('rss.xml', papers=render_paper)

def default_context(papers, **kws):
top_papers = encode_json(papers, args.num_results)
Expand Down
Binary file added static/rss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ <h1>Arxiv Sanity Preserver</h1>
<input name="q" type="text" id="qfield">
</form>
<div id="search_hint"></div>
<!-- RSS icon from https://upload.wikimedia.org/wikipedia/en/thumb/4/43/Feed-icon.svg/128px-Feed-icon.svg.png-->
<a href="/recent_rss.xml">
<img src="static/rss.png" class="rss-icon" title="Click to subscribe to RSS feed." id="rss" style="width: 40px;">
</a>
</div>

{% if show_prompt == "yes" %}
Expand Down
16 changes: 16 additions & 0 deletions templates/rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>Arxiv Sanity Preserver RSS feed</title>
<link>http://arxiv-sanity.com/</link>
<description>Arxiv Sanity Preserver RSS feed of the latest papers</description>
{% for paper in papers%}
<item>
<title>{{ paper.title }}</title>
<link>{{ paper.link }}</link>
<description>{{ paper.summary }}</description>
</item>
{% endfor %}

</channel>
</rss>