aboutsummaryrefslogtreecommitdiffstats
path: root/blogthon.cgi
diff options
context:
space:
mode:
Diffstat (limited to 'blogthon.cgi')
-rwxr-xr-xblogthon.cgi53
1 files changed, 42 insertions, 11 deletions
diff --git a/blogthon.cgi b/blogthon.cgi
index 963f120..96dcbe3 100755
--- a/blogthon.cgi
+++ b/blogthon.cgi
@@ -23,8 +23,9 @@ import codecs
# print() will output ascii, but we want utf-8 (python3)
try:
sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
+ utf8 = True
except:
- None
+ utf8 = False
# Backward compatibilty to python2
try:
@@ -227,10 +228,16 @@ if cname and ctext and ctitle:
else:
comments_file = os.path.join(entries_dir, ctitle + ".comments")
if not os.path.exists(comments_file):
- content = open(comments_file, "w", encoding="utf8")
+ if utf8:
+ content = open(comments_file, "w", encoding="utf8")
+ else:
+ content = open(comments_file, "w")
content.close()
- content = open(comments_file, "a", encoding="utf8")
+ if utf8:
+ content = open(comments_file, "a", encoding="utf8")
+ else:
+ content = open(comments_file, "a")
content.write("-." + cname + "\n")
content.write("+." + time.strftime("%c", time.localtime()) + "\n")
ctext = ctext.split("\n")
@@ -306,7 +313,10 @@ if feed_display == "atom":
print(ind*3 + "<id>urn:uuid:%s</id>" % title_md5sum)
print(ind*3 + "<updated>%s-%s-%sT%s:%s:%sZ</updated>" % (str(date[0]), month, day, hour, min, sec))
print(ind*3 + "<summary>")
- content = open(str(entries[i][1]), "r", encoding="utf8")
+ if utf8:
+ content = open(str(entries[i][1]), "r", encoding="utf8")
+ else:
+ content = open(str(entries[i][1]), "r")
for h in range(0, int(feed_preview)):
rss_line = content.readline().strip()
if rss_line != "":
@@ -336,7 +346,10 @@ elif feed_display == "rss":
print(ind*3 + "<link>%s?p=%s</link>" % (blog_url, title))
print(ind*3 + "<guid>%s?p=%s</guid>" % (blog_url, title))
print(ind*3 + "<pubDate>%s</pubDate>" % date)
- content = open(str(entries[i][1]), "r", encoding="utf8")
+ if utf8:
+ content = open(str(entries[i][1]), "r", encoding="utf8")
+ else:
+ content = open(str(entries[i][1]), "r")
rss_description= ""
for h in range(0, int(feed_preview)):
line = content.readline().strip()
@@ -400,7 +413,10 @@ else:
print(ind*3 + "<div class=\"pages_list\">")
print(ind*4 + "<ul class=\"pages_list\">")
for staticpage in staticpages_list:
- file = open(staticpage, "r", encoding="utf8")
+ if utf8:
+ file = open(staticpage, "r", encoding="utf8")
+ else:
+ file = open(staticpage, "r")
header = file.readline()
if header.split(":", 1)[0] == "extern_link":
link = header.split(":", 1)[1].strip()
@@ -442,7 +458,10 @@ else:
print(ind*3 + "<div class=\"linklist_list\">")
print(ind*4 + "<ul class=\"linklist_list\">")
try:
- content = open("linklist", "r", encoding="utf8")
+ if utf8:
+ content = open("linklist", "r", encoding="utf8")
+ else:
+ content = open("linklist", "r")
for line in content:
if line.strip() is "":
print("<br />")
@@ -462,7 +481,10 @@ else:
# Staticpage
if static_display != "":
- content = open(os.path.join(staticpages_dir, static_display), "r", encoding="utf-8")
+ if utf8:
+ content = open(os.path.join(staticpages_dir, static_display), "r", encoding="utf-8")
+ else:
+ content = open(os.path.join(staticpages_dir, static_display), "r")
print(ind*3 + "<div class=\"entry\">")
print(ind*4 + "<div class=\"entry_title\">%s</div>" % re.sub("^\.", "", re.sub("\d+?-", "", static_display)))
print(ind*4 + "<div class=\"entry_content\">")
@@ -501,7 +523,10 @@ else:
if month_display == date_to_compare or not month_display:
if post_display == title.replace(" ", "-") or not post_display:
if allentries_display == "1" or entry_counter < entries_per_page:
- content = open(entry, "r", encoding="utf8")
+ if utf8:
+ content = open(entry, "r", encoding="utf8")
+ else:
+ content = open(entry, "r")
print(ind*3 + "<div class=\"entry\">")
if permalinks:
print(ind*4 + "<div class=\"entry_title\"><a href=\"?p=%s\" class=\"entry_title\">%s</a></div>" % (title.replace(" ", "-"), title))
@@ -526,7 +551,10 @@ else:
comments_file = glob(os.path.join(entries_dir, title + ".comments"))
if post_display:
if comments_file:
- comments_content = open(comments_file[0], "r", encoding="utf8")
+ if utf8:
+ comments_content = open(comments_file[0], "r", encoding="utf8")
+ else:
+ comments_content = open(comments_file[0], "r")
print(ind*3 + "</div>")
print(ind*2 + "</div>")
print("")
@@ -592,7 +620,10 @@ else:
print(ind*3 + "</div>")
print("")
elif comments_file and not post_display:
- comments_content = open(comments_file[0], "r", encoding="utf8")
+ if utf8:
+ comments_content = open(comments_file[0], "r", encoding="utf8")
+ else:
+ comments_content = open(comments_file[0], "r")
comments_counter = 0
for line in comments_content:
if line.split(".", 1)[0] == "-": comments_counter += 1