From 5cdb9bf44ce7349eafb8bf29101ac41512629173 Mon Sep 17 00:00:00 2001 From: BlenderDumbass Date: Wed, 27 Nov 2024 17:02:54 +0200 Subject: [PATCH] RSS implementation --- modules/Help.py | 2 ++ modules/Render.py | 80 ++++++++++++++++++++++++++++++++++++++++++++--- modules/Run.py | 3 ++ modules/Set.py | 20 ++++++++++++ 4 files changed, 101 insertions(+), 4 deletions(-) diff --git a/modules/Help.py b/modules/Help.py index 49a0dfb..f85ba73 100644 --- a/modules/Help.py +++ b/modules/Help.py @@ -29,6 +29,8 @@ def Set(): print() print(clr["tdyl"]+"--title"+clr["norm"]+" - Set title of the website.") print(clr["tdyl"]+"--tagline"+clr["norm"]+" - Set tagline of the website.") + print(clr["tdyl"]+"--domain"+clr["norm"]+" - Let the server know the clearnet domain.") + print(clr["tdyl"]+"--tor"+clr["norm"]+" - Let the server know the tor domain.") print(clr["tdyl"]+"--port"+clr["norm"]+" - Set port where to run the website.") print(clr["tdyl"]+"--css"+clr["norm"]+" - Set a CSS file.") print(clr["tdyl"]+"--css_edit"+clr["norm"]+" - edit a CSS file.") diff --git a/modules/Render.py b/modules/Render.py index 6c05c4e..16d1970 100644 --- a/modules/Render.py +++ b/modules/Render.py @@ -19,6 +19,8 @@ def guess_type(path): return "application/json" if "/css" in path or ".css" in path: return "text/css" + if "/rss" in path or ".rss" in path: + return "application/rss+xml" if "/icon" in path or path.endswith(".png"): return "image/png" if path.endswith("jpg"): @@ -62,8 +64,8 @@ def head(title="", description="", image="", config={}, author=""): - - + + """ @@ -425,7 +427,7 @@ def ArticlePage(server, url): url = url.replace(".md", "") config = Set.Load() - tab, article = url.split("/") + tab, article, *rest = url.split("/") Tabs = tabs() Articles = articles(tab) f = Set.Folder() @@ -483,13 +485,24 @@ def ArticlePage(server, url): if recording: html = html + '' - + html = html + '
' html = html + markdown.convert(f+"/tabs/"+tab+"/"+article+"/text.md") html = html + '
' + # RSS + + html = html + """ +
+
+ + """+ Button("Subscribe RSS", "/rss", "rss") +""" + +
+
+ """ # Comments @@ -1867,3 +1880,62 @@ def ReadNotification(server): except Exception as e: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Unable to read notification!", e) + + +def RSS(server): + + # Rendering rss feed. + + Articles = allArticles() + config = Set.Load() + + favicon = config.get("favicon", "") + if favicon.startswith("/"): + favicon = "https://"+config.get("domain", "example.com")+favicon + + rss = """ + + + + + + """+config.get("title", "My Website")+""" + https://"""+config.get("domain", "example.com")+""" + """+config.get("tagline", "")+""" + + + """+favicon+""" + """+config.get("title", "My Website")+""" + https://"""+config.get("domain", "example.com")+""" + + + """ + + for n, article in enumerate(Articles): + + if n > 10: + break + + pubDate = Articles[article].get("timestamp", 0) + pubDate = datetime.fromtimestamp(pubDate) + pubDate = pubDate.strftime('%a, %d %b %H:%M:%S')+" -0000" + + rss = rss + """ + + + """+Articles[article].get("title", article)+""" + https://"""+config.get("domain", "example.com")+Articles[article].get("url", "")+""" + + """+pubDate+""" + + + """ + + + + rss = rss + """ + + + """ + + send(server, rss, 200) diff --git a/modules/Run.py b/modules/Run.py index 9f0264d..77b9785 100644 --- a/modules/Run.py +++ b/modules/Run.py @@ -132,6 +132,9 @@ class handler(BaseHTTPRequestHandler): url = self.path[6:] if "?" in url: url = url[:url.find("?")] Render.Graph(self, url) + + elif self.path == "/rss": + Render.RSS(self) elif self.path.startswith("/pictures/"): diff --git a/modules/Set.py b/modules/Set.py index 315eb6e..1b08db2 100644 --- a/modules/Set.py +++ b/modules/Set.py @@ -76,6 +76,17 @@ def Set(): print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Tagline Wasn't Specified!") print('Use: $ python3 run.py --set --title "Ultimate Club for Ultimate Hackers"') + if "--domain" in sys.argv: + try: + domain = sys.argv[ sys.argv.index("--domain") + 1] + if "--" in domain: 1/0 # Failing this for the error message. + Domain(domain) + + except Exception as e: + print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Didn't specify the domain.", e) + print('Use: $ python3 run.py --set --domain blenderdumbass.org') + + if "--port" in sys.argv: try: port = int(sys.argv[ sys.argv.index("--port") + 1]) @@ -147,6 +158,15 @@ def Tagline(tagline): print(clr["bold"]+clr["tbyl"]+tagline+clr["norm"]+" is set as tagline.") +def Domain(domain): + + data = Load() + data["domain"] = domain + + Save(data) + + print(clr["bold"]+clr["tbyl"]+domain+clr["norm"]+" is set as domain.") + def Port(port): data = Load()