Browse Source

big commit fixing parsed dates

main
crunk 1 year ago
parent
commit
938f4fd364
  1. 2
      README.md
  2. 9
      app.py
  3. 9
      column.py
  4. 14
      columns.toml
  5. 2
      parse_rss_feeds.py
  6. 5
      start.py
  7. 8
      static/css/base.css
  8. 1
      static/css/template.css
  9. 1
      templates/base.html

2
README.md

@ -9,7 +9,7 @@ This is a [PESOS](https://indieweb.org/PESOS) style website maker.
## work in progress. ## work in progress.
* download and parse rss only on startup not on every index.html download * download and parse rss only on startup not on every index.html download
* <s>make sort_order types</s> * <s>make sort_order types</s> done
* sort_order options are: default(same order as rss), reverse, random, chronological, reverse-chronological. * sort_order options are: default(same order as rss), reverse, random, chronological, reverse-chronological.
* <s>make limits to amount of entries.</s> done * <s>make limits to amount of entries.</s> done
* make category filter. * make category filter.

9
app.py

@ -1,6 +1,6 @@
import os import os
from flask import Flask from flask import Flask
import flask_apscheduler
# from flask_sqlalchemy import SQLAlchemy # from flask_sqlalchemy import SQLAlchemy
# db = SQLAlchemy() # db = SQLAlchemy()
# migrate = Migrate() # migrate = Migrate()
@ -8,9 +8,16 @@ from flask import Flask
def create_app(): def create_app():
APP = Flask(__name__) APP = Flask(__name__)
scheduler = flask_apscheduler.APScheduler()
scheduler.api_enabled = False
scheduler.init_app(APP)
scheduler.start()
# APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data/crunk_data.db" # APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data/crunk_data.db"
# APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True # APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
# db.init_app(APP) # db.init_app(APP)
# migrate.init_app(APP, db, render_as_batch=True) # migrate.init_app(APP, db, render_as_batch=True)
@scheduler.task("interval", id="update", minutes=10)
def update():
print("Updating the RSS feeds!")
return APP return APP

9
column.py

@ -1,5 +1,6 @@
import random import random
from datetime import datetime from datetime import datetime
from time import mktime
from parse_rss_feeds import parse_rss_feeds from parse_rss_feeds import parse_rss_feeds
@ -29,17 +30,13 @@ class Column:
return return
if self.sort_order.lower() == "chronological": if self.sort_order.lower() == "chronological":
entrylist.sort( entrylist.sort(
key=lambda x: datetime.strptime( key=lambda x: datetime.fromtimestamp(mktime(x[1][1]))
x[1][1], "%a, %d %b %Y %H:%M:%S %z"
)
) )
self.entries = dict(entrylist) self.entries = dict(entrylist)
return return
if self.sort_order.lower() == "reverse-chronological": if self.sort_order.lower() == "reverse-chronological":
entrylist.sort( entrylist.sort(
key=lambda x: datetime.strptime( key=lambda x: datetime.fromtimestamp(mktime(x[1][1]))
x[1][1], "%a, %d %b %Y %H:%M:%S %z"
)
) )
entrylist.reverse() entrylist.reverse()
self.entries = dict(entrylist) self.entries = dict(entrylist)

14
columns.toml

@ -1,10 +1,20 @@
[[column]] [[column]]
urls = ["https://varia.zone/logs/x-y/feed.rss.xml","https://varia.zone/logs/x-y-protocols/feed.rss.xml"] urls = ["https://varia.zone/logs/x-y/feed.rss.xml","https://varia.zone/logs/x-y-protocols/feed.rss.xml"]
title = "code" title = "code"
limit = 40 limit = 5
sort_order = "random" sort_order = "random"
[[column]] [[column]]
urls = ["https://post.lurk.org/@cmos4040.rss","https://post.lurk.org/tags/radio.rss"] urls = ["https://post.lurk.org/@cmos4040.rss"]
title = "circulations" title = "circulations"
sort_order = "reverse"
[[column]]
urls = ["https://post.lurk.org/tags/radio.rss"]
title = "radio"
sort_order = "reverse-chronological" sort_order = "reverse-chronological"
[[column]]
urls = ["https://post.lurk.org/tags/forth.rss"]
title = "forth"
sort_order = "chronological"

2
parse_rss_feeds.py

@ -14,7 +14,7 @@ def _parse_single_rss_feed(url, entries):
entries[title] = [] entries[title] = []
entrylist = entries[title] entrylist = entries[title]
entrylist.append(entry.description) entrylist.append(entry.description)
entrylist.append(entry.published) entrylist.append(entry.published_parsed)
return entries return entries

5
start.py

@ -1,7 +1,5 @@
from flask import (
render_template,
)
import tomli import tomli
from flask import render_template
from app import create_app from app import create_app
from column import Column from column import Column
@ -13,6 +11,7 @@ APP = create_app()
def index(): def index():
with open("columns.toml", "rb") as f: with open("columns.toml", "rb") as f:
column_dict = tomli.load(f) column_dict = tomli.load(f)
columns_file = column_dict["column"] columns_file = column_dict["column"]
columns = [] columns = []
for column_from_file in columns_file: for column_from_file in columns_file:

8
static/css/base.css

@ -1,12 +1,14 @@
body { body {
text-rendering: optimizelegibility; text-rendering: optimizelegibility;
-moz-text-size-adjust: none; -moz-text-size-adjust: none;
margin: 0px;
} }
.crunkcolumns { .crunkcolumns {
display: grid; display: grid;
grid-auto-flow: column; grid-auto-flow: column;
grid-gap: 10px; grid-gap: 1px;
grid-template-columns: repeat(auto-fill, 350px); grid-template-columns: repeat(auto-fill, 336px);
margin-left: 6px;
} }
.feed { .feed {
@ -15,7 +17,7 @@ body {
.feeditem { .feeditem {
display: flex; display: flex;
width: 350px; width: 336px;
position: relative; position: relative;
flex-direction: column; flex-direction: column;
box-sizing: border-box; box-sizing: border-box;

1
static/css/template.css

@ -0,0 +1 @@
/* copy and adjust from base.css */

1
templates/base.html

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title> <title>Title</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/base.css')}}"> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/base.css')}}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/template.css')}}">
<link rel="shortcut icon" href="{{ url_for('static', filename='icons/favicon.ico') }}"> <link rel="shortcut icon" href="{{ url_for('static', filename='icons/favicon.ico') }}">
</head> </head>
<body> <body>

Loading…
Cancel
Save