From 7f5bb9191c9e0106234d7d44dcd49580511a564d Mon Sep 17 00:00:00 2001 From: TheBidouilleur Date: Fri, 30 Oct 2020 11:29:17 +0100 Subject: [PATCH] Ajouter 'generate_config.py' --- generate_config.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 generate_config.py diff --git a/generate_config.py b/generate_config.py new file mode 100644 index 0000000..3f9d7ef --- /dev/null +++ b/generate_config.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +import json, os +from os import path +import sys + + + + + +def series(): + + if path.exists('watched_series.json') == False : + print("Le fichier watched_series.json n'existe pas") + else : + print("Le fichier watched_series.json existe.. On le supprime") + os.remove('watched_series.json') + series = sys.argv + series.pop(0) + + with open('watched_series.json', 'w') as json_file: + config = json.dump(series, json_file) + + print("Le fichier watched_series.json a bien été créé") + +def config(): + if len(sys.argv) != 7 : + print("Il n'y a pas le bon nombre d'argument") + sys.exit() + + client_id = sys.argv[2] + login = sys.argv[3] + password = sys.argv[4] + user_id = sys.argv[5] + token_bot = sys.argv[6] + + + if path.exists('user_config.json') == False : + print("Le fichier user_config.json n'existe pas") + else : + print("Le fichier user_config existe.. On le supprime") + os.remove('user_config.json') + + config = {"client_id" : client_id, + "login" : login, + "password" : password, + "user_id" : user_id, + "token_bot" : token_bot} + + print("Dictionnaire de la configuration", config) + + with open('user_config.json', 'w') as json_file: + config = json.dump(config, json_file) + + print("Le fichier user_config a bien été créé") + return + + +if len(sys.argv) == 1 : + print("Veuillez correctement lancer la commande ! \n") + print("Pour configurer le dictionnaire : python3 generate_config.py config CLIENT_ID LOGIN PASSWORD USER_ID TOKEN_BOT \n") + + print("Pour configurer les séries surveillées : python3 generate_config.py series THETVDB_ID1 THETVDB_ID2 THETVDB_ID3") + sys.exit() + +if sys.argv[1] == "config": + config() + sys.exit() +elif sys.argv[1] == "series" : + series() + sys.exit() +else : + print("Longueur de la liste : ", len(sys.argv)) + print("Veuillez correctement lancer la commande ! \n") + print("Pour configurer le dictionnaire : python3 generate_config.py config CLIENT_ID LOGIN PASSWORD USER_ID TOKEN_BOT \n") + + print("Pour configurer les séries surveillées : python3 generate_config.py series THETVDB_ID1 THETVDB_ID2 THETVDB_ID3")