Exemple #1
0
def update_event(old_data, new_data):
	try:
		id_competition = queries.fetch("competitions", ["id"], "name='%s'" % old_data['tournament_part'])[0][0]
		id_team1 = queries.fetch("teams", ["id"], "name='%s'" % old_data["home"])[0][0]
		id_team2 = queries.fetch("teams", ["id"], "name='%s'" % old_data["away"])[0][0]

		if ":" and " " in old_data['time']:
			old_data['time'] = old_data['time'].split(" ")[0]+str(datetime.datetime.now().year)

		time = datetime.datetime.strptime(old_data['time'], "%d.%m.%Y")

		event = queries.fetch("events", ["id"], "time_started='{}' and id_team1={} and id_team2={} and id_competition='{}'".format(old_data['time'], id_team1, id_team2, id_competition))

		time = str(time).split(" ")[0]
		if data['statistics']:
			update_statistics(old_data['home'], old_data['away'], old_data['time'], old_data['statistics'])
		if data['summary']:
			update_summary(old_data['home'], old_data['away'], old_data['time'], old_data['summary'])

		if event:
			queries.update("events", new_data, "id = '{}'".format(event[0][0]))
			print("Success updating event - time - teams " + str(time) + " - " + str(old_data['home']) + " - " + str(old_data['away']), "\n")
		else:
			pass
			print("Cant find Event to update")

	except Exception as e:
		print("\nGRESKA - event update - ",  e, "\n")
Exemple #2
0
def insert_standings(standings):
	try:
		id_competition = queries.fetch("competitions", ["id"], "name='%s'" % standings['league_name'])[0][0]
		id_team = queries.fetch("teams", ["id"], "name='%s'" % standings['team'])[0][0]

		data = {}

		data['id_competition'] = str(id_competition)
		data['id_team'] = str(id_team)

		data['win'] = str(standings['wins'])
		data['lost'] = str(standings['losses'])
		data['draw'] = str(standings['draws'])
		data['goals'] = str(standings['goals'])
		data['points'] = str(standings['points'])
		data['year'] = str(standings['year'])

		id = queries.fetch("standings", ["id"], "id_competition='{}' and id_team='{}' and year='{}' ".format(data['id_competition'],data['id_team'], data['year']))

		if id:
			queries.update("standings", data, "id = '{}'".format(id[0][0]))
			print("Success update standings - competition - team " + standings['league_name'] + standings['team'], "\n")
		else:
			queries.save("standings", data)
			print("Success saving standings - competition - team " + standings['league_name'] + standings['team'], "\n")

	except Exception as e:
		print("GRESKA - insert_standings - ",  e, "\n")
Exemple #3
0
def insert_events(info):
	data = {}
	try:
		id_competition = queries.fetch("competitions", ["id"], "name='%s'" % info['tournament_part'])[0][0]
		id_team1 = queries.fetch("teams", ["id"], "name='%s'" % info['home'])[0][0]
		id_team2 = queries.fetch("teams", ["id"], "name='%s'" % info['away'])[0][0]

		data['id_competition'] = int(id_competition)
		data['id_team1'] = int(id_team1)
		data['id_team2'] = int(id_team2)

		data['score'] = str(info['score']).replace(" : ", ":")

		if ":" and " " in info["time"]:
			info['time'] = info['time'].split(" ")[0]+str(datetime.datetime.now().year)

		data['time_started'] = datetime.datetime.strptime(info['time'], "%d.%m.%Y")

		event = queries.fetch("events", ["id"], "time_started='{}' and id_team1={} and id_team2={} and id_competition={}".format(data['time_started'],data['id_team1'],data['id_team2'], data['id_competition']))

		if not event:
			data['id_statistics'] = insert_statistics(info['statistics'])[0]
			data['id_summary'] = insert_summary(info['summary'])[0]

			queries.save("events", data)
			print("Success saving event - time - teams " + str(data['time_started']) + " - " + str(data['id_team1']) + " - " + str(data['id_team2']), "\n")
		else:
			pass
			print("@@@@@@@Event already exists - time - teams " + str(data['time_started']) + " - " + str(data['id_team1']) + " - " + str(data['id_team2']), "\n")
	except Exception as e:
		print("\nGRESKA - insert_events - ",  e, info['home'],info['away'],data, "\n")
