diff --git a/modules/Common.py b/modules/Common.py
index 15cfee8..bbee73f 100644
--- a/modules/Common.py
+++ b/modules/Common.py
@@ -62,6 +62,9 @@ def Simplify(text):
return ntext
+def Safe(text):
+ return text.replace("<", "<").replace(">", ">")
+
def RandString(n=50):
# this will make a random string
s = ""
diff --git a/modules/Render.py b/modules/Render.py
index 947a32c..b45863b 100644
--- a/modules/Render.py
+++ b/modules/Render.py
@@ -3,6 +3,7 @@
import os
import json
+import random
from datetime import datetime
from modules import Set
@@ -92,6 +93,24 @@ def tabs():
return tabs
+def accounts():
+
+ folder = Set.Folder()+"/accounts"
+ accounts = {}
+
+ for account in sorted(list(os.walk(folder))[0][2]):
+
+ try:
+ with open(folder+"/"+account) as o:
+ data = json.load(o)
+ accounts[account.replace(".json","")] = data
+ except Exception as e:
+ print(e)
+ pass
+
+ return accounts
+
+
def articles(tab):
folder = Set.Folder()+"/tabs/"+tab
@@ -100,7 +119,10 @@ def articles(tab):
try:
with open(folder+"/"+article+"/metadata.json") as o:
data = json.load(o)
+ data["tab"] = tab
+ data["url"] = "/"+tab+"/"+article
articles[article] = data
+
except Exception as e:
print(e)
pass
@@ -110,6 +132,85 @@ def articles(tab):
return articles
+def allArticles():
+
+ articles = {}
+ f = Set.Folder()
+ for tab in list(os.walk(f+"/tabs/"))[0][1]:
+ folder = f+"/tabs/"+tab
+
+ for article in list(os.walk(folder))[0][1]:
+ try:
+ with open(folder+"/"+article+"/metadata.json") as o:
+ data = json.load(o)
+ data["tab"] = tab
+ data["url"] = "/"+tab+"/"+article
+ articles[article] = data
+ except Exception as e:
+ print(e)
+ pass
+
+ # Sorting articles based on timestamp
+ articles = {k:articles[k] for k in sorted(articles, key=lambda y: articles[y]["timestamp"], reverse=True)}
+ return articles
+
+def randomArticles():
+
+ articles = {}
+ f = Set.Folder()
+ for tab in list(os.walk(f+"/tabs/"))[0][1]:
+ folder = f+"/tabs/"+tab
+
+ for article in list(os.walk(folder))[0][1]:
+ try:
+ with open(folder+"/"+article+"/metadata.json") as o:
+ data = json.load(o)
+ data["tab"] = tab
+ data["url"] = "/"+tab+"/"+article
+ articles[article] = data
+ except Exception as e:
+ print(e)
+ pass
+
+ # Randomizing Articles.
+ newarticles = {}
+ while articles:
+ article = random.choice(list(articles.keys()))
+ newarticles[article] = articles.pop(article)
+
+ return newarticles
+
+def suggestedArticles(cookie, random=False):
+
+ if not random:
+ articles = allArticles()
+ else:
+ articles = randomArticles()
+
+ # Suggesting unread articles.
+ newarticles = {}
+ move = []
+ for article in articles:
+ if cookie not in articles[article].get("views", {}).get("viewers", []):
+ move.append(article)
+
+ for article in move:
+ newarticles[article] = articles[article]
+
+ for article in articles:
+ if article not in move:
+ newarticles[article] = articles[article]
+
+ return newarticles
+
+def previewsToSize(text):
+
+ # Calculates roughly how many previews to fit any
+ # given article.
+
+ # A thousand character article is about 4 articles.
+ return int(round(len(text)/2500))
+
###
@@ -150,7 +251,21 @@ def MainPage(server):
html = html + ""
- for i in range(50): html = html + "
"
+ # Trending articles
+
+ html = html + '