squash merge gallery-tweak
This commit is contained in:
parent
c8d8673037
commit
c787cf3ac8
31
microblog.py
31
microblog.py
@ -35,13 +35,21 @@ def make_gallery(i, w):
|
|||||||
|
|
||||||
# apply basic HTML formatting - only div class here is gallery
|
# apply basic HTML formatting - only div class here is gallery
|
||||||
from html import escape
|
from html import escape
|
||||||
def markup(msg):
|
# 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
|
||||||
|
def markup(self):
|
||||||
result = 0
|
result = 0
|
||||||
tagged = ""
|
tagged = ""
|
||||||
words = msg.split()
|
|
||||||
# support multiple images (gallery style)
|
# support multiple images (gallery style)
|
||||||
images = [] # list of integers
|
|
||||||
tags = [] # list of strings
|
tags = [] # list of strings
|
||||||
|
output = []
|
||||||
|
for line in self.message:
|
||||||
|
images = [] # list of integers
|
||||||
|
words = line.split()
|
||||||
for i in range(len(words)):
|
for i in range(len(words)):
|
||||||
word = words[i]
|
word = words[i]
|
||||||
# don't help people click http
|
# don't help people click http
|
||||||
@ -63,18 +71,11 @@ def markup(msg):
|
|||||||
words[i] = new_word
|
words[i] = new_word
|
||||||
elif word.find(".jpg") != -1 or word.find(".png") != -1:
|
elif word.find(".jpg") != -1 or word.find(".png") != -1:
|
||||||
images.append(i)
|
images.append(i)
|
||||||
# are .gifs and other media files too much bloat?
|
if len(images) > 0:
|
||||||
gallery = make_gallery(images, words)
|
gallery = make_gallery(images, words)
|
||||||
words += gallery
|
words += gallery
|
||||||
return " ".join(words), tags
|
output.append(" ".join(words))
|
||||||
|
return "<br>".join(output), 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 parse_txt(filename):
|
def parse_txt(filename):
|
||||||
content = []
|
content = []
|
||||||
@ -98,7 +99,7 @@ def get_posts(filename, email):
|
|||||||
if len(line) > 1:
|
if len(line) > 1:
|
||||||
message.append(line)
|
message.append(line)
|
||||||
else:
|
else:
|
||||||
p = Post(timestamp, "<br>".join(message))
|
p = Post(timestamp, message)
|
||||||
posts.append(p)
|
posts.append(p)
|
||||||
# reset
|
# reset
|
||||||
message = []
|
message = []
|
||||||
@ -114,7 +115,7 @@ def get_posts(filename, email):
|
|||||||
index = count # - 1
|
index = count # - 1
|
||||||
timeline = []
|
timeline = []
|
||||||
for post in posts:
|
for post in posts:
|
||||||
markedup, tags = markup(post.message)
|
markedup, tags = post.markup()
|
||||||
count -= 1
|
count -= 1
|
||||||
index -= 1
|
index -= 1
|
||||||
timeline.append(
|
timeline.append(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user