Browse Source

Added the acquisition of the token as an environment variable.

Davide Natale 2 years ago
parent
commit
b23530ac29
1 changed files with 8 additions and 7 deletions
  1. 8 7
      LCMbot.py

+ 8 - 7
LCMbot.py

@@ -4,18 +4,19 @@ from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters,
 import handlers as hnd
 from tale_handler import TaleHandler
 import os
+import logging
+logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
+                     level=logging.INFO)
 
-path_to_token = '/usr/local/etc/lcmbot/token'
+
+
+#acquire token from environment variable LCMBOT_TOKEN (string type)
+lcmbot_token = os.environ.get('LCMBOT_TOKEN')
 
 def main():
     # create LCMbot
-    if os.path.isfile(path_to_token):
-        with open(path_to_token) as f:
-            TOKEN = f.readline().rstrip('\n')
-    else:
-	raise Exception('File "' + path_to_token + '" is missing')
 
-    updater = Updater(TOKEN)
+    updater = Updater(lcmbot_token, use_context=True)
     dp = updater.dispatcher
 
     # register handlers