Пример #1
0
def loadAdmins():
    adminsPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "admins")

    for line in adminsPage.splitlines():
        admins.add(line.lower())

    admins.add(globals.OWNER)
Пример #2
0
def loadTimes():
	timesPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "times")

	for timeLine in timesPage.splitlines():
		items = timeLine.split('|')
		if items[0] not in times:
			times[items[0]] = {}

		for item in items[1:]:
			timePart = item.split(",")
			if timePart[0] == "gain":
				if not validateItem(timePart[1], "-?\d+"):
					log.warning("Could not validate time yards: {}".format(timePart[1]))
					continue
				if not validateItem(timePart[2], "\d+"):
					log.warning("Could not validate time: {}".format(timePart[2]))
					continue

				if "gain" not in times[items[0]]:
					times[items[0]]["gain"] = []
				timeObject = {"yards": int(timePart[1]), "time": int(timePart[2])}
				times[items[0]][timePart[0]].append(timeObject)
			else:
				if not validateItem(timePart[1], "\d+"):
					log.warning("Could not validate time: {}".format(timePart[1]))
					continue

				timeObject = {"time": int(timePart[1])}
				times[items[0]][timePart[0]] = timeObject
Пример #3
0
def loadPlays():
	playsPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "plays")

	for playLine in playsPage.splitlines():
		items = playLine.split('|')
		isMovementPlay = items[0] in globals.movementPlays

		if isMovementPlay:
			startIndex = 4
			if not initOffenseDefense(items[0], items[1], items[2], items[3]):
				log.warning("Could not parse play: {}".format(playLine))
				continue
		else:
			startIndex = 2
			if not initRange(items[0], items[1]):
				log.warning("Could not parse play: {}".format(playLine))
				continue

		playParts = {}
		for item in items[startIndex:]:
			range, play = parsePlayPart(item)
			if play is None:
				continue
			playParts[range] = play

		if isMovementPlay:
			plays[items[0]][items[1]][items[2]][items[3]] = playParts
		else:
			plays[items[0]][items[1]] = playParts
Пример #4
0
def loadTeams():
    teamsPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "teams")
    for teamLine in teamsPage.splitlines():
        items = teamLine.split('|')
        if len(items) < 5:
            log.warning("Could not parse team line: {}".format(teamLine))
            continue
        team = {
            'tag': items[0],
            'name': items[1],
            'offense': items[2].lower(),
            'defense': items[3].lower(),
            'coaches': []
        }
        requirements = {
            'tag': "[a-z]+",
            'name': "[\w -]+",
            'offense': "(attack the rim|midrange|3 point)",
            'defense': "(man|zone|press)",
        }
        for requirement in requirements:
            if not validateItem(team[requirement], requirements[requirement]):
                log.debug("Could not validate team on {}: {}".format(
                    requirement, team))
                continue

        for coach in items[4].lower().split(','):
            coach = coach.strip()
            team['coaches'].append(coach)
            coaches[coach] = team
        teams[team['tag']] = team
Пример #5
0
def loadTeams():
    global teams
    teams = {}
    teamsPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "teams")

    requirements = {
        'tag': "[a-z]+",
        'name': "[\w -]+",
    }
    for teamLine in teamsPage.splitlines():
        items = teamLine.split('|')
        if len(items) < 5:
            log.warning("Could not parse team line: {}".format(teamLine))
            continue

        offense = parseOffense(items[2].lower())
        if offense is None:
            log.warning("Invalid offense type for team {}: {}".format(
                items[0], items[2]))
            continue

        defense = parseDefense(items[3].lower())
        if defense is None:
            log.warning("Invalid defense type for team {}: {}".format(
                items[0], items[2]))
            continue

        team = Team(tag=items[0],
                    name=items[1],
                    offense=offense,
                    defense=defense)

        for requirement in requirements:
            if not validateItem(getattr(team, requirement),
                                requirements[requirement]):
                log.debug("Could not validate team on {}: {}".format(
                    requirement, team))
                continue

        for coach in items[4].lower().split(','):
            coach = coach.strip()
            team.coaches.append(coach)
        teams[team.tag] = team

    coach1 = "watchful1"
    team1 = Team(tag="team1",
                 name="Team 1",
                 offense=OffenseType.OPTION,
                 defense=DefenseType.THREE_FOUR)
    team1.coaches.append(coach1)
    teams[team1.tag] = team1

    coach2 = "watchful12"
    team2 = Team(tag="team2",
                 name="Team 2",
                 offense=OffenseType.SPREAD,
                 defense=DefenseType.FOUR_THREE)
    team2.coaches.append(coach2)
    teams[team2.tag] = team2
