Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1.  
  2. from telegram.ext import Updater, CommandHandler, MessageHandler, RegexHandler, InlineQueryHandler, Filters
  3. from datetime import datetime
  4. from openhab import openHAB
  5. import os
  6.  
  7.  
  8. updater = Updater('<TOKEN REMOVED>')
  9.  
  10. base_url = 'http://10.0.0.116:8080/rest'
  11. openhab = openHAB(base_url)
  12. items = openhab.fetch_all_items()
  13. MasterBedroom = items.get('MasterBedroom')
  14. LivingRoom = items.get('livingroom')
  15. all = items.get('all')
  16. Tv = items.get('Tv')
  17. now = datetime.now()
  18.  
  19. def start(bot, update):
  20. update.message.reply_text('Hello Starting Bot Config & Loading Database, Hello I Am FrightBot I Run Intel And Relay Player Tracker Data.')
  21.  
  22. def date(bot, update):
  23. update.message.reply_text(
  24. 'Date: {}/{}/{}'.format(now.month, now.day, now.year))
  25.  
  26. def time(bot, update):
  27. update.message.reply_text(
  28. 'Time: {}:{}'.format(now.hour, now.minute))
  29.  
  30. def boobs(bot, update):
  31. update.message.reply_text('Excuse Me!! No Need For Boobs Here!!!!')
  32.  
  33. def livingstatus(bot, update):
  34. update.message.reply_text(
  35. '{}'.format(LivingRoom.state))
  36.  
  37. def masterstatus(bot, update):
  38. update.message.reply_text(
  39. '{}'.format(MasterBedroom.state))
  40.  
  41. def tvstatus(bot, update):
  42. update.message.reply_text(
  43. '{}'.format(Tv.state))
  44.  
  45. def allstatus(bot, update):
  46. update.message.reply_text(
  47. '{}'.format(all.state))
  48.  
  49. def tvon(bot, update):
  50. os.system('curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" "http://10.0.0.116:8080/rest/items/tv"')
  51.  
  52. update.message.reply_text('Turning Tv ON')
  53.  
  54. def tvoff(bot, update):
  55. os.system('curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://10.0.0.116:8080/rest/items$
  56. update.message.reply_text('Turning Tv OFF')
  57.  
  58. def masteron(bot, update):
  59. os.system('curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" "http://10.0.0.116:8080/rest/items/masterbedroom"')
  60. update.message.reply_text('Master Bedroom Lights ON')
  61.  
  62. def masteroff(bot, update):
  63. os.system('curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://10.0.0.116:8080/rest/items/masterbedroom"')
  64. update.message.reply_text('Master Bedroom Lights OFF')
  65.  
  66. def livingon(bot, update):
  67. os.system('curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" "http://10.0.0.116:8080/rest/items/livingroom"')
  68. update.message.reply_text('Living Room Lights ON')
  69.  
  70. def livingoff(bot, update):
  71. os.system('curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://10.0.0.116:8080/rest/items$
  72. update.message.reply_text('Turning Living Room Lights OFF Current Status:{}'.format(livingroom.state))
  73.  
  74. def help(bot, update):
  75. update.message.reply_text('List Of Commands /start,/date,/time,/boobs,/masterstatus,/masteron,/masteroff,/livingstatus,/livingon,/livingoff$
  76.  
  77. def unknown(bot, update):
  78. bot.sendMessage(chat_id=update.message.chat_id, text="Sorry, I didn't understand that command.")
  79.  
  80. updater.dispatcher.add_handler(CommandHandler('allstatus', allstatus))
  81. updater.dispatcher.add_handler(CommandHandler('help', help))
  82. updater.dispatcher.add_handler(CommandHandler('livingoff', livingoff))
  83. updater.dispatcher.add_handler(CommandHandler('livingon', livingon))
  84. updater.dispatcher.add_handler(CommandHandler('masteroff', masteroff))
  85. updater.dispatcher.add_handler(CommandHandler('masteron', masteron))
  86. updater.dispatcher.add_handler(CommandHandler('boobs', boobs))
  87. updater.dispatcher.add_handler(CommandHandler('start', start))
  88. updater.dispatcher.add_handler(CommandHandler('date', date))
  89. updater.dispatcher.add_handler(CommandHandler('time', time))
  90. updater.dispatcher.add_handler(CommandHandler('livingstatus', livingstatus))
  91. updater.dispatcher.add_handler(CommandHandler('masterstatus', masterstatus))
  92. updater.dispatcher.add_handler(CommandHandler('tvstatus', tvstatus))
  93. updater.dispatcher.add_handler(CommandHandler('tvon', tvon))
  94. updater.dispatcher.add_handler(CommandHandler('tvoff', tvoff))
  95. unknown_handler = MessageHandler(Filters.command, unknown)
  96.  
  97. dispatcher.add_handler(unknown_handler)
  98.  
  99. updater.start_polling()
  100. updater.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement