squash merge gallery-tweak

This commit is contained in:
likho 2022-09-20 16:22:17 -07:00
parent c8d8673037
commit c787cf3ac8

View File

@ -35,46 +35,47 @@ def make_gallery(i, w):
# apply basic HTML formatting - only div class here is gallery
from html import escape
def markup(msg):
result = 0
tagged = ""
words = msg.split()
# support multiple images (gallery style)
images = [] # list of integers
tags = [] # list of strings
for i in range(len(words)):
word = words[i]
# don't help people click http
if word.find("src=") == 0 or word.find("href=") == 0:
continue
elif word.find("https://") != -1:
w = escape(word)
new_word = ("<a href=\"%s\">%s</a>") % (w, w)
words[i] = new_word
elif word.find("#") != -1 and len(word) > 1:
# split by unicode blank character if present
# allows tagging such as #fanfic|tion
w = word.split(chr(8206))
# w[0] is the portion closest to the #
tags.append(w[0])
new_word = "<span class=\"hashtag\">%s</span>" % (w[0])
if len(w) > 1:
new_word += w[1]
words[i] = new_word
elif word.find(".jpg") != -1 or word.find(".png") != -1:
images.append(i)
# are .gifs and other media files too much bloat?
gallery = make_gallery(images, words)
words += gallery
return " ".join(words), tags
# iterate through posts and get information about them
def get_posts(filename, email):
class Post:
def __init__(self, ts, msg):
self.timestamp = ts # string
self.message = msg # list
pass
def markup(self):
result = 0
tagged = ""
# support multiple images (gallery style)
tags = [] # list of strings
output = []
for line in self.message:
images = [] # list of integers
words = line.split()
for i in range(len(words)):
word = words[i]
# don't help people click http
if word.find("src=") == 0 or word.find("href=") == 0:
continue
elif word.find("https://") != -1:
w = escape(word)
new_word = ("<a href=\"%s\">%s</a>") % (w, w)
words[i] = new_word
elif word.find("#") != -1 and len(word) > 1:
# split by unicode blank character if present
# allows tagging such as #fanfic|tion
w = word.split(chr(8206))
# w[0] is the portion closest to the #
tags.append(w[0])
new_word = "<span class=\"hashtag\">%s</span>" % (w[0])
if len(w) > 1:
new_word += w[1]
words[i] = new_word
elif word.find(".jpg") != -1 or word.find(".png") != -1:
images.append(i)
if len(images) > 0:
gallery = make_gallery(images, words)
words += gallery
output.append(" ".join(words))
return "<br>".join(output), tags
def parse_txt(filename):
content = []
@ -98,7 +99,7 @@ def get_posts(filename, email):
if len(line) > 1:
message.append(line)
else:
p = Post(timestamp, "<br>".join(message))
p = Post(timestamp, message)
posts.append(p)
# reset
message = []
@ -114,7 +115,7 @@ def get_posts(filename, email):
index = count # - 1
timeline = []
for post in posts:
markedup, tags = markup(post.message)
markedup, tags = post.markup()
count -= 1
index -= 1
timeline.append(