Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromechoo committed Oct 27, 2023
0 parents commit d33ffb6
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DIFFBOT_TOKEN=
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
__pycache__
.env
env
*.sh
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# base image
FROM nikolaik/python-nodejs:latest

WORKDIR /app
COPY ./ /app

# install requirements
RUN pip install -r requirements.txt

# start app
EXPOSE 8000
CMD ["gunicorn", "app:app", "-b", "0.0.0.0:8000"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Diffbot

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# RSS Anything

Uses [Diffbot's Extract API](https://www.diffbot.com/products/extract/) to transform lists of links on websites into an RSS feed.

## Installation
[virtualenv](https://virtualenv.pypa.io/en/latest/) recommended but not necessary.

```sh
pip install requirements.txt
flask run
```
64 changes: 64 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import requests
import os
from dotenv import load_dotenv
from feedgen.feed import FeedGenerator
from flask import Flask, request, make_response, render_template

app = Flask(__name__)

load_dotenv()
DIFFBOT_TOKEN = os.getenv("DIFFBOT_TOKEN", None)

@app.route('/')
def index():
return render_template('home.html')

@app.route('/rss')
def rss():

# 1. Extract list from URL
list_url = request.args.get('url', None)
feed_items = []
feed_title = ""
feed_description = ""
feed_url = ""

if not list_url:
return make_response("No URL Provided", 400)

try:
extracted_list_response = requests.get(f"https://api.diffbot.com/v3/list?token={DIFFBOT_TOKEN}&url={list_url}")
extracted_list = extracted_list_response.json()
if extracted_list.get("error", None):
raise Exception(extracted_list.get("error", "Page Error"))
feed_items = extracted_list.get("objects", [])[0].get("items", [])
feed_title = extracted_list.get("objects", [])[0].get("title", "Custom Feed")
feed_description = extracted_list.get("objects", [])[0].get("pageUrl", "")
feed_url = extracted_list.get("objects", [])[0].get("pageUrl", "")
except Exception as e:
print(e)
return make_response(str(e), 400)

# 2. Instantiate a Feed
fg = FeedGenerator()
fg.title(feed_title)
fg.description(feed_description)
fg.link(href=feed_url)

# 3. Generate feed item from list items
for article in feed_items:
if article.get("title", None) and article.get("link", None):
fe = fg.add_entry()
fe.title(article.get("title", ""))
fe.id(article.get("link", ""))
fe.link(href=article.get("link", ""))
fe.description(article.get("summary", ""))
if author := article.get("byline", None) or article.get("author", None):
fe.author(name=author)
if published_date := article.get("date", None):
fe.pubDate(published_date)

# 4. Return feed
response = make_response(fg.rss_str())
response.headers.set('Content-Type', 'application/rss+xml')
return response
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.7'

services:
rssanything:
restart: always
container_name: rssanything
build:
context: .
dockerfile: Dockerfile
ports:
- '3011:8000'
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
feedgen
Flask
requests
python-dotenv
gunicorn
11 changes: 11 additions & 0 deletions static/diffbot-logomark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/rss-anything-example.webp
Binary file not shown.
254 changes: 254 additions & 0 deletions static/rss-anything-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>RSS Anything</title>
<meta name="description" content="Transform any old website with a list of links into an RSS or Atom Feed" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Prata&text=RSS%20Anything">
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
-webkit-font-smoothing: antialiased;
background: rgb(255,251,245);
background: linear-gradient(180deg, rgba(255,251,245,1) 0%, rgba(255,255,255,1) 100%);
}
h1.title-font {
font-family:"Prata";
}
</style>
</head>
<body class="min-h-screen py-24 px-4">
<section class="text-slate-600 body-font">
<div class="container mx-auto flex w-auto items-center justify-center flex-col">
<img class="object-center rounded" width="150" alt="hero" src="{{ url_for('static', filename='rss-anything-icon.svg') }}">
<div class="text-center lg:w-2/3 w-full mt-10">
<h1 class="title-font text-4xl sm:text-5xl mb-4 text-slate-900 font-bold">RSS Anything</h1>
<p class="mb-3 text-xl text-slate-500">Transform any old website with a list of links into an RSS Feed</p>
<div class="flex justify-center">
<form action="/rss" method="GET" class="mt-6 flex gap-x-4 w-full">
<label for="url" class="sr-only">Enter a URL</label>
<input id="url" name="url" type="url" required class="min-w-0 flex-auto rounded-md border border-slate-200 bg-white/3 px-4 py-3 shadow-sm ring-1 ring-inset ring-white/10 focus:ring-2 focus:ring-inset focus:ring-sky-500 sm:leading-6" placeholder="Enter a URL">
<button type="submit" class="flex-none rounded-md bg-sky-500 px-5 py-3.5 font-semibold text-white shadow-sm hover:bg-sky-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500">Get Feed URL</button>
</form>
</div>
</div>
</div>
</section>
<section class="text-slate-600 body-font">
<div class="container mx-auto flex w-auto items-center justify-items-start flex-col mb-10">
<div class="lg:w-2/3 w-full mt-10">
<img class="object-cover" alt="Screenshot of theatlantic.com's Work in Progress category page in the background of another screenshot. The foreground screenshot is of the Reeder app opened to the Work in Progress section. The same feed of news articles can be observed on both screenshots." src="{{ url_for('static', filename='rss-anything-example.webp') }}">
</div>
</div>
</section>
<section>
<div class="container mx-auto flex flex-col items-center antialiased text-slate-600">
<div class="mb-6 w-full lg:w-2/3 flex items-top">
<a href="https://www.diffbot.com" class="me-3 pt-1"><img src="{{ url_for('static', filename='diffbot-logomark.svg') }}" width="50" /></a>
<span class="text-sm">
<strong>With ❤️ from <a href="https://www.diffbot.com" class="text-sky-600 hover:underline">Diffbot</a></strong>
<br />Because <a href="https://masto.ai/@jeromechoo" class="hover:underline">Jerome</a> wants to read all the things in RSS
</span>
</div>
</div>
</section>
</body>
</html>

0 comments on commit d33ffb6

Please sign in to comment.