# coding: utf-8
import shelve

from datetime import datetime

from flask import Flask, request, render_template, redirect, escape, Markup

application = Flask(__name__)

DATA_FILE = 'guestbook.dat'

def save_data(name, comment, create_at):
    """Save Posted Data
    """

    # open database file with shelve module
    database = shelve.open(DATA_FILE)

    # create new list unless greeting_list exists in database
    if 'greeting_list' not in database:
        greeting_list = []
    else:
        # Fetch data from database
        greeting_list = database['greeting_list']

    # Add Posted data at the top of the list
    greeting_list.insert(0, {
        'name':      name,
        'comment':   comment,
        'create_at': create_at
    })

    # Reload database
    database['greeting_list'] = greeting_list

    # Close database file
    database.close()


def load_data():
    """Return Posted data
    """

    # Open database file with shelve module
    database = shelve.open(DATA_FILE)

    # Return greeting_list.
    # Return empty list if there is no data
    greeting_list = database.get('greeting_list', [])
    database.close()
    return greeting_list


@application.route('/')
def index():
    """Top Page
    Show page with template.
    """

    # Load Posted data
    greeting_list = load_data()

    return render_template('index.html', greeting_list=greeting_list)


@application.route('/post', methods=['POST'])
def post():
    """URL for Post
    """

    # Receive Posted data
    name      = request.form.get('name')
    comment   = request.form.get('comment')
    create_at = datetime.now()

    # Save data
    save_data(name, comment, create_at)

    # Redirect to top page after saving
    return redirect('/')


@application.template_filter('nl2br')
def nl2br_filter(s):
    """Replace newline to <br />
    """

    return escape(s).replace('\n', Markup('<br />'))


@application.template_filter('datetime_fmt')
def datetime_fmt_filter(dt):
    """Improve readibility of datetime object
    """

    return dt.strftime('%Y%m%d %H:%M:%S')


if __name__ == "__main__":
    # Execute with http://127.0.0.1:8000
    application.run('127.0.0.1', 8000, debug=True)

@@ -2074,16 +2074,69 @@
 :%25S')%0A%0A%0A
+def main():%0A    application.run('127.0.0.1', 8000)%0A%0A%0A
 if __nam

Add entry_points to guestbook/__init__.py def main()