| @@ -6,7 +6,7 @@ | |||||
| import logging | import logging | ||||
| import requests | import requests | ||||
| import json | import json | ||||
| from config import config | |||||
| from config import config, series | |||||
| import os | import os | ||||
| # import time | # import time | ||||
| from os import path | from os import path | ||||
| @@ -40,16 +40,16 @@ def create_api(choice, thetvdb_id): | |||||
| if choice == 'latest' : | if choice == 'latest' : | ||||
| base_url = 'https://api.betaseries.com/episodes/latest?' | base_url = 'https://api.betaseries.com/episodes/latest?' | ||||
| API = base_url + 'token=' + token + '&client_id=' + client_id + '&thetvdb_id=' + thetvdb_id | |||||
| return API | |||||
| API_latest = base_url + 'token=' + token + '&client_id=' + str(client_id) + '&thetvdb_id=' + thetvdb_id | |||||
| return API_latest | |||||
| if choice == 'info' : | if choice == 'info' : | ||||
| base_url = 'https://api.betaseries.com/shows/display?' | base_url = 'https://api.betaseries.com/shows/display?' | ||||
| API = base_url + 'token=' + token + '&client_id=' + client_id + '&thetvdb_id=' + thetvdb_id | |||||
| return API | |||||
| API_info = base_url + 'token=' + token + '&client_id=' + str(client_id) + '&thetvdb_id=' + str(thetvdb_id) | |||||
| return API_info | |||||
| if choice == 'seen': | if choice == 'seen': | ||||
| base_url = 'https://api.betaseries.com/episodes/watched?' | base_url = 'https://api.betaseries.com/episodes/watched?' | ||||
| API = base_url + 'token=' + token + '&client_id=' + client_id + '&id=' | |||||
| return API | |||||
| API_seen = base_url + 'token=' + token + '&client_id=' + str(client_id) + '&id=' | |||||
| return API_seen | |||||
| return False | return False | ||||
| @@ -61,7 +61,6 @@ def check_latest(thetvdb_id): | |||||
| return | return | ||||
| request = requests.get(API) | request = requests.get(API) | ||||
| if str(request) != '<Response [200]>' : | if str(request) != '<Response [200]>' : | ||||
| print("Mauvaise réponse de l'api !(Check_Latest) ") | print("Mauvaise réponse de l'api !(Check_Latest) ") | ||||
| return False | return False | ||||
| @@ -124,6 +123,7 @@ def check_latest(thetvdb_id): | |||||
| return | return | ||||
| if data['seen'] == False : | if data['seen'] == False : | ||||
| print("Vous n'avez pas vu le dernier episode de cette series : ", get_title_only(thetvdb_id)) | |||||
| os.remove(file_path) | os.remove(file_path) | ||||
| create_file(file_path, episode_info) | create_file(file_path, episode_info) | ||||
| return | return | ||||
| @@ -155,14 +155,12 @@ def to_see(thetvdb_id): | |||||
| file_path = 'latest/' + thetvdb_id + '.json' | file_path = 'latest/' + thetvdb_id + '.json' | ||||
| with open(file_path) as json_file: | with open(file_path) as json_file: | ||||
| data = json.load(json_file) | data = json.load(json_file) | ||||
| print(data) | |||||
| if data[u'seen'] == False : | if data[u'seen'] == False : | ||||
| message = data['serie_title'] + ' ! ' + '\n' + 'Episode: ' + str(data['episode']) + ' Saison:' + str(data['season ']) + '\n' + '\n' | message = data['serie_title'] + ' ! ' + '\n' + 'Episode: ' + str(data['episode']) + ' Saison:' + str(data['season ']) + '\n' + '\n' | ||||
| return message | return message | ||||
| else : | |||||
| print(u"Vous etes à jour") | |||||
| return | |||||
| print(u"Vous etes à jour") | |||||
| return False | |||||
| def seen(thetvdb_id): | def seen(thetvdb_id): | ||||
| # Permet de mettre un episode en 'vu' sur betaseries | # Permet de mettre un episode en 'vu' sur betaseries | ||||
| @@ -178,13 +176,27 @@ def seen(thetvdb_id): | |||||
| API = create_api('seen', None) | API = create_api('seen', None) | ||||
| API += str(data['id']) | API += str(data['id']) | ||||
| print(API) | print(API) | ||||
| # request = requests.post(API) | |||||
| # if str(request) == '<Response [400]>' : | |||||
| # send_message(u"Impossible de marquer l'episode comme vu(déjà vu?)") | |||||
| # print(request) | |||||
| # return | |||||
| send_message('Done !') | |||||
| return | |||||
| def get_episode_code(thetvdb_id): | |||||
| file_path = 'latest/' + thetvdb_id + '.json' | |||||
| with open(file_path) as json_file: | |||||
| data = json.load(json_file) | |||||
| code = 'S' + str(data['season ']) + 'E' + str(data['episode']) | |||||
| return code | |||||
| def main(): | def main(): | ||||
| #Only here for debug git | #Only here for debug git | ||||
| login_beta() | |||||
| print(get_title_only('354198')) | |||||
| for i in range(len(series)): | |||||
| id = series[i] | |||||
| print(get_episode_code(id)) | |||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||