<commit_before># -*- coding: utf-8 -*-
from bottle import * 
import sys
from jinja2 import Template

reload(sys)
sys.setdefaultencoding( "utf-8" )

# dababase
import sqlite3
conn = sqlite3.connect('mydaily.db') # connect to  'mydaily.db'
c = conn.cursor()



# 打开历史文件
def print_log():
    open_file = open("mydaily.log")
    log = open_file.read()
    return log

# 向历史文件写入数据
def new(txt_add):
    target = open("mydaily.log", 'a')
    target.write(txt_add + '\n')
    target.close()



@route('/')
@route('/text') #text 页面
def input(): #把text页面与 input 函数绑定，每次打开text 页面，得到 input 函数的返回值
    log = print_log()
    return template('in.tpl', history = log)

@route('/text', method ='POST')
def do_input():
    data = request.forms.get('indata')
    new(data)
    log = print_log()
    return template('in.tpl', history = log)<commit_msg>create a table and a row of data<commit_after># -*- coding: utf-8 -*-
from bottle import * 
import sys
from jinja2 import Template

reload(sys)
sys.setdefaultencoding( "utf-8" )

# dababase
import sqlite3
conn = sqlite3.connect('mydaily.db') # connect to  'mydaily.db'
c = conn.cursor()
# creat a table with sql commands
#c.execute('''CREATE TABLE mydaily_log
#                (time text, contents text, tag text)''')
c.execute("INSERT INTO mydaily_log VALUES ('2016-01-10','1st row of diary in database','test')")
conn.commit()
c.execute("SELECT * FROM mydaily_log")
print c.fetchone()
conn.close()

# 打开历史文件
def print_log():
    open_file = open("mydaily.log")
    log = open_file.read()
    return log

# 向历史文件写入数据
def new(txt_add):
    target = open("mydaily.log", 'a')
    target.write(txt_add + '\n')
    target.close()



@route('/')
@route('/text') #text 页面
def input(): #把text页面与 input 函数绑定，每次打开text 页面，得到 input 函数的返回值
    log = print_log()
    return template('in.tpl', history = log)

@route('/text', method ='POST')
def do_input():
    data = request.forms.get('indata')
    new(data)
    log = print_log()
    return template('in.tpl', history = log)
{'fraction_non_alphanumeric': 0.1593186372745491, 'fraction_numerical': 0.009519038076152305, 'mean_word_length': 3.777511961722488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1278043', 'n_tokens_mistral': 773, 'n_tokens_neox': 768, 'n_words': 188}