Exemple #4
0
def insert_competitions(competition_organiser, competition):
	try:
		id_competition_organiser = queries.fetch("competition_organisers", ["id"], "name='%s'" % competition_organiser)[0][0]

		competition_id = queries.fetch("competitions", ["id"], "name='{}' and id_competition_organiser='{}'".format(competition, id_competition_organiser))

		if not competition_id:
			queries.save("competitions", {"id_competition_organiser": id_competition_organiser, "name": competition})
			print("Success saving competition " + competition, "\n")
		else:
			pass
			# print("competition alewady exists")

	except Exception as e:
		print("\nGRESKA - insert_competitions - ",  e, "\n")
Exemple #5
0
def insert_teams(country, team):
	try:
		id_country = queries.fetch("countries", ["id"], "name='%s'" % country)[0][0]

		team_id = queries.fetch("teams", ["id"], "name='{}' and id_country='{}'".format(team, id_country))

		if not team_id:
			queries.save("teams", {"id_country": id_country, "name": team})
			print("Success saving team " + team, "\n")
		else:
			pass
			# print("Team alewady exists")


	except Exception as e:
		print("\nGRESKA - insert_teams - ",  e, country, team, "\n")
Exemple #6
0
def update_summary(team1, team2, time, summary_data):
	try:
		id_team1 = queries.fetch("teams", ["id"], "name='%s'" % team1)[0][0]
		id_team2 = queries.fetch("teams", ["id"], "name='%s'" % team2)[0][0]

		if ":" and " " in time:
			time = time.split(" ")[0]+str(datetime.datetime.now().year)
		time = datetime.datetime.strptime(time, "%Y-%m-%d")

		event_id = queries.fetch("events", ["id"], "time_started='{}' and id_team1='{}' and id_team2='{}'".format(time, id_team1, id_team2))[0][0]

		summary={}
		for i in summary_data:
			summary["{}".format(i.lower().replace(" ", "_"))] = json.dumps(summary_data[i]).replace('"','\\"')

		queries.update("summary", summary, "id = '{}'".format(event_id))
		print("Success updating summary " + str(summary), "\n")

	except Exception as e:
		print("\nGRESKA - summary update - ",  e, "\n")
Exemple #7
0
def insert_countries(country):
	try:
		country_id = queries.fetch("countries", ["id"], "name='%s'" % country)

		if not country_id:
			queries.save("countries", {"name": country})
			print("Success saving country " + country, "\n")
		else:
			pass
			# print("Country alewady exists")

	except Exception as e:
		print("\nGRESKA - insert_countries - ",  e, "\n")
Exemple #8
0
def insert_types(competition_type):
	try:
		competition_type_id = queries.fetch("competition_types", ["id"], "name='%s'" % competition_type)

		if not competition_type_id:
			queries.save("competition_types", {"name": competition_type})
			print("Success saving competition_type " + competition_type, "\n")
		else:
			pass
			# print("Competition type alewady exists")

	except Exception as e:
		print("\nGRESKA - insert_types - ",  e, "\n")
Exemple #9
0
def update_statistics(team1, team2, time, statistics_data):
	try:
		id_team1 = queries.fetch("teams", ["id"], "name='%s'" % team1)[0][0]
		id_team2 = queries.fetch("teams", ["id"], "name='%s'" % team2)[0][0]

		if ":" and " " in time:
			time = time.split(" ")[0]+str(datetime.datetime.now().year)
		time = datetime.datetime.strptime(time, "%Y-%m-%d")

		event = queries.fetch("events", ["id"], "time_started='{}' and id_team1='{}' and id_team2='{}'".format(time, id_team1, id_team2))[0][0]

		statistics={}
		for i in statistics_data:
			if i.lower().replace(" ","_") in ["yellow_cards", "red_cards", "ball_possession", "shots_on_goal", "shots_off_goal", "corner_kicks", "free_kicks", "fouls", "offsides"]:
				statistics["team1_{}".format(i.lower().replace(" ", "_"))] = statistics_data[i]["team1"].replace("%", "")
				statistics["team2_{}".format(i.lower().replace(" ", "_"))] = statistics_data[i]["team2"].replace("%", "")

		queries.update("statistics", statistics, "id = '{}'".format(event))
		print("Success updating statistics " + str(statistics), "\n")

	except Exception as e:
		print("\nGRESKA - statistics update - ",  e, "\n")