Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

generate_config.py 2.2 KiB

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