| @@ -7,10 +7,9 @@ import logging | |||
| import requests | |||
| import json | |||
| from config import config | |||
| import os.path | |||
| import os | |||
| from os import path | |||
| from telegram_api import send_message | |||
| client_id = config['client_id'] | |||
| login = config['login'] | |||
| password = config['password'] | |||
| @@ -68,21 +67,57 @@ def check_latest(thetvdb_id): | |||
| "season " : episode['season'], | |||
| "episode" : episode['episode'] | |||
| } | |||
| #On choisi créé l'emplacement du fichier. On utilisera l'id thetvdb car utiliser le nom de la série risquerait des fichiers trop long | |||
| file_path = '' | |||
| file_path = 'latest/' + thetvdb_id + '.json' | |||
| print("Path a essayer : ", file_path) | |||
| # Si le fichier n'existe pas. Nous n'avons rien à comparer : Par définition nous sauvegardons les informations. | |||
| if path.exists(file_path) == False : | |||
| print("Fichier inexistant.. creation en cours...") | |||
| with open(file_path, "w") as write_file: | |||
| json.dump(episode_info, write_file) | |||
| else : | |||
| print("Fichier deja existant... On compare") | |||
| # Si le fichier existe. Nous comparons les informations reçues de l'API avec celles du fichier | |||
| else : | |||
| print("Fichier deja existant... On compare") | |||
| with open(file_path) as json_file: | |||
| data = json.load(json_file) | |||
| title = episode_info['serie_title'] | |||
| latest_season = int(episode_info['season ']) | |||
| latest_episode = int(episode_info['episode']) | |||
| saved_season = int(data['season ']) | |||
| saved_episode = int(data['episode']) | |||
| print("------------- Comparaison des 2 versions -----------------") | |||
| if latest_season > saved_season : | |||
| print("Latest saison + recente") | |||
| os.remove(file_path) | |||
| message = 'Nouvel episode de ' + title + ' ! ' + 'S' + str(latest_season) + 'E' + str(latest_episode) | |||
| send_message(message) | |||
| #On supprime le fichier, et on le ré-écris avec les nouvelles informations. | |||
| os.remove(file_path) | |||
| return | |||
| if latest_season == saved_season: | |||
| if latest_episode > saved_episode: | |||
| print("episode + recent") | |||
| message = 'Nouvel episode de ' + title + ' ! ' + 'S' + str(latest_season) + 'E' + str(latest_episode) | |||
| send_message(message) | |||
| os.remove(file_path) | |||
| return | |||
| print("Aucun changement") | |||