Compare commits
No commits in common. "a2dd6a03b8a80dc1c1991bd7f48b7ac561d61a12" and "494865bbab78e772e842c5d388f3346829964b74" have entirely different histories.
a2dd6a03b8
...
494865bbab
56
main.py
56
main.py
@ -44,21 +44,6 @@ _ch.setFormatter(LogFormatter())
|
||||
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):
|
||||
def get(self, index, default=None):
|
||||
try:
|
||||
@ -148,7 +133,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT DO NOTHING
|
||||
""",
|
||||
(game, turn, team(player), move, user, target),
|
||||
(game, turn, player, move, user, target),
|
||||
)
|
||||
case ["switch", name, specie, *rest]:
|
||||
player, name = resolve_mon(name)
|
||||
@ -158,7 +143,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT DO NOTHING
|
||||
""",
|
||||
(game, turn, team(player), name),
|
||||
(game, turn, player, name),
|
||||
)
|
||||
conn.execute(
|
||||
"""
|
||||
@ -166,7 +151,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
|
||||
VALUES(?, ?, ?, ?)
|
||||
ON CONFLICT DO NOTHING
|
||||
""",
|
||||
(game, team(player), name, specie.split(", ")[0]),
|
||||
(game, player, name, specie.split(", ")[0]),
|
||||
)
|
||||
case ["faint", mon]:
|
||||
player, mon = resolve_mon(mon)
|
||||
@ -176,7 +161,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
|
||||
VALUES(?, ?, ?, ?)
|
||||
ON CONFLICT DO NOTHING
|
||||
""",
|
||||
(game, turn, team(player), mon),
|
||||
(game, turn, player, mon),
|
||||
)
|
||||
case ["win", player]:
|
||||
conn.execute(
|
||||
@ -185,7 +170,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
|
||||
SET winner = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(team(player), game),
|
||||
(player, game),
|
||||
)
|
||||
case ["-sidestart", side, env]:
|
||||
if not last_move:
|
||||
@ -238,15 +223,7 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT DO NOTHING
|
||||
""",
|
||||
(
|
||||
game,
|
||||
turn,
|
||||
team(player),
|
||||
mon,
|
||||
source,
|
||||
source_user,
|
||||
team(source_player),
|
||||
),
|
||||
(game, turn, player, mon, source, source_user, source_player),
|
||||
)
|
||||
case _:
|
||||
# LOG.debug(f"unhandled message {chunks[0]}")
|
||||
@ -304,14 +281,6 @@ def main(args):
|
||||
action="store_true",
|
||||
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(
|
||||
"-o",
|
||||
"--output",
|
||||
@ -328,11 +297,6 @@ def main(args):
|
||||
elif args.verbose:
|
||||
LOG.setLevel(logging.DEBUG)
|
||||
|
||||
if args.teams:
|
||||
with open(args.teams) as f:
|
||||
global TEAMS
|
||||
TEAMS = json.load(f)
|
||||
|
||||
try:
|
||||
db = sqlite3.connect(args.output)
|
||||
_init_db(db)
|
||||
@ -351,13 +315,7 @@ def main(args):
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
ON CONFLICT DO NOTHING
|
||||
""",
|
||||
(
|
||||
replay.id,
|
||||
team(replay.p1),
|
||||
team(replay.p2),
|
||||
replay.format,
|
||||
replay.uploadtime,
|
||||
),
|
||||
(replay.id, replay.p1, replay.p2, replay.format, replay.uploadtime),
|
||||
)
|
||||
|
||||
parse_log(replay.id, replay.log, into=db)
|
||||
|
14
teams.json
14
teams.json
@ -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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user