from flask import Flask, request
import os
from twilio.twiml.messaging_response import MessagingResponse
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), chrome_options=chrome_options)
app = Flask(__name__)
import utils

@app.route("/")
def hello():
    return "Hello World!"

@app.route('/bot', methods=['POST'])
def bot():
    incoming_msg = request.values.get('Body', '')
    print(incoming_msg)
    resp = MessagingResponse()
    msg = resp.message()
    responded = False
    
    if incoming_msg in ['Hi', 'Hey', 'Menu']:
        text = f'Hello\n For any suggestions or requests 👇 \n 📞 : 9537701631 \n ✉ : rohit.saxena.met17@itbhu.ac.in \n\n Please enter one of the following option 👇 \n *TPC*. TPC portal willingness \n *B*. __________. '
        msg.body(text)
        responded = True

    elif 'TPC' in incoming_msg:
        if incoming_msg == 'TPC':
            text = 'Menu of options for TPC command'
            msg.body(text)
            h = 7
            responded = True
         
        utils.portalLogin(os.environ.get('TPC_EMAIL'),os.environ.get('TPC_PWD'))
        if incoming_msg == 'TPC -willingness -short' or incoming_msg == 'TPC -w -s':
            utils.getWillingness()
            utils.shortenWillingness()
        elif incoming_msg == 'TPC -willingness -details' or incoming_msg == 'TPC -w -d':
            utils.portalLogin(os.environ.get('TPC_EMAIL'),os.environ.get('TPC_PWD'))
            utils.getWillingness()
        elif incoming_msg == 'TPC -willingness -details' or incoming_msg == 'TPC -w -d':
            utils.portalLogin(os.environ.get('TPC_EMAIL'),os.environ.get('TPC_PWD'))
            utils.getWillingness()
        elif incoming_msg[:15] == 'TPC -experience' or (incoming_msg[:7] == 'TPC - e ' and len(incoming_msg)>8):
            utils.portalLogin(os.environ.get('TPC_EMAIL'),os.environ.get('TPC_PWD'))
            companyName = incoming_msg.split(' ')[2]
            print(companyName)
            utils.getInterviewExperience(companyName)
        else:
            # send custom error msg for TPC commands
            pass
    else:
        # Checking for formality
        if responded == False:
            msg.body('Please enter valid commands')

    return str(resp)

if __name__ == "__main__":
    app.run(host="localhost", port=5000, debug=True)



[((5, 17, 5, 42), 'selenium.webdriver.ChromeOptions', 'webdriver.ChromeOptions', ({}, {}), '()', False, 'from selenium import webdriver\n'), ((6, 33, 6, 68), 'os.environ.get', 'os.environ.get', ({(6, 48, 6, 67): '"""GOOGLE_CHROME_BIN"""'}, {}), "('GOOGLE_CHROME_BIN')", False, 'import os\n'), ((11, 6, 11, 21), 'flask.Flask', 'Flask', ({(11, 12, 11, 20): '__name__'}, {}), '(__name__)', False, 'from flask import Flask, request\n'), ((20, 19, 20, 49), 'flask.request.values.get', 'request.values.get', ({(20, 38, 20, 44): '"""Body"""', (20, 46, 20, 48): '""""""'}, {}), "('Body', '')", False, 'from flask import Flask, request\n'), ((22, 11, 22, 30), 'twilio.twiml.messaging_response.MessagingResponse', 'MessagingResponse', ({}, {}), '()', False, 'from twilio.twiml.messaging_response import MessagingResponse\n'), ((10, 42, 10, 77), 'os.environ.get', 'os.environ.get', ({(10, 57, 10, 76): '"""CHROMEDRIVER_PATH"""'}, {}), "('CHROMEDRIVER_PATH')", False, 'import os\n'), ((38, 26, 38, 53), 'os.environ.get', 'os.environ.get', ({(38, 41, 38, 52): '"""TPC_EMAIL"""'}, {}), "('TPC_EMAIL')", False, 'import os\n'), ((38, 54, 38, 79), 'os.environ.get', 'os.environ.get', ({(38, 69, 38, 78): '"""TPC_PWD"""'}, {}), "('TPC_PWD')", False, 'import os\n'), ((40, 12, 40, 34), 'utils.getWillingness', 'utils.getWillingness', ({}, {}), '()', False, 'import utils\n'), ((41, 12, 41, 38), 'utils.shortenWillingness', 'utils.shortenWillingness', ({}, {}), '()', False, 'import utils\n'), ((44, 12, 44, 34), 'utils.getWillingness', 'utils.getWillingness', ({}, {}), '()', False, 'import utils\n'), ((43, 30, 43, 57), 'os.environ.get', 'os.environ.get', ({(43, 45, 43, 56): '"""TPC_EMAIL"""'}, {}), "('TPC_EMAIL')", False, 'import os\n'), ((43, 58, 43, 83), 'os.environ.get', 'os.environ.get', ({(43, 73, 43, 82): '"""TPC_PWD"""'}, {}), "('TPC_PWD')", False, 'import os\n'), ((47, 12, 47, 34), 'utils.getWillingness', 'utils.getWillingness', ({}, {}), '()', False, 'import utils\n'), ((46, 30, 46, 57), 'os.environ.get', 'os.environ.get', ({(46, 45, 46, 56): '"""TPC_EMAIL"""'}, {}), "('TPC_EMAIL')", False, 'import os\n'), ((46, 58, 46, 83), 'os.environ.get', 'os.environ.get', ({(46, 73, 46, 82): '"""TPC_PWD"""'}, {}), "('TPC_PWD')", False, 'import os\n'), ((52, 12, 52, 53), 'utils.getInterviewExperience', 'utils.getInterviewExperience', ({(52, 41, 52, 52): 'companyName'}, {}), '(companyName)', False, 'import utils\n'), ((49, 30, 49, 57), 'os.environ.get', 'os.environ.get', ({(49, 45, 49, 56): '"""TPC_EMAIL"""'}, {}), "('TPC_EMAIL')", False, 'import os\n'), ((49, 58, 49, 83), 'os.environ.get', 'os.environ.get', ({(49, 73, 49, 82): '"""TPC_PWD"""'}, {}), "('TPC_PWD')", False, 'import os\n')]