Пример #6
0
def loadAdmins():
    global admins
    adminsPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "admins")

    for line in adminsPage.splitlines():
        admins.add(line.lower())

    admins.add(globals.OWNER)
    log.debug('admins are now {}'.format(admins))
Пример #7
0
def loadTimes():
    global times
    times = {}
    timesPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "times")

    for timeLine in timesPage.splitlines():
        items = timeLine.split('|')

        playType = parsePlay(items[0])
        if playType is None:
            log.warning("Could not parse play: {}".format(timeLine))
            continue

        if playType not in times:
            times[playType] = {}

        for item in items[1:]:
            timePart = item.split(",")

            result = parseResult(timePart[0])
            if result is None:
                log.warning("Could not validate result in times: {}".format(
                    timePart[1]))
                continue

            if result in [Result.GAIN, Result.KICK]:
                if not validateItem(timePart[1], "-?\d+"):
                    log.warning("Could not validate time yards: {}".format(
                        timePart[1]))
                    continue
                if not validateItem(timePart[2], "\d+"):
                    log.warning("Could not validate time: {}".format(
                        timePart[2]))
                    continue

                if result not in times[playType]:
                    times[playType][result] = []
                timeObject = {
                    'yards': int(timePart[1]),
                    'time': int(timePart[2])
                }
                times[playType][result].append(timeObject)
            else:
                if not validateItem(timePart[1], "\d+"):
                    log.warning("Could not validate time: {}".format(
                        timePart[1]))
                    continue

                timeObject = {'time': int(timePart[1])}
                times[playType][result] = timeObject
Пример #8
0
def loadPlays():
    global plays
    plays = {}
    playsPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "plays")

    for playLine in playsPage.splitlines():
        items = playLine.split('|')

        playType = parsePlay(items[0])
        if playType is None:
            log.warning("Could not parse play: {}".format(playLine))
            continue

        isMovementPlay = playType in [Play.RUN, Play.PASS]

        offense = None
        defense = None
        if isMovementPlay:
            startIndex = 4

            offense = parseOffense(items[1])
            if offense is None:
                log.warning("Bad offense item: {}".format(items[1]))
                continue

            defense = parseDefense(items[2])
            if defense is None:
                log.warning("Bad defense item: {}".format(items[2]))
                continue

            if not initOffenseDefense(playType, offense, defense, items[3]):
                log.warning("Could not parse play: {}".format(playLine))
                continue
        else:
            startIndex = 2
            if not initRange(playType, items[1]):
                log.warning("Could not parse play: {}".format(playLine))
                continue

        playParts = {}
        for item in items[startIndex:]:
            range, play = parsePlayPart(item)
            if play is None:
                continue
            playParts[range] = play

        if isMovementPlay:
            plays[playType][offense][defense][items[3]] = playParts
        else:
            plays[playType][items[1]] = playParts
Пример #9
0
def loadTeams():
	teamsPage = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "teams")

	for teamLine in teamsPage.splitlines():
		items = teamLine.split('|')
		if len(items) < 5:
			log.warning("Could not parse team line: {}".format(teamLine))
			continue
		team = {'tag': items[0], 'name': items[1], 'offense': items[2].lower(), 'defense': items[3].lower(),
		        'coaches': []}
		for coach in items[4].lower().split(','):
			coach = coach.strip()
			team['coaches'].append(coach)
			coaches[coach] = team
		teams[team['tag']] = team
Пример #10
0
def loadIntro():
    global intro
    intro = reddit.getWikiPage(globals.CONFIG_SUBREDDIT, "intro")