<commit_before># encoding=utf-8

import os.path
import random
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import MySQLdb

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

class IndexHandler(tornado.web.RequestHandler):
    def get(self):
        self.render('index.html')


class PoemPageHandler(tornado.web.RequestHandler):
	def get(self):
		db = MySQLdb.connect("localhost","3000word","","3000word")
		cursor = db.cursor()
		cursor.execute("SELECT * FROM record ORDER BY id DESC LIMIT 1;")
		r = cursor.fetchone()
		db.commit()
		totalCount = r[2]
		recordID = r[1]
		if recordID == totalCount:
			sql = "INSERT INTO record (record,totalCount) values(0,'%d')" % (totalCount)
			cursor.execute(sql)
			recordID = 0
			db.commit()
		sql = "SELECT * from word LIMIT %d,1;" % recordID
		cursor.execute(sql)
		r = cursor.fetchone()
		times = r[0]
		db.commit()
		def randomAnswer ():
			record_random = random.randint(1,3000)
			sql = "SELECT * from word LIMIT %d,1;" % record_random
			cursor.execute(sql)
			r = cursor.fetchone()[2]
			s = r.split(";")
			db.commit()
			return s[random.randint(0,len(s)-1)]
		answer_set = [randomAnswer(),randomAnswer(),randomAnswer()]
		answer_index = random.randint(0,3)
		correct_answer_t = r[2].split(";")
		correct_answer = correct_answer_t[random.randint(0,len(correct_answer_t)-1)]
		answer_set.insert(answer_index,correct_answer)
		db.close()
		q = r[1]
		a1 = answer_set[0]
		a2 = answer_set[1]
		a3 = answer_set[2]
		a4 = answer_set[3]
		self.render('3000words.html',recordID=recordID, totalCount=totalCount, \
			q=q,times=times,a1=a1,a2=a2,a3=a3,a4=a4,correct=answer_index+1)

	def post(self):
		db = MySQLdb.connect("localhost","3000word","","3000word")
		cursor = db.cursor()
		recordID_new = self.get_argument("ID")
		recordID_new = int(recordID_new) + 1
		sql = "UPDATE record SET record='%d';" % recordID_new 
		cursor.execute(sql)
		db.commit()
		db.close()
		self.get()

if __name__ == '__main__':
	tornado.options.parse_command_line()

	app = tornado.web.Application(
		handlers=[(r'/', IndexHandler), (r'/3000words', PoemPageHandler)],
		template_path=os.path.join(os.path.dirname(__file__), ""),
		static_path=os.path.join(os.path.dirname(__file__), "statics"),
		debug=True
	)
 


	http_server = tornado.httpserver.HTTPServer(app)
	http_server.listen(options.port)
	tornado.ioloop.IOLoop.instance().start()

<commit_msg>fixed bugs about how many times<commit_after># encoding=utf-8

import os.path
import random
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import MySQLdb

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

class IndexHandler(tornado.web.RequestHandler):
    def get(self):
        self.render('index.html')


class PoemPageHandler(tornado.web.RequestHandler):
	def get(self):
		db = MySQLdb.connect("localhost","3000word","","3000word")
		cursor = db.cursor()
		cursor.execute("SELECT * FROM record ORDER BY id DESC LIMIT 1;")
		r = cursor.fetchone()
		times = r[0]
		db.commit()
		totalCount = r[2]
		recordID = r[1]
		if recordID == totalCount:
			sql = "INSERT INTO record (record,totalCount) values(0,'%d')" % (totalCount)
			cursor.execute(sql)
			recordID = 0
			times = times + 1
			db.commit()
		sql = "SELECT * from word LIMIT %d,1;" % recordID
		cursor.execute(sql)
		r = cursor.fetchone()
		db.commit()
		def randomAnswer ():
			record_random = random.randint(1,3000)
			sql = "SELECT * from word LIMIT %d,1;" % record_random
			cursor.execute(sql)
			r = cursor.fetchone()[2]
			s = r.split(";")
			db.commit()
			return s[random.randint(0,len(s)-1)]
		answer_set = [randomAnswer(),randomAnswer(),randomAnswer()]
		answer_index = random.randint(0,3)
		correct_answer_t = r[2].split(";")
		correct_answer = correct_answer_t[random.randint(0,len(correct_answer_t)-1)]
		answer_set.insert(answer_index,correct_answer)
		db.close()
		q = r[1]
		a1 = answer_set[0]
		a2 = answer_set[1]
		a3 = answer_set[2]
		a4 = answer_set[3]
		self.render('3000words.html',recordID=recordID, totalCount=totalCount, \
			q=q,times=times,a1=a1,a2=a2,a3=a3,a4=a4,correct=answer_index+1)

	def post(self):
		db = MySQLdb.connect("localhost","3000word","","3000word")
		cursor = db.cursor()
		recordID_new = self.get_argument("ID")
		recordID_new = int(recordID_new) + 1
		sql = "UPDATE record SET record='%d';" % recordID_new 
		cursor.execute(sql)
		db.commit()
		db.close()
		self.get()

if __name__ == '__main__':
	tornado.options.parse_command_line()

	app = tornado.web.Application(
		handlers=[(r'/', IndexHandler), (r'/3000words', PoemPageHandler)],
		template_path=os.path.join(os.path.dirname(__file__), ""),
		static_path=os.path.join(os.path.dirname(__file__), "statics"),
		debug=True
	)
 


	http_server = tornado.httpserver.HTTPServer(app)
	http_server.listen(options.port)
	tornado.ioloop.IOLoop.instance().start()


{'fraction_non_alphanumeric': 0.15479752643127867, 'fraction_numerical': 0.027727907440654297, 'mean_word_length': 4.789838337182448, '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': '576553', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1823, 'n_words': 340}