Compare commits
6 Commits
0ecc0ecd3a
...
main
Author | SHA1 | Date | |
---|---|---|---|
028bc1df84 | |||
82a017f624 | |||
9d9f8f6d72 | |||
e01aa9a607 | |||
3055ee37df | |||
a4f749ebd7 |
107
konfluks/feed.py
107
konfluks/feed.py
@ -155,8 +155,11 @@ def parse_enclosures(post_dir, entry):
|
|||||||
if "type" in e:
|
if "type" in e:
|
||||||
print("found enclosed media", e.type)
|
print("found enclosed media", e.type)
|
||||||
if "image/" in e.type:
|
if "image/" in e.type:
|
||||||
|
if not os.path.exists(post_dir): #this might be redundant with create_post
|
||||||
|
os.makedirs(post_dir)
|
||||||
featured_image = grab_media(post_dir, e.href)
|
featured_image = grab_media(post_dir, e.href)
|
||||||
entry["featured_image"] = featured_image
|
media_item = urlparse(e.href).path.split('/')[-1]
|
||||||
|
entry["featured_image"] = media_item
|
||||||
else:
|
else:
|
||||||
print("FIXME:ignoring enclosed", e.type)
|
print("FIXME:ignoring enclosed", e.type)
|
||||||
return entry
|
return entry
|
||||||
@ -373,62 +376,66 @@ def main():
|
|||||||
|
|
||||||
data = grab_feed(feed_url)
|
data = grab_feed(feed_url)
|
||||||
|
|
||||||
if data:
|
if data: #whenever we get a 200
|
||||||
|
if data.feed: #only if it is an actual feed
|
||||||
|
opds_feed = False
|
||||||
|
if 'links' in data.feed:
|
||||||
|
for i in data.feed['links']:
|
||||||
|
if i['rel'] == 'self':
|
||||||
|
if 'opds' in i['type']:
|
||||||
|
opds_feed = True
|
||||||
|
print("OPDS type feed!")
|
||||||
|
|
||||||
opds_feed = False
|
for entry in data.entries:
|
||||||
for i in data.feed['links']:
|
# if 'tags' in entry:
|
||||||
if i['rel'] == 'self':
|
# for tag in entry.tags:
|
||||||
if 'opds' in i['type']:
|
# for x in ['lumbung.space', 'D15', 'lumbung']:
|
||||||
opds_feed = True
|
# if x in tag['term']:
|
||||||
print("OPDS type feed!")
|
# print(entry.title)
|
||||||
|
entry["feed_name"] = feed_name
|
||||||
|
|
||||||
|
post_name = slugify(entry.title)
|
||||||
|
|
||||||
for entry in data.entries:
|
# pixelfed returns the whole post text as the post name. max
|
||||||
# if 'tags' in entry:
|
# filename length is 255 on many systems. here we're shortening
|
||||||
# for tag in entry.tags:
|
# the name and adding a hash to it to avoid a conflict in a
|
||||||
# for x in ['lumbung.space', 'D15', 'lumbung']:
|
# situation where 2 posts start with exactly the same text.
|
||||||
# if x in tag['term']:
|
if len(post_name) > 150:
|
||||||
# print(entry.title)
|
post_hash = md5(bytes(post_name, "utf-8"))
|
||||||
entry["feed_name"] = feed_name
|
post_name = post_name[:150] + "-" + post_hash.hexdigest()
|
||||||
|
|
||||||
post_name = slugify(entry.title)
|
|
||||||
|
|
||||||
# pixelfed returns the whole post text as the post name. max
|
|
||||||
# filename length is 255 on many systems. here we're shortening
|
|
||||||
# the name and adding a hash to it to avoid a conflict in a
|
|
||||||
# situation where 2 posts start with exactly the same text.
|
|
||||||
if len(post_name) > 150:
|
|
||||||
post_hash = md5(bytes(post_name, "utf-8"))
|
|
||||||
post_name = post_name[:150] + "-" + post_hash.hexdigest()
|
|
||||||
|
|
||||||
if opds_feed:
|
|
||||||
entry['opds'] = True
|
|
||||||
#format: Beyond-Debiasing-Report_Online-75535a4886e3
|
|
||||||
post_name = slugify(entry['title'])+'-'+entry['id'].split('-')[-1]
|
|
||||||
|
|
||||||
post_dir = os.path.join(output_dir, feed_name, post_name)
|
|
||||||
|
|
||||||
if post_name not in existing_posts:
|
|
||||||
# if there is a blog entry we dont already have, make it
|
|
||||||
if opds_feed:
|
if opds_feed:
|
||||||
create_opds_post(post_dir, entry)
|
entry['opds'] = True
|
||||||
else:
|
#format: Beyond-Debiasing-Report_Online-75535a4886e3
|
||||||
create_post(post_dir, entry)
|
post_name = slugify(entry['title'])+'-'+entry['id'].split('-')[-1]
|
||||||
|
|
||||||
elif post_name in existing_posts:
|
post_dir = os.path.join(output_dir, feed_name, post_name)
|
||||||
# if we already have it, update it
|
|
||||||
if opds_feed:
|
|
||||||
create_opds_post(post_dir, entry)
|
|
||||||
else:
|
|
||||||
create_post(post_dir, entry)
|
|
||||||
existing_posts.remove(
|
|
||||||
post_name
|
|
||||||
) # create list of posts which have not been returned by the feed
|
|
||||||
|
|
||||||
for post in existing_posts:
|
if post_name not in existing_posts:
|
||||||
# remove blog posts no longer returned by the RSS feed
|
# if there is a blog entry we dont already have, make it
|
||||||
print("deleted", post)
|
if opds_feed:
|
||||||
shutil.rmtree(os.path.join(feed_dir, slugify(post)))
|
create_opds_post(post_dir, entry)
|
||||||
|
else:
|
||||||
|
create_post(post_dir, entry)
|
||||||
|
|
||||||
|
elif post_name in existing_posts:
|
||||||
|
# if we already have it, update it
|
||||||
|
if opds_feed:
|
||||||
|
create_opds_post(post_dir, entry)
|
||||||
|
else:
|
||||||
|
create_post(post_dir, entry)
|
||||||
|
existing_posts.remove(
|
||||||
|
post_name
|
||||||
|
) # create list of posts which have not been returned by the feed
|
||||||
|
|
||||||
|
|
||||||
|
for post in existing_posts:
|
||||||
|
# remove blog posts no longer returned by the RSS feed
|
||||||
|
post_dir = os.path.join(output_dir, feed_name, post)
|
||||||
|
shutil.rmtree(post_dir)
|
||||||
|
print("deleted", post_dir)
|
||||||
|
else:
|
||||||
|
print(feed_url, "is not or no longer a feed!")
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
title: "{{ event.name }}"
|
title: "{{ event.name }}"
|
||||||
date: "{{ event.begin }}" #2021-06-10T10:46:33+02:00
|
date: "{{ event.begin }}" #2021-06-10T10:46:33+02:00
|
||||||
draft: false
|
draft: false
|
||||||
categories: "calendar"
|
source: "lumbung calendar"
|
||||||
event_begin: "{{ event.begin }}"
|
event_begin: "{{ event.begin }}"
|
||||||
event_end: "{{ event.end }}"
|
event_end: "{{ event.end }}"
|
||||||
duration: "{{ event.duration }}"
|
duration: "{{ event.duration }}"
|
||||||
|
@ -3,11 +3,11 @@ title: "{{ frontmatter.title }}"
|
|||||||
date: "{{ frontmatter.date }}" #2021-06-10T10:46:33+02:00
|
date: "{{ frontmatter.date }}" #2021-06-10T10:46:33+02:00
|
||||||
draft: false
|
draft: false
|
||||||
summary: "{{ frontmatter.summary }}"
|
summary: "{{ frontmatter.summary }}"
|
||||||
authors: {% if frontmatter.author %} ["{{ frontmatter.author }}"] {% endif %}
|
contributors: {% if frontmatter.author %} ["{{ frontmatter.author }}"] {% endif %}
|
||||||
original_link: "{{ frontmatter.original_link }}"
|
original_link: "{{ frontmatter.original_link }}"
|
||||||
feed_name: "{{ frontmatter.feed_name}}"
|
feed_name: "{{ frontmatter.feed_name}}"
|
||||||
categories: ["{{ frontmatter.card_type }}", "{{ frontmatter.feed_name}}"]
|
card_type: "{{ frontmatter.card_type }}"
|
||||||
contributors: ["{{ frontmatter.feed_name}}"]
|
sources: ["{{ frontmatter.feed_name}}"]
|
||||||
tags: {{ frontmatter.tags }}
|
tags: {{ frontmatter.tags }}
|
||||||
{% if frontmatter.featured_image %}featured_image: "{{frontmatter.featured_image}}"{% endif %}
|
{% if frontmatter.featured_image %}featured_image: "{{frontmatter.featured_image}}"{% endif %}
|
||||||
---
|
---
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
---
|
---
|
||||||
date: {{ post_metadata.created_at }} #2021-06-10T10:46:33+02:00
|
date: {{ post_metadata.created_at }} #2021-06-10T10:46:33+02:00
|
||||||
draft: false
|
draft: false
|
||||||
authors: ["{{ post_metadata.account.display_name }}"]
|
contributors: ["{{ post_metadata.account.display_name }}"]
|
||||||
contributors: ["{{ post_metadata.account.acct}}"]
|
|
||||||
avatar: {{ post_metadata.account.avatar }}
|
avatar: {{ post_metadata.account.avatar }}
|
||||||
categories: ["shouts"]
|
|
||||||
title: {{ post_metadata.account.display_name }}
|
title: {{ post_metadata.account.display_name }}
|
||||||
tags: [{% for i in post_metadata.tags %} "{{ i.name }}", {% endfor %}]
|
tags: [{% for i in post_metadata.tags %} "{{ i.name }}", {% endfor %}]
|
||||||
images: [{% for i in post_metadata.media_attachments %}{% if i.type == "image" %}"{{ i.url | localize_media_url }}", {%endif%}{% endfor %}]
|
images: [{% for i in post_metadata.media_attachments %}{% if i.type == "image" %}"{{ i.url | localize_media_url }}", {%endif%}{% endfor %}]
|
||||||
|
@ -3,10 +3,10 @@ title: "{{ frontmatter.title }}"
|
|||||||
date: "{{ frontmatter.date }}" #2021-06-10T10:46:33+02:00
|
date: "{{ frontmatter.date }}" #2021-06-10T10:46:33+02:00
|
||||||
draft: false
|
draft: false
|
||||||
summary: "{{ frontmatter.summary }}"
|
summary: "{{ frontmatter.summary }}"
|
||||||
authors: {% if frontmatter.author %} ["{{ frontmatter.author }}"] {% endif %}
|
contributors: {% if frontmatter.author %} ["{{ frontmatter.author }}"] {% endif %}
|
||||||
original_link: "{{ frontmatter.original_link }}"
|
original_link: "{{ frontmatter.original_link }}"
|
||||||
feed_name: "{{ frontmatter.feed_name}}"
|
feed_name: "{{ frontmatter.feed_name}}"
|
||||||
categories: ["timeline", "{{ frontmatter.feed_name}}"]
|
sources: ["timeline", "{{ frontmatter.feed_name}}"]
|
||||||
timelines: {{ frontmatter.timelines }}
|
timelines: {{ frontmatter.timelines }}
|
||||||
hidden: true
|
hidden: true
|
||||||
---
|
---
|
||||||
|
@ -9,7 +9,7 @@ channel_url: "{{ v.channel.url }}"
|
|||||||
contributors: ["{{ v.account.display_name }}"]
|
contributors: ["{{ v.account.display_name }}"]
|
||||||
preview_image: "{{ preview_image }}"
|
preview_image: "{{ preview_image }}"
|
||||||
images: ["./{{ preview_image }}"]
|
images: ["./{{ preview_image }}"]
|
||||||
categories: ["tv","{{ v.channel.display_name }}"]
|
sources: ["{{ v.channel.display_name }}"]
|
||||||
is_live: {{ v.is_live }}
|
is_live: {{ v.is_live }}
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user