This commit is contained in:
aozhiwei 2018-11-06 16:56:33 +08:00
parent f86d455b60
commit fe9c58036c
3 changed files with 2000 additions and 9 deletions

1968
scripts/md_csv/dict.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
import os
import json
dict_file = open('/usr/share/nginx/html/gamelog/webapp/bootstrap/dict.php', 'w')
dict_file.write('<?php\n\n')
dict_file.write(' $log_dict = array(\n')
log_dict = json.loads(open('dict.json', 'r').read())
for key in log_dict['__keys__']:
dict_file.write(" \"%s\" => array(\n" % key)
node = log_dict[key]
for fieldname in node['__keys__']:
en_name = node[fieldname]['en_name']
dict_file.write(" \"%s\" => \"%s\",\n" % (fieldname, en_name))
dict_file.write(" ),\n")
dict_file.write(' );\n')

View File

@ -10,6 +10,7 @@ TOKEN_REGEX2 = r"""(?:\|\s*)([^\s]*)(?:\s*)(?:\|\s*)([^\s]*)(?:\s*)(?:\|\s*)([^\
def md2csv(mdfile):
state = 0
log_dict = {}
log_dict['__keys__'] = []
curr_node = None
for line in open(mdfile).readlines():
match = re.match(TOKEN_REGEX, line)
@ -18,23 +19,27 @@ def md2csv(mdfile):
state = 1
assert((logclass1 + '-' + logclass2) not in log_dict)
curr_node = {}
log_dict[logclass1 + '-' + logclass2] = curr_node
# print('')
# print(logclass1, logclass2, title)
curr_node['__keys__'] = []
log_key = logclass1 + '-' + logclass2
log_dict[log_key] = curr_node
log_dict['__keys__'].append(log_key)
continue
match2 = re.match(TOKEN_REGEX2, line)
if match2 and state == 1:
field1, field2, field3, field4 = match2.groups()
if field1[0] != '-' and field1 != '字段':
curr_node[field1.replace('\\', '')] = {
'short_name': field1.replace('\\', ''),
'en_name': field2.replace('\\', ''),
field_name = field1.replace('\\', '')
en_name = field2.replace('\\', '')
curr_node[field_name] = {
'short_name': field_name,
'en_name': en_name,
'desc': field4
}
curr_node[field2.replace('\\', '')] = curr_node[field1.replace('\\', '')]
# print(field1 + ',' + field2 + ',' + field3 + ',' + field4)
curr_node['__keys__'].append(field_name)
if not (en_name in curr_node):
curr_node['__keys__'].append(en_name)
curr_node[en_name] = curr_node[field_name]
#end for
# pprint.pprint(log_dict)
print(json.dumps(log_dict, sort_keys=True, indent=4, separators=(',', ': ')))
md2csv('/root/opensource/doc/api说明/gamelog.md')