25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.2 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json, os
  4. from os import path
  5. import sys
  6. def series():
  7. if path.exists('watched_series.json') == False :
  8. print("Le fichier watched_series.json n'existe pas")
  9. else :
  10. print("Le fichier watched_series.json existe.. On le supprime")
  11. os.remove('watched_series.json')
  12. series = sys.argv
  13. series.pop(0)
  14. with open('watched_series.json', 'w') as json_file:
  15. config = json.dump(series, json_file)
  16. print("Le fichier watched_series.json a bien été cree")
  17. def config():
  18. if len(sys.argv) != 7 :
  19. print("Il n'y a pas le bon nombre d'argument")
  20. sys.exit()
  21. client_id = sys.argv[2]
  22. login = sys.argv[3]
  23. password = sys.argv[4]
  24. user_id = sys.argv[5]
  25. token_bot = sys.argv[6]
  26. if path.exists('user_config.json') == False :
  27. print("Le fichier user_config.json n'existe pas")
  28. else :
  29. print("Le fichier user_config existe.. On le supprime")
  30. os.remove('user_config.json')
  31. config = {"client_id" : client_id,
  32. "login" : login,
  33. "password" : password,
  34. "user_id" : user_id,
  35. "token_bot" : token_bot}
  36. print("Dictionnaire de la configuration", config)
  37. with open('user_config.json', 'w') as json_file:
  38. config = json.dump(config, json_file)
  39. print("Le fichier user_config a bien ete cree")
  40. return
  41. if len(sys.argv) == 1 :
  42. print("Veuillez correctement lancer la commande ! \n")
  43. print("Pour configurer le dictionnaire : python3 generate_config.py config CLIENT_ID LOGIN PASSWORD USER_ID TOKEN_BOT \n")
  44. print("Pour configurer les series surveillees : python3 generate_config.py series THETVDB_ID1 THETVDB_ID2 THETVDB_ID3")
  45. sys.exit()
  46. if sys.argv[1] == "config":
  47. config()
  48. sys.exit()
  49. elif sys.argv[1] == "series" :
  50. series()
  51. sys.exit()
  52. else :
  53. print("Longueur de la liste : ", len(sys.argv))
  54. print("Veuillez correctement lancer la commande ! \n")
  55. print("Pour configurer le dictionnaire : python3 generate_config.py config CLIENT_ID LOGIN PASSWORD USER_ID TOKEN_BOT \n")
  56. print("Pour configurer les series surveillees : python3 generate_config.py series THETVDB_ID1 THETVDB_ID2 THETVDB_ID3")