Created
May 1, 2024 21:58
-
-
Save Serizao/9aac6e030b319e57449371d413dde483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"flag" | |
) | |
func main() { | |
// Ouvrir le fichier JSON source | |
file := flag.String("file", "", "Input file") | |
output := flag.String("output", "", "Output file") | |
prefix := flag.String("prefix", "", "Prefix") | |
flag.Parse() | |
inputFile, err := os.Open(*file) | |
if err != nil { | |
fmt.Println("Error opening file:", err) | |
return | |
} | |
defer inputFile.Close() | |
// Décoder le fichier JSON dans une structure dynamique | |
var results []map[string]interface{} | |
decoder := json.NewDecoder(inputFile) | |
if err := decoder.Decode(&results); err != nil { | |
fmt.Println("Error decoding JSON:", err) | |
return | |
} | |
// Ajouter le préfixe aux noms des captures d'écran, en supposant une certaine structure | |
for i := range results { | |
if infos, ok := results[i]["infos"].(map[string]interface{}); ok { | |
if screenshotName, ok := infos["screenshot_name"].(string); ok { | |
infos["screenshot_name"] = *prefix + screenshotName | |
} | |
} | |
} | |
// Créer ou ouvrir le fichier de sortie | |
outputFile, err := os.Create(*output) | |
if err != nil { | |
fmt.Println("Error creating output file:", err) | |
return | |
} | |
defer outputFile.Close() | |
// Encoder les résultats modifiés en JSON minifié et les écrire dans le fichier de sortie | |
encoder := json.NewEncoder(outputFile) | |
if err := encoder.Encode(results); err != nil { | |
fmt.Println("Error encoding JSON:", err) | |
return | |
} | |
fmt.Println("File successfully modified and saved as 'modified_final_result.json'") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment