Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Wed Aug 8 14:00:23 2018
- @author: A670679
- """
- import mysql.connector
- tourney_name = ""
- tourney_tier = ""
- number_players = -1
- players = []
- matches = []
- cnx = None
- class player:
- def __init__(self,name,punt):
- self.name = name
- self.punt = punt
- def read_data():
- global tourney_name
- global tourney_tier
- global number_players
- global players
- global matches
- with open ("data_1.txt", "r") as myfile:
- data=myfile.readlines()
- tourney_name = data[0]
- tourney_tier = data[1]
- number_players = int(data[2])
- for i in range(4,4+number_players):
- spc = data[i].index(" ")
- players.append(player(data[i][:spc],data[i][spc+1:len(data[i])-1]))
- for i in range(4+number_players+1,len(data)):
- matches.append(data[i][:len(data[i])-1] + " " + tourney_tier)
- def db_connex():
- global cnx
- cnx = mysql.connector.connect(user='Kakarot', password='292Hikotsu',
- host='localhost',database='sys')
- def db_get_tourney():
- global cnx
- cursor = cnx.cursor()
- #Mejor hacer con where i ver si returna el torneo en cuestion
- query = ("SELECT TOURNEY_NAME FROM usr_dne")
- cursor.execute(query)
- found = False
- for tupla in cursor:
- if tupla[0] == tourney_name:
- found = True
- break
- if not found:
- query = "INSERT INTO usr_dne (TOURNEY_NAME) VALUES ('" + tourney_name + "')"
- cursor.execute(query)
- cnx.commit()
- return found
- def db_getplayers_nicknames():
- global cnx
- cursor = cnx.cursor()
- query = ("SELECT PLAYER_ID, NICKNAME FROM usr_gen")
- cursor.execute(query)
- player_db = []
- for tupla in cursor:
- player_db.append(tupla[1])
- last_id = tupla[0]
- return player_db, last_id
- def db_insertplayers(player_db,last_id):
- global cnx
- global players
- cursor = cnx.cursor()
- for player in players:
- if not(player.name in player_db):
- last_id += 1
- query = "INSERT INTO usr_gen (NICKNAME,PLAYER_ID) VALUES ('" + player.name + "'," + str(last_id) + ")"
- cursor.execute(query)
- cnx.commit()
- def Main():
- read_data()
- db_connex()
- exists = db_get_tourney()
- #should be not exists!!!!!!!!!!!!!!!!!!!!!!!
- if exists:
- player_db, last_id = db_getplayers_nicknames()
- db_insertplayers(player_db, last_id)
- cnx.close()
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement