Fix file syndication
This commit is contained in:
@@ -84,7 +84,7 @@ class FeedFinder:
|
|||||||
|
|
||||||
return entry.get("content")
|
return entry.get("content")
|
||||||
|
|
||||||
def run(self, rss_url: str, domain: str, output: dict):
|
def run(self, rss_url: str, domain: str, output: dict, data: dict):
|
||||||
feed = feedparser.parse(rss_url)
|
feed = feedparser.parse(rss_url)
|
||||||
|
|
||||||
if feed.status == 200:
|
if feed.status == 200:
|
||||||
@@ -93,7 +93,9 @@ class FeedFinder:
|
|||||||
|
|
||||||
for e in self.find_urls(self.get_label(feed.version, entry)):
|
for e in self.find_urls(self.get_label(feed.version, entry)):
|
||||||
if domain in e:
|
if domain in e:
|
||||||
|
temp = e
|
||||||
e = clean_slug(e)
|
e = clean_slug(e)
|
||||||
|
data[e] = temp
|
||||||
if output.get(e, False):
|
if output.get(e, False):
|
||||||
output[e].append(link.strip())
|
output[e].append(link.strip())
|
||||||
else:
|
else:
|
||||||
@@ -118,14 +120,16 @@ class IndieWebOrg:
|
|||||||
|
|
||||||
return entry.get("content")
|
return entry.get("content")
|
||||||
|
|
||||||
def run(self, rss_url: str, site: str, domain: str, output: dict):
|
def run(self, rss_url: str, site: str, domain: str, output: dict, data: dict):
|
||||||
feed = feedparser.parse(rss_url)
|
feed = feedparser.parse(rss_url)
|
||||||
|
|
||||||
if feed.status == 200:
|
if feed.status == 200:
|
||||||
for entry in feed.entries:
|
for entry in feed.entries:
|
||||||
for e in self.find_urls(self.get_label(feed.version, entry)):
|
for e in self.find_urls(self.get_label(feed.version, entry)):
|
||||||
if domain in e:
|
if domain in e:
|
||||||
|
temp = e
|
||||||
e = clean_slug(e)
|
e = clean_slug(e)
|
||||||
|
data[e] = temp
|
||||||
if output.get(e, False):
|
if output.get(e, False):
|
||||||
output[e].append(site)
|
output[e].append(site)
|
||||||
else:
|
else:
|
||||||
@@ -143,6 +147,7 @@ class WriterSyndication:
|
|||||||
domain: str,
|
domain: str,
|
||||||
):
|
):
|
||||||
self.output = {}
|
self.output = {}
|
||||||
|
self.data = {}
|
||||||
self.rss = rss
|
self.rss = rss
|
||||||
self.indiweb = indiweb
|
self.indiweb = indiweb
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
@@ -151,25 +156,26 @@ class WriterSyndication:
|
|||||||
def data_gathering(self):
|
def data_gathering(self):
|
||||||
ff = FeedFinder()
|
ff = FeedFinder()
|
||||||
for i in self.rss:
|
for i in self.rss:
|
||||||
ff.run(i, self.domain, self.output)
|
ff.run(i, self.domain, self.output, self.data)
|
||||||
ii = IndieWebOrg()
|
ii = IndieWebOrg()
|
||||||
for a, b in self.indiweb:
|
for a, b in self.indiweb:
|
||||||
ii.run(a, b, self.domain, output=self.output)
|
ii.run(a, b, self.domain, output=self.output, data=self.data)
|
||||||
|
|
||||||
hn = HackerNewsFinder(self.hacker_news_username, self.output)
|
hn = HackerNewsFinder(self.hacker_news_username, self.output)
|
||||||
hn.run()
|
hn.run()
|
||||||
|
print(self.data)
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
for key in self.output.keys():
|
for key in self.output.keys():
|
||||||
|
|
||||||
path_folder = os.path.join("data", "syndication")
|
path_folder = os.path.join("data", "syndication")
|
||||||
|
|
||||||
Path(path_folder).mkdir(parents=True, exist_ok=True)
|
Path(path_folder).mkdir(parents=True, exist_ok=True)
|
||||||
path_file = os.path.join(path_folder, key)
|
path_file = os.path.join(path_folder, key)
|
||||||
|
|
||||||
if os.path.exists(path_file + ".json"):
|
if os.path.exists(path_file + ".json"):
|
||||||
with open(path_file + ".json") as fp:
|
with open(path_file + ".json") as fp:
|
||||||
data = json.load(fp)
|
data = json.load(fp)
|
||||||
|
data["source"] = self.data.get(key, None)
|
||||||
if data.get("syndication", False):
|
if data.get("syndication", False):
|
||||||
data["syndication"] = sorted(
|
data["syndication"] = sorted(
|
||||||
set(data["syndication"] + self.output[key])
|
set(data["syndication"] + self.output[key])
|
||||||
|
|||||||
Reference in New Issue
Block a user