From 627220060eadd9c65d42c8a5720c9d93a4bb7cb4 Mon Sep 17 00:00:00 2001 From: administrator Date: Fri, 1 May 2020 00:59:48 +0200 Subject: [PATCH] modified: Correction probleme ID + Ajout de la fonction 'seen' modified: Ajout du keyboard visuel ! modified: Permet de faire la difference entre une liste complete et liste d'un seul element --- betaseries.py | 36 +++++++++++++++++++++++++++++------- bot.py | 32 +++++++++++++++++++------------- notification.py | 11 ++++++++--- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/betaseries.py b/betaseries.py index 487b0dd..bf991db 100644 --- a/betaseries.py +++ b/betaseries.py @@ -47,7 +47,9 @@ def create_api(choice, thetvdb_id): API = base_url + 'token=' + token + '&client_id=' + client_id + '&thetvdb_id=' + thetvdb_id return API if choice == 'seen': - base_url = 'https://api.betaseries.com/shows/display?' + base_url = 'https://api.betaseries.com/episodes/watched?' + API = base_url + 'token=' + token + '&client_id=' + client_id + '&id=' + return API return False @@ -59,8 +61,9 @@ def check_latest(thetvdb_id): return request = requests.get(API) + if str(request) != '' : - print("Mauvaise réponse de l'api ! ") + print("Mauvaise réponse de l'api !(Check_Latest) ") return False show = request.json() episode = show['episode'] @@ -77,7 +80,7 @@ def check_latest(thetvdb_id): "serie_title" : title['title'], "season " : episode['season'], "episode" : episode['episode'], - "id" : title['id'], + "id" : episode['id'], "seen" : user['seen'] } @@ -119,8 +122,10 @@ def check_latest(thetvdb_id): os.remove(file_path) create_file(file_path, episode_info) return - print("Aucun changement") - + + if data['seen'] == False : + os.remove(file_path) + create_file(file_path, episode_info) return def create_file(file_path, episode_info): @@ -136,7 +141,7 @@ def get_title_only(thetvdb_id): return request = requests.get(API) if str(request) != '' : - print("Mauvaise réponse de l'api ! ") + print("Mauvaise réponse de l'api ! (Get_title) ") return False info = request.json() @@ -146,7 +151,7 @@ def get_title_only(thetvdb_id): def to_see(thetvdb_id): - # Permet de dire qu'un episode est deja vu + # Permet de dire les episodes dejà vu A PARTIR des fichiers file_path = 'latest/' + thetvdb_id + '.json' with open(file_path) as json_file: data = json.load(json_file) @@ -159,6 +164,23 @@ def to_see(thetvdb_id): return +def seen(thetvdb_id): + # Permet de mettre un episode en 'vu' sur betaseries + print(u"Ajout d'un episode à la liste des vu") + file_path = 'latest/' + thetvdb_id + '.json' + + with open(file_path) as json_file: + data = json.load(json_file) + + if data['seen'] == True : + send_message('Episode deja vu') + return + API = create_api('seen', None) + API += str(data['id']) + print(API) + + + def main(): #Only here for debug git login_beta() diff --git a/bot.py b/bot.py index af59fde..2ae39e4 100644 --- a/bot.py +++ b/bot.py @@ -8,7 +8,7 @@ import json from telegram import InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import Updater, CommandHandler, CallbackQueryHandler from config import config, series -from betaseries import login_beta, get_title_only, to_see +from betaseries import login_beta, get_title_only, to_see, seen from telegram_api import send_message # Activer / Désactiver le debuggage {Projet : pas encore utilisé} @@ -117,30 +117,36 @@ def coding(update, context): print(file_path) with open(file_path) as json_file: data = json.load(json_file) - message = u'Episode que vous allez marquer comme vu : ' + data['serie_title'] + ' - S' + str(data['season ']) + 'E' + str(data['episode']) - send_message(message) - return - + # message = u'Episode que vous allez marquer comme vu : ' + data['serie_title'] + ' - S' + str(data['season ']) + 'E' + str(data['episode']) + # send_message(message) - keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'), + keyboard = [[InlineKeyboardButton(data['serie_title'] + '|' + 'S' + str(data['season ']) + 'E' + str(data['episode']), callback_data='1')]] + reply_markup = InlineKeyboardMarkup(keyboard) + update.message.reply_text('Vous avez vu :', reply_markup=reply_markup) + return + else : + keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'), InlineKeyboardButton("Option 2", callback_data='2'), InlineKeyboardButton("Option 3", callback_data='3')], - - [InlineKeyboardButton("Option 4", callback_data='5')] ] + [InlineKeyboardButton("Option 4", callback_data='4')] ] - reply_markup = InlineKeyboardMarkup(keyboard) - - update.message.reply_text(message, reply_markup=reply_markup) + reply_markup = InlineKeyboardMarkup(keyboard) + update.message.reply_text('Selectionnez une reponse', reply_markup=reply_markup) + return def button(update, context): query = update.callback_query - query.answer() - + print(type(query['data'])) + if query['data'] == u'1' : + if type(series) == str : + seen(series) + + query.edit_message_text(text="Selected option: {}".format(query.data)) diff --git a/notification.py b/notification.py index 87ca5ec..bf5d9ef 100644 --- a/notification.py +++ b/notification.py @@ -30,9 +30,14 @@ def main(): now = datetime.datetime.now() print (now.strftime("%Y-%m-%d %H:%M:%S")) - for i in range(len(series)): - thetvdb_id = series[i] - check_latest(thetvdb_id) + + if type(series) == str : + check_latest(series) + + else: + for i in range(len(series)): + thetvdb_id = series[i] + check_latest(thetvdb_id)