Compare commits

..

No commits in common. "a2dd6a03b8a80dc1c1991bd7f48b7ac561d61a12" and "494865bbab78e772e842c5d388f3346829964b74" have entirely different histories.

2 changed files with 7 additions and 63 deletions

56
main.py
View File

@ -44,21 +44,6 @@ _ch.setFormatter(LogFormatter())
LOG.addHandler(_ch) LOG.addHandler(_ch)
TEAMS = {}
_logged_teams = []
def team(player: str) -> str:
"""Maps a username to a defined team."""
if player in TEAMS:
return TEAMS[player]
else:
if not player in _logged_teams:
LOG.warning(f"missing team mapping for {player}")
_logged_teams.append(player)
return player
class safelist(list): class safelist(list):
def get(self, index, default=None): def get(self, index, default=None):
try: try:
@ -148,7 +133,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
""", """,
(game, turn, team(player), move, user, target), (game, turn, player, move, user, target),
) )
case ["switch", name, specie, *rest]: case ["switch", name, specie, *rest]:
player, name = resolve_mon(name) player, name = resolve_mon(name)
@ -158,7 +143,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
""", """,
(game, turn, team(player), name), (game, turn, player, name),
) )
conn.execute( conn.execute(
""" """
@ -166,7 +151,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
VALUES(?, ?, ?, ?) VALUES(?, ?, ?, ?)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
""", """,
(game, team(player), name, specie.split(", ")[0]), (game, player, name, specie.split(", ")[0]),
) )
case ["faint", mon]: case ["faint", mon]:
player, mon = resolve_mon(mon) player, mon = resolve_mon(mon)
@ -176,7 +161,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
VALUES(?, ?, ?, ?) VALUES(?, ?, ?, ?)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
""", """,
(game, turn, team(player), mon), (game, turn, player, mon),
) )
case ["win", player]: case ["win", player]:
conn.execute( conn.execute(
@ -185,7 +170,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
SET winner = ? SET winner = ?
WHERE id = ? WHERE id = ?
""", """,
(team(player), game), (player, game),
) )
case ["-sidestart", side, env]: case ["-sidestart", side, env]:
if not last_move: if not last_move:
@ -238,15 +223,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
VALUES(?, ?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
""", """,
( (game, turn, player, mon, source, source_user, source_player),
game,
turn,
team(player),
mon,
source,
source_user,
team(source_player),
),
) )
case _: case _:
# LOG.debug(f"unhandled message {chunks[0]}") # LOG.debug(f"unhandled message {chunks[0]}")
@ -304,14 +281,6 @@ def main(args):
action="store_true", action="store_true",
help="fetch replays instead of using cache", help="fetch replays instead of using cache",
) )
parser.add_argument(
"-t",
"--teams",
action="store",
metavar="FILE",
default="teams.json",
help="JSON file defining players to teams",
)
parser.add_argument( parser.add_argument(
"-o", "-o",
"--output", "--output",
@ -328,11 +297,6 @@ def main(args):
elif args.verbose: elif args.verbose:
LOG.setLevel(logging.DEBUG) LOG.setLevel(logging.DEBUG)
if args.teams:
with open(args.teams) as f:
global TEAMS
TEAMS = json.load(f)
try: try:
db = sqlite3.connect(args.output) db = sqlite3.connect(args.output)
_init_db(db) _init_db(db)
@ -351,13 +315,7 @@ def main(args):
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
""", """,
( (replay.id, replay.p1, replay.p2, replay.format, replay.uploadtime),
replay.id,
team(replay.p1),
team(replay.p2),
replay.format,
replay.uploadtime,
),
) )
parse_log(replay.id, replay.log, into=db) parse_log(replay.id, replay.log, into=db)

View File

@ -1,14 +0,0 @@
{
"DogOfAnnoyance": "Raleigh County Revavrooms",
"FedeX23": "Buenos Aires Aggrons",
"InkFoxclaw": "Mew York",
"Inkfoxclaw": "Mew York",
"Lex101": "Scheveningen Slow Bros",
"Omega Cheyenne": "The Cheyenne Chimchars",
"Roromiya989": "San Francisco 549ers",
"YafamEm": "Emily's Eevees",
"in it for agency": "Barrow's Biggest Birds",
"phantomr23": "East Midland Milotics",
"treesgobark": "Nimbasa City Ninjasks",
"xeal is taken": "Canberra Mamoswines"
}