diff --git a/updatePacks.py b/updatePacks.py index fe9bded92c301659b6d5a27e912b715788b15fbd..12dab54eee21a472ba1c292bb85bc2e11ec6be39 100644 --- a/updatePacks.py +++ b/updatePacks.py @@ -2,8 +2,7 @@ import json import sys from colorama import Fore, Back, Style -# Check the arguments -# Pack is updated only if index and description are precised +# Pack is updated only if index and description are given update = False if len(sys.argv) <= 1 or len(sys.argv) == 3: print("Usage : python updatePacks.py pack.json [sticker_index] [new_description]") @@ -21,11 +20,14 @@ nb_stickers = len(json_pack['stickers']) if update == False: + # Print the number of stickers in this pack - print("There are " +str(nb_stickers) + " stickers in this pack: ") + print("There are " + str(nb_stickers) + " stickers in this pack: ") for i in range(nb_stickers): print("\t"+str(i+1) + ". " + json_pack['stickers'][i]['body']) - print("To update one of them replace the red arguments:") + + # Print how to update the description of a sticker + print("To update a sticker, replace the arguments in red:") print(Fore.CYAN +Style.BRIGHT + "python " +Style.RESET_ALL+ "updatePacks.py " + sys.argv[1] + Fore.RED + Style.BRIGHT+" sticker_index 'new_description'") exit(0) @@ -37,10 +39,14 @@ new_body = sys.argv[3] # Change the body of the sticker_index if sticker_index > nb_stickers: print("Index out of range : "+ str(sticker_index) + " > "+str(nb_stickers)) + exit(1) elif sticker_index == 0: print("Index starts at 1") + exit(1) else: + # Update the body of the sticker json_pack['stickers'][sticker_index-1]['body'] = new_body + # Print the body of all the stickers print(Fore.GREEN + 'Updated!'+ Style.RESET_ALL) print("New sticker pack:") @@ -49,6 +55,8 @@ else: print("\t "+Fore.GREEN+str(i+1) + ". " + json_pack['stickers'][i]['body']+Style.RESET_ALL) else: print("\t "+str(i+1) + ". " + json_pack['stickers'][i]['body']) + + # Replace the old pack.json by the updated one out_file = open(sys.argv[1], 'w') json.dump(json_pack, out_file, indent = 3)