<commit_before>import string
import json
import urllib.request
import requests
import pymysql
import re
import random

from pytz import timezone
from datetime import datetime, timedelta, date, time
from Settings import CHANNEL, connection
from TheSocket import openSocket, sendMessage

def getUser(line):

	separate = line.split(":", 2)
	user = separate[1].split("!", 1)[0]
	return user

def getMessage(line):

	separate = line.split(":", 2)
	message = separate[2]
	return message

def get_points(check_user):

	check_db = connection.cursor()
	count = check_db.execute("SELECT COUNT(*) FROM table1")
	#print(count) # prints no. of rows
	check_db.execute("SELECT user_id from table1")
	data = check_db.fetchall() 
	#print(data) # print user_id rows

	for x in range(0, count + 1):

		if data[x] != str(check_user):

			check_db.execute("INSERT ignore into table1 VALUES ( '" + check_user + "', " + str(0) + " )")
			check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")
			points = check_db.fetchone()

			format_points = re.findall('\d+', str(points))
			result_points = (check_user + " has " + format_points[0] + " points")
			return(str(result_points))
 
		if data[x] == str(check_user):

			check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")
			return_points = check_db.fetchone()

			format_checkpoints = re.findall('\d+', str(return_points))
			result_checkpoints = (check_user + " has " + format_points[0] + " points")
			return(str(result_checkpoints))

	connection.close()

def add_points():

	pointnum = 16 # 4 points per minute
	check_db = connection.cursor()
	check_db.execute("UPDATE table1 set points = points + " + str(pointnum))

def roulette(check_user, gamble):

	check_db = connection.cursor()

	int_gamble = int(re.search(r'\d+', gamble).group())
	#print(int_gamble)

	result = int_gamble * 2
	#print(result)

	roll = random.randrange(1, 3)
	if(roll == 1):
		check_db.execute("UPDATE table1 set points = points + " + str(result) + " where user_id = '" + str(check_user) + "' ")
		return(check_user + " gambled " + str(int_gamble) + " points and won " + str(result) + " points! PogChamp")
	if(roll == 2):
		check_db.execute("UPDATE table1 set points = points - " + str(result) + " where user_id = '" + str(check_user) + "'")
		return(check_user + " gambled " + str(int_gamble) + " points and lost " + str(result) + " points! BibleThump")

	#ADD POINTS
	#UPDATE table1 set points = points + 10 where user_id = 'kritzware';


	# for x in data:
	# 	if check_user not in data:
	# 		print("user not found, adding to database")
	# 		check_db.execute("INSERT into table1 VALUES ( '" + check_user + "', " + str(0) + " )")
	# 		check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")
			
	# 		new_points = check_db.fetchone()
	# 		strnew_points = str(new_points)

	# 		format_newpoints = re.findall('\d+', strnew_points)
	# 		new_result = (check_user + " has " + format_newpoints[0] + " points")
	# 		return(strnew_points)

	# else:
	# 	check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")

	# 	points = check_db.fetchall()
	# 	strpoints = str(points)
	
	# 	formatp = re.findall('\d+', strpoints)
	# 	result = (check_user + " has " + formatp[0] + " points")
	# 	return(result)

	# result = check_user + " has {} " + " points".format(points[0:3])
	# print(result)
	# return(str(result))

	# if check_user in check_db.fetchall():
	# 	points = check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")
	# 	print("user points found")
	# 	return check_user + " has" + points + " points"
	# else:
	# 	check_db.execute("INSERT into table1 VALUES ( '" + check_user + "', " + str(0) + " )")
	# 	print("adding new user to db")
	# 	return check_user + " has 0 points FeelsBadMan"
 
	


def uptime():

	user_channel = CHANNEL
	url = 'https://api.twitch.tv/kraken/channels/' + user_channel + '/videos?limit=1&broadcasts=true'
	req = urllib.request.urlopen(url)
	data = json.loads(req.read().decode('UTF-8'))
	latestbroadcast = data['videos'][0]['recorded_at']
	online = True

	#print("Broadcast start: " + latestbroadcast)

	timeformat = "%Y-%m-%dT%H:%M:%SZ"
	startdate = datetime.strptime(latestbroadcast, timeformat)
	currentdate = datetime.utcnow()
	combineddate = currentdate - startdate - timedelta(microseconds=currentdate.microsecond)

	check_request = urllib.request.urlopen('https://api.twitch.tv/kraken/streams/' + user_channel)
	check_online = json.loads(check_request.read().decode('UTF-8'))
	if(check_online['stream'] == None):
		online = False

	hours = str(combineddate)[:1]
	minutes = str(combineddate)[2:4]

	if(online):
		#print(combineddate)
		return(user_channel + " has been live for " + hours + " hrs, " + minutes + " mins")
	else:
		return(user_channel + " is not streaming at the moment FeelsBadMan")

def localtime():

	local_time = timezone('US/Eastern')
	time = datetime.now(local_time)
	time_format = time.strftime('%H:%M:%S')
	time_format_str = "Local time: " + str(time_format) + " EST"
	return(time_format_str)<commit_msg>Negative point values correctly displaying now<commit_after>import string
import json
import urllib.request
import requests
import pymysql
import re
import random

from pytz import timezone
from datetime import datetime, timedelta, date, time
from Settings import CHANNEL, connection
from TheSocket import openSocket, sendMessage

def getUser(line):

	separate = line.split(":", 2)
	user = separate[1].split("!", 1)[0]
	return user

