Skip to content

Instantly share code, notes, and snippets.

@perymerdeka
Created September 3, 2021 09:50
Show Gist options
  • Select an option

  • Save perymerdeka/2320b76bbeb7e0630dcd7f4edbccd0b6 to your computer and use it in GitHub Desktop.

Select an option

Save perymerdeka/2320b76bbeb7e0630dcd7f4edbccd0b6 to your computer and use it in GitHub Desktop.
Command Line Application to Generate Assets PATH in flutter, build with python
import os
import json
#print(current_dir)
def generate_assets(assets_path: str, output_path: str, filename: str):
path_result: list = []
current_dir = os.path.dirname(os.path.abspath(__file__))
assets = os.path.join(current_dir, assets_path)
# writing assets json file
datas = os.listdir(assets)
for path in datas:
data_dict: dict = {
'filename': path,
'images': assets_path + path
}
#
path_result.append(data_dict)
# writing json file
output_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), output_path)
with open(f'{output_dir}{filename}.json', 'w+') as generated_json:
json.dump(path_result, generated_json)
print(f'Assets Generated Check on {output_dir} directory')
def main():
counter: str = 'y'
while counter == 'y':
print('++' * 10, ' Simple JSON Generator for Flutter Assets ', '++' * 10)
print()
print('1. Generate JSON Assets')
print('2. Quit')
choice: int = int(input('Input Your Choice: '))
if choice == 1:
assets_path: str = input('Input Your Assets Path: ')
output_path: str = input('Input your Output Dirextory: ')
filename: str = input('Input Result filename: ').replace(' ', '_')
generate_assets(assets_path=assets_path, output_path=output_path, filename=filename)
counter = 'n'
elif choice == 2:
print('Program Exited')
counter = 'n'
else:
print('Invalid Input')
counter = 'n'
if '__main__' == __name__:
# generate_assets('assets/images/', output_path='assets/json/', filename='wallpaper')
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment