From de4c69f34c624a32dd04e05d9c821ba63a76057e Mon Sep 17 00:00:00 2001 From: crunk Date: Sat, 3 Jun 2023 18:12:55 +0200 Subject: [PATCH] first commit --- .gitignore | 11 ++++++++++ README.md | 16 ++++++++++++++ app.py | 14 +++++++++++++ column.py | 12 +++++++++++ columns.toml | 11 ++++++++++ parse_rss_feeds.py | 22 ++++++++++++++++++++ pyproject.toml | 22 ++++++++++++++++++++ quick_test.py | 20 ++++++++++++++++++ start.py | 44 +++++++++++++++++++++++++++++++++++++++ static/css/base.css | 34 ++++++++++++++++++++++++++++++ templates/base.html | 14 +++++++++++++ templates/index.html | 16 ++++++++++++++ templates/singlefeed.html | 10 +++++++++ 13 files changed, 246 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 app.py create mode 100644 column.py create mode 100644 columns.toml create mode 100644 parse_rss_feeds.py create mode 100644 pyproject.toml create mode 100644 quick_test.py create mode 100644 start.py create mode 100644 static/css/base.css create mode 100644 templates/base.html create mode 100644 templates/index.html create mode 100644 templates/singlefeed.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..820e8a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/.venv/ +/__pycache__/ +*.pyc +*.egg-info/ +.eggs/ +build/ +dist/ +pip-wheel-metadata/ + +test/* +*.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..2bc0eba --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Crunk columns + +crunk-columns is a work in progress website/portfolio maker. +part of the crunk suite of software. +Heavily inspired by [multifeeder](https://git.vvvvvvaria.org/varia/multifeeder) +This is a [PESOS](https://indieweb.org/PESOS) style website maker. +By filling in your desired columns in the columns.toml file you can make your own portfolio page in seconds +By adding your own css you can lose countless of hours tweaking everything. + + +## work in progress. + + +## POSSE is a much better approach, what are you even doing? +Yes, but I am lazy and I already exist on the internet and this is a way to bring +it all together. diff --git a/app.py b/app.py new file mode 100644 index 0000000..10ec038 --- /dev/null +++ b/app.py @@ -0,0 +1,14 @@ +import os +from flask import Flask +# from flask_sqlalchemy import SQLAlchemy +#db = SQLAlchemy() +#migrate = Migrate() + +def create_app(): + APP = Flask(__name__) + #APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data/crunk_data.db" + #APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True + # db.init_app(APP) + # migrate.init_app(APP, db, render_as_batch=True) + + return APP diff --git a/column.py b/column.py new file mode 100644 index 0000000..fe1e7e0 --- /dev/null +++ b/column.py @@ -0,0 +1,12 @@ +class Column: + def __init__(self, title, entries): + self.title = title + self.entries = entries + self.sort_order = None + self.limit = None + + def set_sort_order(self, sort_order): + self.sort_order = sort_order + + def set_limit(self, limit): + self.limit = limit diff --git a/columns.toml b/columns.toml new file mode 100644 index 0000000..27fd1e2 --- /dev/null +++ b/columns.toml @@ -0,0 +1,11 @@ +[[column]] +id = 1 +urls = ["https://varia.zone/logs/x-y/feed.rss.xml","https://varia.zone/logs/x-y-protocols/feed.rss.xml"] +title = "code" + +[[column]] +id = 2 +urls = ["https://post.lurk.org/@cmos4040.rss"] +sort_order = "chronological" +title = "circulations" +limit = 100 diff --git a/parse_rss_feeds.py b/parse_rss_feeds.py new file mode 100644 index 0000000..20bc71b --- /dev/null +++ b/parse_rss_feeds.py @@ -0,0 +1,22 @@ +from feedparser import parse +import random + +def _parse_single_rss_feed(url): + feed = parse(url) + entries = {} + for entrynumber, entry in enumerate(feed.entries): + if entry.has_key("title"): + entries[entry.title] = [] + entrylist = entries[entry.title] + else: + title = str(entrynumber) + entries[title] = [] + entrylist = entries[title] + entrylist.append(entry.description) + return entries + +def parse_rss_feeds(urls): + entries = {} + for url in urls: + entries.update(_parse_single_rss_feed(url)) + return entries diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5ae46f5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[tool.black] +line-length = 79 +target-version = ["py37","py38","py39"] + +exclude = ''' +/( + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist + # The following are specific to Black, you probably don't want those. + | blib2to3 + | tests/data + | profiling +)/ +''' diff --git a/quick_test.py b/quick_test.py new file mode 100644 index 0000000..1097dfa --- /dev/null +++ b/quick_test.py @@ -0,0 +1,20 @@ +import tomli +from column import Column +from parse_rss_feeds import parse_rss_feeds + + +with open("columns.toml", "rb") as f: + feeds_dict = tomli.load(f) + +feeds_file = feeds_dict["column"] +columns = [] +for feed_from_file in feeds_file: + entries = parse_rss_feeds(feed_from_file["urls"]) + title = feed_from_file["title"] + column = Column(title=title, entries=entries) + if "limit" in feed_from_file: + print(feed_from_file["limit"]) + columns.append(column) + +for column in columns: + print(column.title) diff --git a/start.py b/start.py new file mode 100644 index 0000000..4aa5682 --- /dev/null +++ b/start.py @@ -0,0 +1,44 @@ +from flask import ( + render_template, + redirect, +) +import tomli + +from parse_rss_feeds import parse_rss_feeds +from app import create_app +from column import Column + +APP = create_app() + + +@APP.route("/singlefeed") +def singlefeed(): + with open("columns.toml", "rb") as f: + feeds_dict = tomli.load(f) + feeds = feeds_dict["column"] + + feed = parse_rss_feeds(feeds[0]["urls"][0]) + return render_template("singlefeed.html", feed=feed) + + +@APP.route("/") +def index(): + with open("columns.toml", "rb") as f: + column_dict = tomli.load(f) + columns_file = column_dict["column"] + columns = [] + for column_from_file in columns_file: + entries = parse_rss_feeds(column_from_file["urls"]) + title = column_from_file["title"] + column = Column(title=title, entries=entries) + if "limit" in column_from_file: + column.set_limit(column_from_file["limit"]) + if "sort_order" in column_from_file: + column.set_sort_order(column_from_file["sort_order"]) + columns.append(column) + return render_template("index.html", columns=columns) + + +if __name__ == "__main__": + APP.debug = True + APP.run(port=5000) diff --git a/static/css/base.css b/static/css/base.css new file mode 100644 index 0000000..49beed3 --- /dev/null +++ b/static/css/base.css @@ -0,0 +1,34 @@ +body { + text-rendering: optimizelegibility; + -moz-text-size-adjust: none; +} +.crunkcolumns { + display: grid; + grid-auto-flow: column; + grid-gap: 10px; + grid-template-columns: repeat(auto-fill, 350px); +} + +.feed { + grid-template-columns: inherit; +} + +.feeditem { + display: flex; + width: 350px; + position: relative; + flex-direction: column; + box-sizing: border-box; + border: 1px solid black; + margin-top: 1px; + padding: 3px; +} + +.feeditem h2, p{ + margin-bottom: 3px; + margin-top: 3px; +} +img { + max-width: 100%; + max-height: 100%; +} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..8e5c2de --- /dev/null +++ b/templates/base.html @@ -0,0 +1,14 @@ + + + + + + Title + + + + + {% block main %} + {% endblock main %} + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..7f90565 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} +{% block main %} +
+{% for column in columns %} +
+

{{ column.title }}

+ {% for feedtitle, text in column.entries.items() %} +
+

{{ feedtitle }}

+ {{ text[0]|safe }} +
+ {% endfor%} +
+{% endfor%} +
+{% endblock %} diff --git a/templates/singlefeed.html b/templates/singlefeed.html new file mode 100644 index 0000000..99c8847 --- /dev/null +++ b/templates/singlefeed.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% block main %} + +{% for feedtitle, text in feed.items() %} +
+

{{ feedtitle }}

+ {{ text[0]|safe }} +
+{% endfor%} +{% endblock %}