Fix synd
This commit is contained in:
@@ -2,10 +2,16 @@ import feedparser
|
||||
from pathlib import Path
|
||||
import os
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
domain = "https://fundor333.com"
|
||||
rss_url_mastodon = "https://mastodon.social/@fundor333.rss"
|
||||
|
||||
|
||||
domain = 'https://fundor333.com'
|
||||
rss_url_mastodon = 'https://mastodon.social/@fundor333.rss'
|
||||
def clean_slug(slug: str):
|
||||
return hashlib.md5(
|
||||
(slug.split("?")[0]).encode("utf-8"), usedforsecurity=False
|
||||
).hexdigest()
|
||||
|
||||
|
||||
class MastodonFinder:
|
||||
@@ -21,9 +27,10 @@ class MastodonFinder:
|
||||
feed = feedparser.parse(rss_url)
|
||||
if feed.status == 200:
|
||||
for entry in feed.entries:
|
||||
link = entry.get('link')
|
||||
for e in self.find_urls(entry.get('description')):
|
||||
link = entry.get("link")
|
||||
for e in self.find_urls(entry.get("description")):
|
||||
if domain in e:
|
||||
e = clean_slug(e)
|
||||
if output.get(e, False):
|
||||
output[e].append(link)
|
||||
else:
|
||||
@@ -44,18 +51,13 @@ class WriterSyndication:
|
||||
|
||||
def write(self):
|
||||
for key in self.output.keys():
|
||||
original_path = key.split(self.domain)[1]
|
||||
path_list = original_path.split('/')
|
||||
|
||||
path_list = [x for x in path_list if x.strip()]
|
||||
filename = path_list.pop()
|
||||
|
||||
path_folder = os.path.join('data', "syndication", *path_list)
|
||||
path_folder = os.path.join("data", "syndication")
|
||||
|
||||
Path(path_folder).mkdir(parents=True, exist_ok=True)
|
||||
path_file = os.path.join(path_folder, filename + ".json")
|
||||
path_file = os.path.join(path_folder, key)
|
||||
|
||||
with open(path_file, 'w') as fp:
|
||||
with open(path_file + ".json", "w") as fp:
|
||||
json.dump({"syndication": self.output[key]}, fp)
|
||||
|
||||
def run(self):
|
||||
|
||||
@@ -7,7 +7,7 @@ from pathlib import Path
|
||||
|
||||
http_domain = "https://fundor333.com"
|
||||
domain = "fundor333.com"
|
||||
token = os.getenv('WEBMENTIONS_TOKEN')
|
||||
token = os.getenv("WEBMENTIONS_TOKEN")
|
||||
since_days = 30
|
||||
|
||||
|
||||
@@ -21,16 +21,14 @@ def clean_slug(slug: str):
|
||||
|
||||
|
||||
r = requests.get(url)
|
||||
|
||||
data = r.json()
|
||||
|
||||
output = {}
|
||||
|
||||
for webmention in data["children"]:
|
||||
|
||||
with open('temp.json', 'w') as fp:
|
||||
with open("temp.json", "w") as fp:
|
||||
|
||||
label = clean_slug(webmention['wm-target'])
|
||||
label = clean_slug(webmention["wm-target"])
|
||||
|
||||
if output.get(label, False):
|
||||
output[label].append(webmention)
|
||||
@@ -39,16 +37,16 @@ for webmention in data["children"]:
|
||||
|
||||
for key in output.keys():
|
||||
original_path = key
|
||||
path_list = original_path.split('/')
|
||||
path_list = original_path.split("/")
|
||||
|
||||
path_list = [x for x in path_list if x.strip()]
|
||||
if path_list != []:
|
||||
filename = path_list.pop()
|
||||
|
||||
path_folder = os.path.join('data', "webmentions", *path_list)
|
||||
path_folder = os.path.join("data", "webmentions", *path_list)
|
||||
|
||||
Path(path_folder).mkdir(parents=True, exist_ok=True)
|
||||
path_file = os.path.join(path_folder, filename + ".json")
|
||||
|
||||
with open(path_file, 'w') as fp:
|
||||
with open(path_file, "w") as fp:
|
||||
json.dump(output[key], fp)
|
||||
|
||||
Reference in New Issue
Block a user