mc-transformer/transformer.py

55 lines
1.6 KiB
Python
Raw Permalink Normal View History

2017-06-10 20:02:08 +03:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# nimetön.py
#
# Copyright 2017 Jyri Eerola <je1@clr-f55255f3d66b4bfba1010f57f9384f00>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
import sys
import re
import json
#class bcolors:
# HEADER = '\033[95m'
# OKBLUE = '\033[94m'
# OKGREEN = '\033[92m'
# WARNING = '\033[93m'
# FAIL = '\033[91m'
# ENDC = '\033[0m'
# BOLD = '\033[1m'
# UNDERLINE = '\033[4m'
gamejoin = r"\[(?P<time>\d\d:\d\d:\d\d)\] \[Server thread\/INFO\]: (?P<player>\w+) (?P<verb>\w+) the game"
def main(source_id):
compiled = re.compile(gamejoin)
for line in sys.stdin:
print('\033[94m{}\033[0m'.format(line), file=sys.stderr, end='')
data = re.match(compiled, line)
if data:
gd = data.groupdict()
gd.update(source_id=source_id)
print(json.dumps(gd), flush=True)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1])) # olkoon argv[1] source_id