add location to posts, and update to work with new version of mf2util
This commit is contained in:
parent
e259d6d4a6
commit
61b28ef654
2 changed files with 32 additions and 9 deletions
|
@ -47,7 +47,10 @@ def flask_app():
|
||||||
from woodwind import create_app
|
from woodwind import create_app
|
||||||
_app = create_app()
|
_app = create_app()
|
||||||
with _app.app_context():
|
with _app.app_context():
|
||||||
yield _app
|
try:
|
||||||
|
yield _app
|
||||||
|
except:
|
||||||
|
_app.logger.exception('Unhandled exception')
|
||||||
|
|
||||||
|
|
||||||
def tick():
|
def tick():
|
||||||
|
@ -319,13 +322,13 @@ def process_xml_feed_for_new_entries(feed, content, backfill, now):
|
||||||
if not uid:
|
if not uid:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if 'updated_parsed' in p_entry:
|
if 'updated_parsed' in p_entry and p_entry.updated_parsed:
|
||||||
updated = datetime.datetime.fromtimestamp(
|
updated = datetime.datetime.fromtimestamp(
|
||||||
time.mktime(p_entry.updated_parsed))
|
time.mktime(p_entry.updated_parsed))
|
||||||
else:
|
else:
|
||||||
updated = None
|
updated = None
|
||||||
|
|
||||||
if 'published_parsed' in p_entry:
|
if 'published_parsed' in p_entry and p_entry.published_parsed:
|
||||||
published = datetime.datetime.fromtimestamp(
|
published = datetime.datetime.fromtimestamp(
|
||||||
time.mktime(p_entry.published_parsed))
|
time.mktime(p_entry.published_parsed))
|
||||||
else:
|
else:
|
||||||
|
@ -381,7 +384,13 @@ def process_xml_feed_for_new_entries(feed, content, backfill, now):
|
||||||
def process_html_feed_for_new_entries(feed, content, backfill, now):
|
def process_html_feed_for_new_entries(feed, content, backfill, now):
|
||||||
# strip noscript tags before parsing, since we definitely aren't
|
# strip noscript tags before parsing, since we definitely aren't
|
||||||
# going to preserve js
|
# going to preserve js
|
||||||
content = re.sub('</?noscript[^>]*>', '', content)
|
was_bytes = isinstance(content, bytes) # ugly hack to deal with unknown encodings
|
||||||
|
if was_bytes:
|
||||||
|
content = content.decode()
|
||||||
|
content = re.sub('</?noscript[^>]*>', '', content, flags=re.IGNORECASE)
|
||||||
|
if was_bytes:
|
||||||
|
content = content.encode()
|
||||||
|
|
||||||
|
|
||||||
parsed = mf2util.interpret_feed(
|
parsed = mf2util.interpret_feed(
|
||||||
mf2py.parse(url=feed.feed, doc=content), feed.feed)
|
mf2py.parse(url=feed.feed, doc=content), feed.feed)
|
||||||
|
@ -432,7 +441,14 @@ def hentry_to_entry(hentry, feed, backfill, now):
|
||||||
or (feed and fallback_photo(feed.origin)),
|
or (feed and fallback_photo(feed.origin)),
|
||||||
author_url=hentry.get('author', {}).get('url'))
|
author_url=hentry.get('author', {}).get('url'))
|
||||||
|
|
||||||
for prop in 'in-reply-to', 'like-of', 'repost-of', 'syndication':
|
# complex properties, convert from list of complex objects to a list of URLs
|
||||||
|
for prop in ('in-reply-to', 'like-of', 'repost-of'):
|
||||||
|
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)
|
value = hentry.get(prop)
|
||||||
if value:
|
if value:
|
||||||
entry.set_property(prop, value)
|
entry.set_property(prop, value)
|
||||||
|
@ -454,7 +470,7 @@ def fetch_reply_context(entry_id, in_reply_to, now):
|
||||||
parsed = mf2util.interpret(
|
parsed = mf2util.interpret(
|
||||||
mf2py.parse(url=proxy_url(in_reply_to)), in_reply_to)
|
mf2py.parse(url=proxy_url(in_reply_to)), in_reply_to)
|
||||||
if parsed:
|
if parsed:
|
||||||
context = hentry_to_entry(parsed, in_reply_to, False, now)
|
context = hentry_to_entry(parsed, None, False, now)
|
||||||
|
|
||||||
if context:
|
if context:
|
||||||
entry.reply_context.append(context)
|
entry.reply_context.append(context)
|
||||||
|
|
|
@ -53,6 +53,13 @@
|
||||||
|
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
|
{% set location = entry.get_property('location') %}
|
||||||
|
{% if location and 'name' in location %}
|
||||||
|
<div>
|
||||||
|
<code>@</code> {% if 'url' in location %}<a href="{{ location.url }}">{{ location.name }}</a>{% else %}{{ location.name }}{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<a class="permalink" href="{{ entry.permalink }}">
|
<a class="permalink" href="{{ entry.permalink }}">
|
||||||
<time datetime="{{ entry.published | isoformat }}">
|
<time datetime="{{ entry.published | isoformat }}">
|
||||||
{{ entry.published | relative_time }}
|
{{ entry.published | relative_time }}
|
||||||
|
@ -62,9 +69,9 @@
|
||||||
<i class="fa fa-external-link"></i>
|
<i class="fa fa-external-link"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{% if entry._syndicated_copies %}
|
{% if entry.get_property('syndication') %}
|
||||||
(also on{% for copy in entry._syndicated_copies %} <a href="{{ copy.permalink }}">{{ copy.permalink | domain_for_url }}</a>{% endfor %})
|
| {% for synd in entry.get_property('syndication') %} <a href="{{ synd }}">{{ synd | domain_for_url}}</a>{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="reply-area">
|
<div class="reply-area">
|
||||||
{% include '_reply.jinja2' with context %}
|
{% include '_reply.jinja2' with context %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue