Skip to content
Extraits de code Groupes Projets
Valider 54b3edca rédigé par Miryuni's avatar Miryuni
Parcourir les fichiers

Comments and cleaner code

parent fde13a50
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -2,8 +2,7 @@ import json ...@@ -2,8 +2,7 @@ import json
import sys import sys
from colorama import Fore, Back, Style from colorama import Fore, Back, Style
# Check the arguments # Pack is updated only if index and description are given
# Pack is updated only if index and description are precised
update = False update = False
if len(sys.argv) <= 1 or len(sys.argv) == 3: if len(sys.argv) <= 1 or len(sys.argv) == 3:
print("Usage : python updatePacks.py pack.json [sticker_index] [new_description]") print("Usage : python updatePacks.py pack.json [sticker_index] [new_description]")
...@@ -21,11 +20,14 @@ nb_stickers = len(json_pack['stickers']) ...@@ -21,11 +20,14 @@ nb_stickers = len(json_pack['stickers'])
if update == False: if update == False:
# Print the number of stickers in this pack # 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): for i in range(nb_stickers):
print("\t"+str(i+1) + ". " + json_pack['stickers'][i]['body']) 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'") print(Fore.CYAN +Style.BRIGHT + "python " +Style.RESET_ALL+ "updatePacks.py " + sys.argv[1] + Fore.RED + Style.BRIGHT+" sticker_index 'new_description'")
exit(0) exit(0)
...@@ -37,10 +39,14 @@ new_body = sys.argv[3] ...@@ -37,10 +39,14 @@ new_body = sys.argv[3]
# Change the body of the sticker_index # Change the body of the sticker_index
if sticker_index > nb_stickers: if sticker_index > nb_stickers:
print("Index out of range : "+ str(sticker_index) + " > "+str(nb_stickers)) print("Index out of range : "+ str(sticker_index) + " > "+str(nb_stickers))
exit(1)
elif sticker_index == 0: elif sticker_index == 0:
print("Index starts at 1") print("Index starts at 1")
exit(1)
else: else:
# Update the body of the sticker
json_pack['stickers'][sticker_index-1]['body'] = new_body json_pack['stickers'][sticker_index-1]['body'] = new_body
# Print the body of all the stickers # Print the body of all the stickers
print(Fore.GREEN + 'Updated!'+ Style.RESET_ALL) print(Fore.GREEN + 'Updated!'+ Style.RESET_ALL)
print("New sticker pack:") print("New sticker pack:")
...@@ -49,6 +55,8 @@ else: ...@@ -49,6 +55,8 @@ else:
print("\t "+Fore.GREEN+str(i+1) + ". " + json_pack['stickers'][i]['body']+Style.RESET_ALL) print("\t "+Fore.GREEN+str(i+1) + ". " + json_pack['stickers'][i]['body']+Style.RESET_ALL)
else: else:
print("\t "+str(i+1) + ". " + json_pack['stickers'][i]['body']) 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') out_file = open(sys.argv[1], 'w')
json.dump(json_pack, out_file, indent = 3) json.dump(json_pack, out_file, indent = 3)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter