upgrade mf2py and mf2util
convert TEXT columns to JSONB
This commit is contained in:
parent
46e98853d9
commit
aa7f8ace80
4 changed files with 11 additions and 32 deletions
|
@ -16,8 +16,8 @@ bleach==1.4.1
|
|||
feedparser>=5.2.0
|
||||
html5lib==0.99999
|
||||
|
||||
mf2py==0.2.6
|
||||
mf2util==0.1.9
|
||||
mf2py==0.2.7
|
||||
mf2util==0.2.3
|
||||
psycopg2==2.6
|
||||
|
||||
pyOpenSSL==0.15.1
|
||||
|
|
|
@ -2,7 +2,6 @@ from flask.ext.login import LoginManager
|
|||
from flask.ext.micropub import MicropubClient
|
||||
from flask.ext.sqlalchemy import SQLAlchemy
|
||||
from flask_debugtoolbar import DebugToolbarExtension
|
||||
from flask.ext.migrate import Migrate
|
||||
|
||||
|
||||
db = SQLAlchemy()
|
||||
|
@ -10,7 +9,6 @@ micropub = MicropubClient(client_id='https://reader.kylewm.com')
|
|||
login_mgr = LoginManager()
|
||||
login_mgr.login_view = 'views.index'
|
||||
toolbar = DebugToolbarExtension()
|
||||
migrate = Migrate()
|
||||
|
||||
|
||||
def init_app(app):
|
||||
|
@ -18,4 +16,3 @@ def init_app(app):
|
|||
micropub.init_app(app)
|
||||
login_mgr.init_app(app)
|
||||
toolbar.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
|
|
|
@ -1,26 +1,9 @@
|
|||
from .extensions import db
|
||||
import json
|
||||
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
import uuid
|
||||
|
||||
|
||||
class JsonType(db.TypeDecorator):
|
||||
"""Represents an immutable structure as a json-encoded string.
|
||||
http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#marshal-json-strings
|
||||
"""
|
||||
impl = db.Text
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
if value is not None:
|
||||
value = json.dumps(value)
|
||||
|
||||
return value
|
||||
|
||||
def process_result_value(self, value, dialect):
|
||||
if value is not None:
|
||||
value = json.loads(value)
|
||||
return value
|
||||
|
||||
|
||||
entry_to_reply_context = db.Table(
|
||||
'entry_to_reply_context', db.Model.metadata,
|
||||
db.Column('entry_id', db.Integer, db.ForeignKey('entry.id'), index=True),
|
||||
|
@ -30,10 +13,10 @@ entry_to_reply_context = db.Table(
|
|||
class User(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
url = db.Column(db.String(256))
|
||||
#domain = db.Column(db.String(256))
|
||||
# domain = db.Column(db.String(256))
|
||||
micropub_endpoint = db.Column(db.String(512))
|
||||
access_token = db.Column(db.String(512))
|
||||
settings = db.Column(JsonType)
|
||||
settings = db.Column(JSONB)
|
||||
|
||||
# Flask-Login integration
|
||||
def is_authenticated(self):
|
||||
|
@ -134,7 +117,7 @@ class Entry(db.Model):
|
|||
content = db.Column(db.Text)
|
||||
content_cleaned = db.Column(db.Text)
|
||||
# other properties
|
||||
properties = db.Column(JsonType)
|
||||
properties = db.Column(JSONB)
|
||||
reply_context = db.relationship(
|
||||
'Entry', secondary='entry_to_reply_context',
|
||||
primaryjoin=id == entry_to_reply_context.c.entry_id,
|
||||
|
@ -142,7 +125,6 @@ class Entry(db.Model):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.subscription = None
|
||||
self._syndicated_copies = []
|
||||
|
||||
|
@ -152,8 +134,8 @@ class Entry(db.Model):
|
|||
return self.properties.get(key, default)
|
||||
|
||||
def set_property(self, key, value):
|
||||
self.properties = ({} if self.properties is None
|
||||
else dict(self.properties))
|
||||
if self.properties is None:
|
||||
self.properties = {}
|
||||
self.properties[key] = value
|
||||
|
||||
def __repr__(self):
|
||||
|
|
|
@ -391,7 +391,6 @@ def process_html_feed_for_new_entries(feed, content, backfill, now):
|
|||
if was_bytes:
|
||||
content = content.encode()
|
||||
|
||||
|
||||
parsed = mf2util.interpret_feed(
|
||||
mf2py.parse(url=feed.feed, doc=content), feed.feed)
|
||||
hfeed = parsed.get('entries', [])
|
||||
|
@ -446,13 +445,14 @@ def hentry_to_entry(hentry, feed, backfill, now):
|
|||
values = hentry.get(prop)
|
||||
if values:
|
||||
entry.set_property(prop, [value['url'] for value in values if 'url' in value])
|
||||
|
||||
|
||||
# simple properties, just transfer them over wholesale
|
||||
for prop in ('syndication', 'location'):
|
||||
value = hentry.get(prop)
|
||||
if value:
|
||||
entry.set_property(prop, value)
|
||||
|
||||
current_app.logger.debug('entry properties %s', entry.properties)
|
||||
return entry
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue