Exemple #1
0
def main():
    import argparse
    parser = argparse.ArgumentParser(description="Prints replay data to a json string.")
    parser.add_argument('--indent', '-i', type=int, default=None, help="The per-line indent to use when printing a human readable json string")
    parser.add_argument('--encoding', '-e', type=str, default='UTF-8', help="The character encoding use..")
    parser.add_argument('path', metavar='path', type=str, nargs=1, help="Path to the replay to serialize.")
    args = parser.parse_args()

    factory = sc2reader.factories.SC2Factory()
    factory.register_plugin("Replay", toJSON(encoding=args.encoding, indent=args.indent))
    replay_json = factory.load_replay(args.path[0])
    print(replay_json)
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Prints replay data to a json string.")
    parser.add_argument(
        "--indent",
        "-i",
        type=int,
        default=None,
        help=
        "The per-line indent to use when printing a human readable json string",
    )
    parser.add_argument(
        "--encoding",
        "-e",
        type=str,
        default="UTF-8",
        help="The character encoding use..",
    )
    parser.add_argument(
        "path",
        metavar="path",
        type=str,
        nargs=1,
        help="Path to the replay to serialize.",
    )
    args = parser.parse_args()

    factory = sc2reader.factories.SC2Factory()
    try:
        factory.register_plugin("Replay",
                                toJSON(encoding=args.encoding,
                                       indent=args.indent))  # legacy Python
    except TypeError:
        factory.register_plugin("Replay", toJSON(indent=args.indent))

    replay_json = factory.load_replay(args.path[0])
    print(replay_json)
Exemple #3
0
    def test_factory_plugins(self):
        from sc2reader.factories.plugins.replay import APMTracker, SelectionTracker, toJSON

        factory = sc2reader.factories.SC2Factory()
        factory.register_plugin("Replay", APMTracker())
        factory.register_plugin("Replay", SelectionTracker())
        factory.register_plugin("Replay", toJSON())
        replay = factory.load_replay("test_replays/2.0.5.25092/cn1.SC2Replay")

        # Load and quickly check the JSON output consistency
        result = json.loads(replay)
        self.assertEqual(result["map_name"], "生化实验区")
        self.assertEqual(result["players"][2]["name"], "ImYoonA")
        self.assertEqual(result["players"][2]["avg_apm"], 84.52332657200812)
        self.assertEqual(result["release"], "2.0.5.25092")
        self.assertEqual(result["game_length"], 986)
        self.assertEqual(result["real_length"], 704)
        self.assertEqual(result["gateway"], "cn")
        self.assertEqual(result["game_fps"], 16.0)
        self.assertTrue(result["is_ladder"])
Exemple #4
0
    def test_factory_plugins(self):
        from sc2reader.factories.plugins.replay import APMTracker, SelectionTracker, toJSON

        factory = sc2reader.factories.SC2Factory()
        factory.register_plugin("Replay", APMTracker())
        factory.register_plugin("Replay", SelectionTracker())
        factory.register_plugin("Replay", toJSON())
        replay = factory.load_replay("test_replays/2.0.5.25092/cn1.SC2Replay")

        # Load and quickly check the JSON output consistency
        result = json.loads(replay)
        self.assertEqual(result["map_name"], "生化实验区")
        self.assertEqual(result["players"][2]["name"], "ImYoonA")
        self.assertEqual(result["players"][2]["avg_apm"], 84.52332657200812)
        self.assertEqual(result["release"], "2.0.5.25092")
        self.assertEqual(result["game_length"], 986)
        self.assertEqual(result["real_length"], 704)
        self.assertEqual(result["region"], "cn")
        self.assertEqual(result["game_fps"], 16.0)
        self.assertTrue(result["is_ladder"])
Exemple #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals, division

import logging
import os
import argparse
import shutil
import SocketServer

# Set up sc2reader
import sc2reader
from sc2reader.factories.plugins.replay import toJSON
sc2reader.register_plugin("Replay", toJSON(encoding='UTF-8', indent=None))

# Set up logging
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(
    fmt='%(asctime)s - %(name)s [%(levelname)s] - %(message)s',
    datefmt='%Y%m%dT%H%M%S'
))
logger = logging.getLogger('sc2json')
logger.setLevel(logging.INFO)
logger.addHandler(handler)


# Create our socket server
class ReplayParser(SocketServer.StreamRequestHandler):
    def handle(self):
        path = self.rfile.readline().strip()
        logger.info("Parsing replay file: {}".format(path))