Skip to content
Permalink
Browse files

appliped PEP8, print json with minified version.

  • Loading branch information...
ho94949 committed Aug 15, 2019
1 parent 3720b36 commit f08c7bb8cfc54847e098bf811f19cc73e9ba9c6d
Showing with 61 additions and 7 deletions.
  1. +6 −0 .gitignore
  2. +6 −1 server-script/bmsparser.py
  3. +49 −6 server-script/loadbms.py
@@ -142,3 +142,9 @@ server-script/json/
server-script/new/
server-script/zip/

# server-script generated json

server-script/BMS2ZIP.json
server-script/BMS2ZIP.mini.json
server-script/ZIP2BMS.json
server-script/ZIP2BMS.mini.json
@@ -11,7 +11,12 @@ class UnknownEncodingError(Exception):

@classmethod
def AutoDecode(cls, raw):
EncodingList = ['shift-jis', 'cp932', 'shift_jisx0213', 'utf-8', 'cp949']
EncodingList = [
'shift-jis',
'cp932',
'shift_jisx0213',
'utf-8',
'cp949']
for e in EncodingList:
try:
ret = raw.decode(e)
@@ -77,10 +77,7 @@ def ExtractZIPData(zipName):
print('OK! [{0}] {1}'.format(zipJSON['artist'], zipJSON['title']))


def main():
"""Main Logic"""

# Generate default directories
def GenerateDefaultDir():
for dirname in [
ZIP_FOLDER_NAME,
EXTRACT_FOLDER_NAME,
@@ -92,16 +89,62 @@ def main():
else:
os.mkdir(dirname)

for fileName in os.listdir(NEW_FOLDER_NAME):

def LoadNewBMS():
for fileName in os.listdir(NEW_FOLDER_NAME):
fileName = os.path.join(NEW_FOLDER_NAME, fileName)

if IsZIPFile(fileName):
try:
ExtractZIPData(fileName)
except Exception:
traceback.print_exc()


def CreateJSON():

BMS2ZIP = {}
ZIP2BMS = {}

for fileName in os.listdir(JSON_FOLDER_NAME):
fileName = os.path.join(JSON_FOLDER_NAME, fileName)
with open(fileName, 'r') as f:
jsonData = json.loads(f.read())

zipCode = jsonData['code']
ZIP2BMS[zipCode] = jsonData

for bms in jsonData['bms']:
bmsHash = 'BMS_' + bms['md5']

if bmsHash not in BMS2ZIP:
BMS2ZIP[bmsHash] = []

BMS2ZIP[bmsHash].append(zipCode)

with open('BMS2ZIP.json', 'w') as f:
jstr = json.dumps(BMS2ZIP, sort_keys=True, indent=4)
f.write(jstr + '\n')

with open('BMS2ZIP.mini.json', 'w') as f:
jstr = json.dumps(BMS2ZIP, ensure_ascii=False, separators=(',', ':'))
f.write(jstr + '\n')

with open('ZIP2BMS.json', 'w') as f:
jstr = json.dumps(ZIP2BMS, sort_keys=True, indent=4)
f.write(jstr + '\n')

with open('ZIP2BMS.mini.json', 'w') as f:
jstr = json.dumps(ZIP2BMS, ensure_ascii=False, separators=(',', ':'))
f.write(jstr + '\n')


def main():
"""Main Logic"""

GenerateDefaultDir()
LoadNewBMS()
CreateJSON()


if __name__ == '__main__':
main()

0 comments on commit f08c7bb

Please sign in to comment.
You can’t perform that action at this time.