generates follow page mostly the way I want
This commit is contained in:
parent
d9e998750c
commit
427d4ff972
83
microblog.py
83
microblog.py
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import sys, os, traceback
|
import sys, os, traceback
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
|
from time import strftime, localtime
|
||||||
|
|
||||||
# returns html-formatted string
|
# returns html-formatted string
|
||||||
def make_buttons(btn_dict, msg_id):
|
def make_buttons(btn_dict, msg_id):
|
||||||
@ -52,6 +53,8 @@ def make_gallery(indices, w, conf=None):
|
|||||||
tag.append("</div>")
|
tag.append("</div>")
|
||||||
return tag
|
return tag
|
||||||
|
|
||||||
|
# apply basic HTML formatting - only div class here is gallery
|
||||||
|
from html import escape
|
||||||
def markup(message, config):
|
def markup(message, config):
|
||||||
def is_image(s, image_formats):
|
def is_image(s, image_formats):
|
||||||
l = s.rsplit('.', maxsplit=1)
|
l = s.rsplit('.', maxsplit=1)
|
||||||
@ -116,8 +119,6 @@ def markup(message, config):
|
|||||||
gallery = []
|
gallery = []
|
||||||
return sep.join(output), tags
|
return sep.join(output), tags
|
||||||
|
|
||||||
# apply basic HTML formatting - only div class here is gallery
|
|
||||||
from html import escape
|
|
||||||
class Post:
|
class Post:
|
||||||
def __init__(self, ts, msg):
|
def __init__(self, ts, msg):
|
||||||
self.timestamp = ts.strip() # string
|
self.timestamp = ts.strip() # string
|
||||||
@ -321,6 +322,11 @@ if __name__ == "__main__":
|
|||||||
demote_css(html, config["relative_css"], lvl),
|
demote_css(html, config["relative_css"], lvl),
|
||||||
tcloud, timeline
|
tcloud, timeline
|
||||||
)
|
)
|
||||||
|
elif subdir == "placeholder":
|
||||||
|
lvl = 1
|
||||||
|
tcloud = make_tagcloud(tagcloud, "./tags/%s/latest.html")
|
||||||
|
with open ("follows.html", 'w') as f:
|
||||||
|
print(pagectrl.singlepage(html, tcloud, timeline),file=f)
|
||||||
else: # if timelines per tag
|
else: # if timelines per tag
|
||||||
is_tagline = True
|
is_tagline = True
|
||||||
lvl = 2
|
lvl = 2
|
||||||
@ -351,14 +357,15 @@ if __name__ == "__main__":
|
|||||||
def export_profile(post_count, last_update, config):
|
def export_profile(post_count, last_update, config):
|
||||||
if "profile" not in config:
|
if "profile" not in config:
|
||||||
return
|
return
|
||||||
if "alias" not in config["profile"] \
|
if "username" not in config["profile"] \
|
||||||
or "url" not in config["profile"]:
|
or "url" not in config["profile"]:
|
||||||
print("Warning: no profile exported", file=sys.stderr)
|
print("Warning: no profile exported", file=sys.stderr)
|
||||||
return
|
return
|
||||||
profile = {
|
profile = {
|
||||||
"username" : config["profile"]["alias"],
|
"username" : config["profile"]["username"],
|
||||||
"url": config["profile"]["url"],
|
"url": config["profile"]["url"],
|
||||||
"last-updated": last_update,
|
"last-updated": last_update,
|
||||||
|
"short-bio" : config["profile"]["short_bio"],
|
||||||
"post-count" : post_count
|
"post-count" : post_count
|
||||||
}
|
}
|
||||||
if "avatar" in config["profile"]:
|
if "avatar" in config["profile"]:
|
||||||
@ -367,13 +374,49 @@ if __name__ == "__main__":
|
|||||||
print(json.dumps(profile), file=f)
|
print(json.dumps(profile), file=f)
|
||||||
|
|
||||||
import urllib.request as http
|
import urllib.request as http
|
||||||
def fetch(follow_list):
|
def fn1(config): # come up with better name later
|
||||||
objects = []
|
def fetch(follow_list):
|
||||||
for eceleb in follow_list:
|
oither_people = []
|
||||||
with http.urlopen(eceleb) as response:
|
for someone in follow_list:
|
||||||
data = response.read()
|
try:
|
||||||
objects.append(json.loads(data))
|
with http.urlopen(someone) as response:
|
||||||
return objects
|
data = response.read()
|
||||||
|
objects.append(json.loads(data))
|
||||||
|
except urllib.error.HTTPError:
|
||||||
|
print("http error - skipping", file=sys.stderr)
|
||||||
|
pass
|
||||||
|
return other_people
|
||||||
|
list_of_json_objs = []
|
||||||
|
with open("meta.json",'r') as f:
|
||||||
|
list_of_json_objs.append(json.loads(f.read()))
|
||||||
|
# list_of_json_obj = fetch(config["profile"]["following"])
|
||||||
|
rendered = []
|
||||||
|
template = config["format"]
|
||||||
|
SHORT_BIO_LIMIT = 150
|
||||||
|
for profile in list_of_json_objs:
|
||||||
|
epoch_timestamp = profile["last-updated"]
|
||||||
|
if not isinstance(epoch_timestamp, int):
|
||||||
|
epoch_timestamp = 0
|
||||||
|
|
||||||
|
post_count = profile["post-count"]
|
||||||
|
if not isinstance(post_count, int):
|
||||||
|
post_count = 0
|
||||||
|
|
||||||
|
self_desc = profile["short-bio"]
|
||||||
|
if len(profile["short-bio"]) >= SHORT_BIO_LIMIT:
|
||||||
|
self_desc = profile["short-bio"][:SHORT_BIO_LIMIT] + "..."
|
||||||
|
|
||||||
|
rendered.append(template.format(
|
||||||
|
__avatar__=escape(profile["avatar"]),
|
||||||
|
__handle__=escape(profile["username"]),
|
||||||
|
__url__=escape(profile["url"]),
|
||||||
|
__post_count__ = post_count,
|
||||||
|
__shortbio__= escape(self_desc),
|
||||||
|
__lastupdated__= strftime(
|
||||||
|
"%Y %b %d", localtime(epoch_timestamp))
|
||||||
|
))
|
||||||
|
# print(html, file=sys.stderr)
|
||||||
|
return rendered
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
tpl, content = get_args()
|
tpl, content = get_args()
|
||||||
@ -388,11 +431,6 @@ if __name__ == "__main__":
|
|||||||
print("exit: table 'page' absent in settings.toml", file=sys.stderr)
|
print("exit: table 'page' absent in settings.toml", file=sys.stderr)
|
||||||
return
|
return
|
||||||
p = parse_txt(content)
|
p = parse_txt(content)
|
||||||
if "syndication" in cfg:
|
|
||||||
if cfg["syndication"]["enabled"] == True:
|
|
||||||
export_profile(
|
|
||||||
len(p), p[0].get_epoch_time(), cfg["syndication"]
|
|
||||||
)
|
|
||||||
tl, tc, tg = get_posts(p, cfg["post"])
|
tl, tc, tg = get_posts(p, cfg["post"])
|
||||||
if tl == []:
|
if tl == []:
|
||||||
return
|
return
|
||||||
@ -412,6 +450,14 @@ if __name__ == "__main__":
|
|||||||
tpl, tagline, tc, cfg["page"], \
|
tpl, tagline, tc, cfg["page"], \
|
||||||
subdir="tags/%s" % key[1:] \
|
subdir="tags/%s" % key[1:] \
|
||||||
)
|
)
|
||||||
|
if "syndication" in cfg:
|
||||||
|
if cfg["syndication"]["enabled"] == True:
|
||||||
|
export_profile(
|
||||||
|
len(p), p[0].get_epoch_time(), cfg["syndication"] )
|
||||||
|
if "following" in cfg["syndication"]:
|
||||||
|
fellows = fn1(cfg["syndication"]["following"] )
|
||||||
|
updated += writepage(
|
||||||
|
tpl, fellows, tc, cfg["page"], subdir="placeholder" )
|
||||||
with open("updatedfiles.txt", 'w') as f:
|
with open("updatedfiles.txt", 'w') as f:
|
||||||
for filename in updated:
|
for filename in updated:
|
||||||
print(filename, file=f) # sys.stderr)
|
print(filename, file=f) # sys.stderr)
|
||||||
@ -422,8 +468,11 @@ if __name__ == "__main__":
|
|||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print("\n\tA key may be missing from your settings file.", file=sys.stderr)
|
print("\n\tA key may be missing from your settings file.", file=sys.stderr)
|
||||||
except dateutil.parser._parser.ParserError as e:
|
except dateutil.parser._parser.ParserError:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print("\n\tFailed to interpret a date from string..",
|
print("\n\tFailed to interpret a date from string..",
|
||||||
"\n\tYour file of posts may be malformed.",
|
"\n\tYour file of posts may be malformed.",
|
||||||
"\n\tCheck if your file starts with a line break.", file=sys.stderr)
|
"\n\tCheck if your file starts with a line break.", file=sys.stderr)
|
||||||
|
except toml.decoder.TomlDecodeError:
|
||||||
|
traceback.print_exc()
|
||||||
|
print("\n\tYour configuration file is malformed.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user