Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
8 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # This program is dedicated to the public domain under the CC0 license.
  4. # Telegram - Betaseries
  5. import logging
  6. import requests
  7. import json
  8. from telegram import InlineKeyboardButton, InlineKeyboardMarkup
  9. from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
  10. from config import config, series
  11. from betaseries import login_beta, get_title_only, to_see, seen
  12. from telegram_api import send_message
  13. # Activer / Désactiver le debuggage {Projet : pas encore utilisé}
  14. DEBUG = True
  15. # Recupération de la configuration dans config.py
  16. client_id = config['client_id']
  17. login= config['login']
  18. password = config['password']
  19. user_id = config['user_id']
  20. token_bot = config['token_bot']
  21. #Debug only -> permet d'afficher les erreurs sur la console.
  22. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  23. level=logging.INFO)
  24. logger = logging.getLogger(__name__)
  25. def start(update, context):
  26. send_message('Bonjour Sensei. !')
  27. send_message('Je suis ici pour te servir, malgré ça : je reste en Beta ! Soyez doux.')
  28. return
  29. def ping(update, context):
  30. send_message("Pong!")
  31. return
  32. def init(update, context):
  33. update.message.reply_text("Tentative de connexion à Betaseries...")
  34. data = login_beta()
  35. if data == False :
  36. error = "Impossible d'interroger l'API\n Code:" + str(request.status_code)
  37. update.message.reply_text(error)
  38. return
  39. #Si la fonction ne renvoie pas "False", on considère que le token est bon !
  40. betauser = data
  41. message = "Token utilise pour Betaseries : " + betauser
  42. # à editer : nous utiliserons plutot la librairie de telegram lorsque nous répondons à une commande. l'API sera utile pour le script
  43. API_Message = 'https://api.telegram.org/'
  44. API_Message += 'bot' + token_bot + '/sendMessage?chat_id=' + user_id + '&text='
  45. #
  46. Notification = API_Message + "Connection Reussie ! "
  47. request = requests.post(Notification)
  48. Notification = API_Message + " Votre Token sur Betaseries: " + betauser
  49. request = requests.post(Notification)
  50. update.message.reply_text("Vous pouvez maintenant utiliser le bot !")
  51. print("Token Betaseries :", betauser)
  52. return
  53. def repeat(update, context):
  54. message = ''
  55. user = update.message.from_user
  56. if DEBUG == True :
  57. print('Pseudo du compte : {} ID: {} '.format(user['username'], user['id']))
  58. if len(context.args) > 1 :
  59. for i in range(len(context.args)):
  60. mot = str(context.args[i]) + " "
  61. message += mot
  62. message = message[:-1]
  63. else :
  64. message = context.args[0]
  65. if DEBUG == True :
  66. print("phrase envoyée : ", message)
  67. if message == "Cinabre est parfait":
  68. update.message.reply_text("J'avoue !")
  69. return
  70. update.message.reply_text(message)
  71. return
  72. def check_seen(update, context):
  73. message = 'à voir \n'
  74. for i in range(len(series)):
  75. thetvdb_id = series[i]
  76. message += '- ' + str(to_see(thetvdb_id))
  77. send_message(message)
  78. def liste(update, context):
  79. message = ''
  80. message = u'Liste des séries surveillées : ' + '\n'
  81. for i in range(len(series)):
  82. message += '- ' + get_title_only(series[i]) + '\n'
  83. message += '\n' + "Bon Visionnage !"
  84. send_message(message)
  85. def coding(update, context):
  86. if type(series) == str :
  87. file_path = 'latest/' + series + '.json'
  88. print(file_path)
  89. with open(file_path) as json_file:
  90. data = json.load(json_file)
  91. # message = u'Episode que vous allez marquer comme vu : ' + data['serie_title'] + ' - S' + str(data['season ']) + 'E' + str(data['episode'])
  92. # send_message(message)
  93. keyboard = [[InlineKeyboardButton(data['serie_title'] + '|' + 'S' + str(data['season ']) + 'E' + str(data['episode']), callback_data='1')]]
  94. reply_markup = InlineKeyboardMarkup(keyboard)
  95. update.message.reply_text('Vous avez vu :', reply_markup=reply_markup)
  96. return
  97. else :
  98. keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'),
  99. InlineKeyboardButton("Option 2", callback_data='2'),
  100. InlineKeyboardButton("Option 3", callback_data='3')],
  101. [InlineKeyboardButton("Option 4", callback_data='4')] ]
  102. reply_markup = InlineKeyboardMarkup(keyboard)
  103. update.message.reply_text('Selectionnez une reponse', reply_markup=reply_markup)
  104. return
  105. def button(update, context):
  106. query = update.callback_query
  107. query.answer()
  108. print(type(query['data']))
  109. if query['data'] == u'1' :
  110. if type(series) == str :
  111. seen(series)
  112. query.edit_message_text(text="Selected option: {}".format(query.data))
  113. def main():
  114. updater = Updater(token_bot, use_context=True)
  115. print("Bot connecté")
  116. dp = updater.dispatcher
  117. dp.add_handler(CommandHandler("start", start))
  118. dp.add_handler(CommandHandler("help", start))
  119. dp.add_handler(CommandHandler("ping", ping))
  120. dp.add_handler(CommandHandler("repeat", repeat,
  121. pass_args=True,
  122. pass_job_queue=True,
  123. pass_chat_data=True))
  124. dp.add_handler(CommandHandler("initialisation", init,
  125. pass_args=True,
  126. pass_job_queue=True,
  127. pass_chat_data=True))
  128. dp.add_handler(CommandHandler("liste", liste))
  129. dp.add_handler(CommandHandler("check", check_seen))
  130. dp.add_handler(CommandHandler("code", coding))
  131. updater.dispatcher.add_handler(CallbackQueryHandler(button))
  132. updater.start_polling()
  133. updater.idle()
  134. if __name__ == '__main__':
  135. main()