<commit_before>from threading import Timer
from packtpub import PacktpubController
import time, base64, cherrypy

class Root(object):
	def __init__(self, pull_delay):
		cherrypy.engine.subscribe('stop', self.stop)
		self.status = ""
		self.timer = None
		self.users = [];
		self.next_pull_time = 0
		self.pull_delay = pull_delay

	def __format_time(self, time_ = None):
		if time_ == None:
			time_ = time.time()
		res = ""
		if time_ < 0:
			res += "-"
			time_ = -time_
		res += time.strftime('%H:%M:%S', time.localtime(time_))	
		return res

	def __log(self, message):
		if self.status != "" :
			self.status += "\n"
		self.status += self.__format_time()
		if self.status[-1:] != "\n" and message[0] != "\n":
			self.status += "\n"
		self.status += message

	def stop(self):
		if self.timer:
			self.timer.cancel()

	@cherrypy.expose
	def index(self):
		return """<!DOCTYPE html>
			<html>
				<head>
					<title>Packtpub Claimer</title>
				</head>
				<body>
					<form method="post" action="/register">
						<input type="email" name="email" placeholder="email" /><br />
						<input type="password" name="password" placeholder="password" /><br/>
						<input type="submit" value="Register" />
					</form>
					""" + self.status + """
					<h1>Current time: """ + self.__format_time() + """</h1>
					<h2>Time until next pull: """ + self.__format_time(self.next_pull_time - time.time()) + """</h2>
				</body>
			</html>"""

	@cherrypy.expose
	def registered(self):
		return '\n'.join(user['email'] for user in self.users)

	@cherrypy.expose
	def register(self, email, password):
		packtpub_controller = PacktpubController()
		if packtpub_controller.login(email, password):
			user = {
				'email': email,	
				'password': <PASSWORD>.b64encode(password),
				'controller': packtpub_controller,
			}
			self.users.append(user)
			is_new_user = True
			users_file = open("users.txt", "r")
			for username in users_file.readlines():
				if username == user['email']:
					is_new_user = False
					break
			users_file.close()
			if is_new_user:
				users_file = open("users.txt", "a")
				users_file.write(user['email'])
				users_file.close()
			self.__log("New user registered: " + email)
			return 'registered as ' + email + '!<br><a href="/">back</a>'
		else:<commit_msg>Disallow duplicate registration<commit_after>from threading import Timer
from packtpub import PacktpubController
import time, base64, cherrypy

class Root(object):
	def __init__(self, pull_delay):
		cherrypy.engine.subscribe('stop', self.stop)
		self.status = ""
		self.timer = None
		self.users = [];
		self.next_pull_time = 0
		self.pull_delay = pull_delay

	def __format_time(self, time_ = None):
		if time_ == None:
			time_ = time.time()
		res = ""
		if time_ < 0:
			res += "-"
			time_ = -time_
		res += time.strftime('%H:%M:%S', time.localtime(time_))	
		return res

	def __log(self, message):
		if self.status != "" :
			self.status += "\n"
		self.status += self.__format_time()
		if self.status[-1:] != "\n" and message[0] != "\n":
			self.status += "\n"
		self.status += message

	def stop(self):
		if self.timer:
			self.timer.cancel()

	@cherrypy.expose
	def index(self):
		return """<!DOCTYPE html>
			<html>
				<head>
					<title>Packtpub Claimer</title>
				</head>
				<body>
					<form method="post" action="/register">
						<input type="email" name="email" placeholder="email" /><br />
						<input type="password" name="password" placeholder="password" /><br/>
						<input type="submit" value="Register" />
					</form>
					""" + self.status + """
					<h1>Current time: """ + self.__format_time() + """</h1>
					<h2>Time until next pull: """ + self.__format_time(self.next_pull_time - time.time()) + """</h2>
				</body>
			</html>"""

	@cherrypy.expose
	def registered(self):
		return '\n'.join(user['email'] for user in self.users)

	@cherrypy.expose
	def register(self, email, password):
		for user in self.users:
			if email == user['email']:
				return "User " + email + " is already registered."
		packtpub_controller = PacktpubController()
		if packtpub_controller.login(email, password):
			user = {
				'email': email,	
				'password': <PASSWORD>(password),
				'controller': packtpub_controller,
			}
			self.users.append(user)
			is_new_user = True
			users_file = open("users.txt", "r")
			for username in users_file.readlines():
				if username == user['email']:
					is_new_user = False
					break
			users_file.close()
			if is_new_user:
				users_file = open("users.txt", "a")
				users_file.write(user['email'])
				users_file.close()
			self.__log("New user registered: " + email)
			return 'registered as ' + email + '!<br><a href="/">back</a>'
		else:
{'fraction_non_alphanumeric': 0.1709090909090909, 'fraction_numerical': 0.004705882352941176, 'mean_word_length': 3.4406457739791074, 'pattern_counts': {'":': 2, '<': 53, '<?xml version=': 0, '>': 51, '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': '2698171', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1610, 'n_words': 366}