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

Added a python script to update the description of stickers

parent ffa9a097
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
import json
import sys
# Check the arguments
# Pack is updated only if index and description are precised
update = False
if len(sys.argv) <= 1 or len(sys.argv) == 3:
print("Usage : python updatePack.py pack.json [sticker_index] [new_description]")
exit(1)
elif len(sys.argv) > 3:
update = True
# Read the pack file
with open(sys.argv[1],'r') as myfile:
stickerpack = myfile.read()
# Parse the pack
json_pack = json.loads(stickerpack)
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: ")
for i in range(nb_stickers):
print(str(i+1) + ". " + json_pack['stickers'][i]['body'])
print("To update one of them type:")
print("python updatePack.py " + sys.argv[1] + " sticker_index 'new_description'")
exit(0)
# Informations
sticker_index = int(sys.argv[2])
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))
elif sticker_index == 0:
print("Index starts at 1")
else:
json_pack['stickers'][sticker_index-1]['body'] = new_body
# Print the body of all the stickers
for i in range(nb_stickers):
print(str(i+1) + ". " + json_pack['stickers'][i]['body'])
out_file = open(sys.argv[1], 'w')
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.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter