Some code cleanup
This commit is contained in:
parent
9a8023158b
commit
6575010157
44
blogthon.cgi
44
blogthon.cgi
@ -16,17 +16,17 @@
|
||||
# * Complete Atom Feed (like RSS)
|
||||
# * Fix broken charset in outgoing mails (needs some testing)
|
||||
|
||||
import ConfigParser
|
||||
from ConfigParser import ConfigParser
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import locale
|
||||
import re
|
||||
import cgi
|
||||
import glob
|
||||
import md5
|
||||
import random
|
||||
import smtplib
|
||||
from smtplib import SMTP
|
||||
from md5 import new as newmd5
|
||||
from glob import glob
|
||||
from random import randint
|
||||
|
||||
# A wonderful place for doing some regexp ;)
|
||||
no_break = re.compile('^\s*(<ul|</ul>|<li|</li>|<ol|</ol>|<table|</table>|<tr|</tr>|<td|</td>|<th|</th>|<p|</p>).*$')
|
||||
@ -36,18 +36,13 @@ line_start_plus = re.compile('^\+.*$')
|
||||
tab = "\t"
|
||||
|
||||
def generate_uuid(string):
|
||||
string_md5sum = md5.new(string).hexdigest()
|
||||
string_md5sum = newmd5(string).hexdigest()
|
||||
string = str.join('-', (string_md5sum[0:8], string_md5sum[8:12], string_md5sum[12:16], string_md5sum[16:20], string_md5sum[20:32]))
|
||||
return string
|
||||
|
||||
def errorpage(string):
|
||||
print 'Content-type: text/html\n'
|
||||
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
|
||||
print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
||||
print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'
|
||||
print '<head>'
|
||||
print tab + '<title>Error!</title>'
|
||||
print '</head>'
|
||||
document_header('xhtml-strict')
|
||||
print '<head><title>Error!</title></head>'
|
||||
print '<body>'
|
||||
print tab + string
|
||||
print '</body>'
|
||||
@ -74,7 +69,7 @@ def document_header(string):
|
||||
print '<?xml version="1.0" encoding="utf-8"?>'
|
||||
print '<rss version="2.0">'
|
||||
|
||||
configuration = ConfigParser.ConfigParser()
|
||||
configuration = ConfigParser()
|
||||
|
||||
# Look for a configuration:
|
||||
if os.path.exists('../blogthonrc'):
|
||||
@ -217,7 +212,7 @@ if cname and ctext and ctitle:
|
||||
if not cquiz == cquizv:
|
||||
errorpage("Brainmode")
|
||||
else:
|
||||
comments_file = glob.glob(entries_dir + ctitle + '.comments')
|
||||
comments_file = glob(entries_dir + ctitle + '.comments')
|
||||
if not comments_file:
|
||||
try:
|
||||
content = open(entries_dir + ctitle + '.comments', "w")
|
||||
@ -235,7 +230,8 @@ if cname and ctext and ctitle:
|
||||
# Send mail?
|
||||
if not new_comment_mail == 'False':
|
||||
msg = 'From: Blogthon\nTo: ' + mail_to + '\nSubject: New comment on ' + blog_title + '\n\nSomeone wrote a comment to this entry: ' + blog_url + '?p=' + ctitle.replace(' ', '-')
|
||||
smtp = smtplib.SMTP(smtp_host)
|
||||
smtp = SMTP(smtp_host)
|
||||
smtp.starttls() # TODO: some hosts need TLS, needs testing
|
||||
smtp.sendmail(blog_title, mail_to, msg)
|
||||
smtp.quit()
|
||||
except:
|
||||
@ -243,7 +239,7 @@ if cname and ctext and ctitle:
|
||||
|
||||
# Read entries and store their title and timestamp
|
||||
entries = []
|
||||
entries_list = glob.glob(entries_dir + '*.' + entries_suffix)
|
||||
entries_list = glob(entries_dir + '*.' + entries_suffix)
|
||||
|
||||
for entry in entries_list:
|
||||
timestamp = os.stat(entry)
|
||||
@ -346,7 +342,7 @@ else:
|
||||
|
||||
# Plugins
|
||||
sys.path.append(plugins_dir)
|
||||
for plugin in glob.glob(plugins_dir + '*.py'):
|
||||
for plugin in glob(plugins_dir + '*.py'):
|
||||
__import__ (plugin.split('/')[1].replace('.py', ''))
|
||||
|
||||
# Site header
|
||||
@ -375,7 +371,7 @@ else:
|
||||
# Staticpages
|
||||
if staticpages == "True":
|
||||
staticpages = []
|
||||
staticpages_list = glob.glob(staticpages_dir + '*')
|
||||
staticpages_list = glob(staticpages_dir + '*')
|
||||
staticpages_list.sort()
|
||||
print tab*2 + '<div class="pages">'
|
||||
print tab*3 + '<div class="pages_title">' + blog_locale[0] + '</div>'
|
||||
@ -500,10 +496,10 @@ else:
|
||||
|
||||
# Comments...
|
||||
# ... are shown when post_display and comments_file isn't false
|
||||
comments_file = glob.glob(entries_dir + title + '.comments')
|
||||
comments_file = glob(entries_dir + title + '.comments')
|
||||
if post_display:
|
||||
if comments_file:
|
||||
comments_file = glob.glob(entries_dir + title + '.comments')
|
||||
comments_file = glob(entries_dir + title + '.comments')
|
||||
comments_content = open(comments_file[0], "r")
|
||||
print tab*3 + '</div>'
|
||||
print tab*2 + '</div>'
|
||||
@ -544,8 +540,8 @@ else:
|
||||
|
||||
# Form for adding comments
|
||||
if comments == "True":
|
||||
random_int_a = random.randint(1,9)
|
||||
random_int_b = random.randint(1,9)
|
||||
random_int_a = randint(1,9)
|
||||
random_int_b = randint(1,9)
|
||||
cquizv = random_int_a + random_int_b
|
||||
print tab*3 + '<div class="submit_comment">'
|
||||
print tab*4 + '<form action="" method="post">'
|
||||
@ -562,7 +558,7 @@ else:
|
||||
print ''
|
||||
|
||||
if comments == "True":
|
||||
comments_file = glob.glob(entries_dir + title + '.comments')
|
||||
comments_file = glob(entries_dir + title + '.comments')
|
||||
if not comments_file and not post_display:
|
||||
print tab*4 + '<div class="entry_comment">'
|
||||
print tab*5 + '<a href="?p=' + title.replace(' ','-') + '" class="entry_comment">' + blog_locale[3] + '</a>'
|
||||
|
Loading…
Reference in New Issue
Block a user