diff --git a/microblog.py b/microblog.py
index adbab87..47d800c 100644
--- a/microblog.py
+++ b/microblog.py
@@ -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 = ("%s") % (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 = "%s" % (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 = ("%s") % (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 = "%s" % (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 "
".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, "
".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(