def getMessage(line):

	separate = line.split(":", 2)
	message = separate[2]
	return message

def get_points(check_user):

	check_db = connection.cursor()
	count = check_db.execute("SELECT COUNT(*) FROM table1")
	#print(count) # prints no. of rows
	check_db.execute("SELECT user_id from table1")
	data = check_db.fetchall() 
	#print(data) # print user_id rows

	for x in range(0, count + 1):

		if data[x] != str(check_user):

			check_db.execute("INSERT ignore into table1 VALUES ( '" + check_user + "', " + str(0) + " )")
			check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")
			points = check_db.fetchone()
			#print(points)

			format_points = re.findall('[+-]?\d+(?:\.\d+)?', str(points))
			#print(format_points)

			result_points = (check_user + " has " + format_points[0] + " points")

			if(int(format_points[0]) < 0):
				print(int(format_points[0]))
				negative_checkpoints = (check_user + " has -" + format_points[0] + " points BabyRage")
				return(str(negative_checkpoints))		

			return(str(result_points))
 
		if data[x] == str(check_user):

			check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")
			return_points = check_db.fetchone()

			format_checkpoints = re.findall('\d+', str(return_points))
			result_checkpoints = (check_user + " has " + format_points[0] + " points")
			return(str(result_checkpoints))

	connection.close()

def add_points():

	pointnum = 16 # 4 points per minute
	check_db = connection.cursor()
	check_db.execute("UPDATE table1 set points = points + " + str(pointnum))

def roulette(check_user, gamble):

	check_db = connection.cursor()

	int_gamble = int(re.search(r'\d+', gamble).group())
	#print(int_gamble)

	result = int_gamble * 2
	#print(result)

	roll = random.randrange(1, 3)
	if(roll == 1):
		check_db.execute("UPDATE table1 set points = points + " + str(result) + " where user_id = '" + str(check_user) + "' ")
		#return(check_user + " gambled " + str(int_gamble) + " points and won " + str(result) + " points! PogChamp")
		return(check_user + " won " + str(result) + " points! PogChamp")
	if(roll == 2):
		check_db.execute("UPDATE table1 set points = points - " + str(result) + " where user_id = '" + str(check_user) + "' and points > 0")
		#return(check_user + " gambled " + str(int_gamble) + " points and lost " + str(result) + " points! BibleThump")
		return(check_user + " lost " + str(result) + " points! BibleThump")

	#ADD POINTS
	#UPDATE table1 set points = points + 10 where user_id = 'kritzware';


	# for x in data:
	# 	if check_user not in data:
	# 		print("user not found, adding to database")
	# 		check_db.execute("INSERT into table1 VALUES ( '" + check_user + "', " + str(0) + " )")
	# 		check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")
			
	# 		new_points = check_db.fetchone()
	# 		strnew_points = str(new_points)

	# 		format_newpoints = re.findall('\d+', strnew_points)
	# 		new_result = (check_user + " has " + format_newpoints[0] + " points")
	# 		return(strnew_points)

	# else:
	# 	check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")

	# 	points = check_db.fetchall()
	# 	strpoints = str(points)
	
	# 	formatp = re.findall('\d+', strpoints)
	# 	result = (check_user + " has " + formatp[0] + " points")
	# 	return(result)

	# result = check_user + " has {} " + " points".format(points[0:3])
	# print(result)
	# return(str(result))

	# if check_user in check_db.fetchall():
	# 	points = check_db.execute("SELECT points from table1 where user_id = '" + check_user + "'")
	# 	print("user points found")
	# 	return check_user + " has" + points + " points"
	# else:
	# 	check_db.execute("INSERT into table1 VALUES ( '" + check_user + "', " + str(0) + " )")
	# 	print("adding new user to db")
	# 	return check_user + " has 0 points FeelsBadMan"
 
	


def uptime():

	user_channel = CHANNEL
	url = 'https://api.twitch.tv/kraken/channels/' + user_channel + '/videos?limit=1&broadcasts=true'
	req = urllib.request.urlopen(url)
	data = json.loads(req.read().decode('UTF-8'))
	latestbroadcast = data['videos'][0]['recorded_at']
	online = True

	#print("Broadcast start: " + latestbroadcast)

	timeformat = "%Y-%m-%dT%H:%M:%SZ"
	startdate = datetime.strptime(latestbroadcast, timeformat)
	currentdate = datetime.utcnow()
	combineddate = currentdate - startdate - timedelta(microseconds=currentdate.microsecond)

	check_request = urllib.request.urlopen('https://api.twitch.tv/kraken/streams/' + user_channel)
	check_online = json.loads(check_request.read().decode('UTF-8'))
	if(check_online['stream'] == None):
		online = False

	hours = str(combineddate)[:1]
	minutes = str(combineddate)[2:4]

	if(online):
		#print(combineddate)
		return(user_channel + " has been live for " + hours + " hrs, " + minutes + " mins")
	else:
		return(user_channel + " is not streaming at the moment FeelsBadMan")

def localtime():

	local_time = timezone('US/Eastern')
	time = datetime.now(local_time)
	time_format = time.strftime('%H:%M:%S')
	time_format_str = "Local time: " + str(time_format) + " EST"
	return(time_format_str)
{'fraction_non_alphanumeric': 0.15409219190968956, 'fraction_numerical': 0.009689557855126998, 'mean_word_length': 4.399187404773997, 'pattern_counts': {'":': 4, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 4, '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': '384072', 'n_tokens_mistral': 4014, 'n_tokens_neox': 3762, 'n_words': 829}