update formatting
This commit is contained in:
28
materials.py
28
materials.py
@@ -20,10 +20,10 @@ VERSION = """\
|
|||||||
EPILOG = """\
|
EPILOG = """\
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
def list_files():
|
||||||
|
"""\
|
||||||
|
List all materials
|
||||||
def list():
|
"""
|
||||||
from os import listdir
|
from os import listdir
|
||||||
|
|
||||||
for data in listdir("./data"):
|
for data in listdir("./data"):
|
||||||
@@ -31,24 +31,29 @@ def list():
|
|||||||
if file_name != "INFO":
|
if file_name != "INFO":
|
||||||
print(file_name)
|
print(file_name)
|
||||||
|
|
||||||
|
def read(input_file, search_keys=None):
|
||||||
def read(input, search_keys=None):
|
"""\
|
||||||
|
Read json file
|
||||||
|
"""
|
||||||
|
import os
|
||||||
import json
|
import json
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
def find_values(id, json_repr):
|
def find_values(key, json_repr):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
def _decode_dict(a_dict):
|
def _decode_dict(a_dict):
|
||||||
try: results.append(a_dict[id])
|
try:
|
||||||
except KeyError: pass
|
results.append(a_dict[key])
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
return a_dict
|
return a_dict
|
||||||
|
|
||||||
json.loads(json_repr, object_hook=_decode_dict) # return value ignored
|
json.loads(json_repr, object_hook=_decode_dict) # return value ignored
|
||||||
return results
|
return results
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(os.path.join('data', input + '.json')) as data_file:
|
with open(os.path.join('data', input_file + '.json')) as data_file:
|
||||||
if search_keys is not None:
|
if search_keys is not None:
|
||||||
data = data_file.read()
|
data = data_file.read()
|
||||||
for search_key in search_keys:
|
for search_key in search_keys:
|
||||||
@@ -76,7 +81,6 @@ def read(input, search_keys=None):
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""\
|
"""\
|
||||||
Main function
|
Main function
|
||||||
@@ -117,7 +121,7 @@ def main():
|
|||||||
print(args)
|
print(args)
|
||||||
|
|
||||||
if args.command == 'list':
|
if args.command == 'list':
|
||||||
list()
|
list_files()
|
||||||
|
|
||||||
elif args.command == 'material':
|
elif args.command == 'material':
|
||||||
if args.const_collection:
|
if args.const_collection:
|
||||||
|
|||||||
Reference in New Issue
Block a user