Example #1
0
def main():
    startTimes = [8, 8, 8, 8, 8]
    endTimes = [18, 16, 18, 18, 10]
    date = datetime.today()
    dayOfWeek = date.weekday()
    message = ""
    phone_number = "+19257877379"

    hourly_forecast = forecast.get_hourly_forecast("CA", "Goleta")

    for i in range(5):
        if (dayOfWeek == i):
            minTemp = int(hourly_forecast[startTimes[dayOfWeek] -
                                          6]['temp']['english'])
            maxTemp = int(hourly_forecast[startTimes[dayOfWeek] -
                                          6]['temp']['english'])
            minTempTime = startTimes[dayOfWeek]
            maxTempTime = endTimes[dayOfWeek]

            for j in range(startTimes[dayOfWeek] - 6, endTimes[dayOfWeek] - 5):
                if ("Rain" in hourly_forecast[j]['condition']):
                    message += "Rain forecasted at " + str(j % 12) + ":00. "
                if (int(hourly_forecast[j]['temp']['english']) < minTemp):
                    minTemp = int(hourly_forecast[j]['temp']['english'])
                    minTempTime = j + 6
                if (int(hourly_forecast[j]['temp']['english']) > maxTemp):
                    maxTemp = int(hourly_forecast[j]['temp']['english'])
                    maxTempTime = j + 6

    message += "Min temp today is " + str(minTemp) + " at " \
            + str(minTempTime) + ":00. "
    message += "Max temp today is " + str(maxTemp) + " at " \
            + str(maxTempTime) + ":00. "
    #print(message)
    send_sms.send_message(phone_number, message)
Example #2
0
def yes_func():

    #check if phone in DB
    if session.attributes.get('yes') == 'featured':

        phone_n = check_phone(str(session.user.userId))
        #session.attributes['featured']

        if phone_n == False:

            session.attributes['yes'] = 'phone_ask'
            return question('Great!, tell me your phone number') \
                    .standard_card(title='Golf Georgia',
                    text='Great!,  tell me your phone number',
                    large_image_url=golfcourse_img)

        #phone in DB, send message
        #TWILIO SEND
        else:
            send_text = render_template('send_text')
            send_message(phone_n, session.attributes.get('info'))

            #For NO close session
            session.attributes['yes'] = 'another_golf'
            return question(send_text) \
                    .standard_card(title='Golf Georgia',
                    text=send_text,
                    large_image_url=golfcourse_img)

    #Phone OK send text to phone and write phone to DB
    elif session.attributes.get('yes') == 'phone_confirm':

        session.attributes['yes'] = 'another_golf'
        #Write to DynamoDB
        writeU = write_user(str(session.user.userId),
                            session.attributes.get('phone_number'))

        #TWILIO SEND
        send_text = render_template('send_text')
        send_message('+1' + str(session.attributes['phone_number']),
                     session.attributes.get('info'))

        return question(send_text) \
                .standard_card(title='Golf Georgia',
                text=send_text,
                large_image_url=golfcourse_img)

    elif session.attributes.get('yes') == 'another_golf':
        ask_golf = render_template('ask_golf')
        return question(ask_golf) \
                .standard_card(title='Golf Georgia',
                text='About Georgia Golf',
                large_image_url=golfcourse_img)

    else:
        return question('Would you like to hear today featured golf course or ask a question about a golf course or driving range?') \
                .standard_card(title='Golf Georgia',
                text='Would you like to hear today featured golf course or ask a question about a golf course or driving range?',
                large_image_url=golfcourse_img)
Example #3
0
def unlock_function(input_string):
    lime_help = "Enter: \"limebike bikenumber. No other spaces or funny business\" eg: \"lime 123456\". Just those two!\n"
    args = input_string.split(" ")
    while len(args) != 2:
        return lime_help
    bike_number = input_string.split(" ")[1]
    # change this to the screen coordinates of your start menu or app search function.
    pyautogui.click(22, 746)
    time.sleep(.3)
    pyautogui.typewrite("bluestacks\n")
    time.sleep(15)
    pyautogui.click(
        pyautogui.center(pyautogui.locateOnScreen("images/myAppsToClick.png")))
    while pyautogui.locateOnScreen("images/limebike.png") == None:
        time.sleep(2)
    pyautogui.click(
        pyautogui.center(pyautogui.locateOnScreen("images/limebike.png")))
    time.sleep(1)
    while pyautogui.locateOnScreen("images/unlock.png") == None:
        time.sleep(.5)
    pyautogui.click(
        pyautogui.center(pyautogui.locateOnScreen("images/unlock.png")))
    time.sleep(.2)
    pyautogui.click()
    time.sleep(1)
    while pyautogui.locateOnScreen("images/typeDigitsOption.png") == None:
        time.sleep(.3)
    pyautogui.click(
        pyautogui.center(
            pyautogui.locateOnScreen("images/typeDigitsOption.png")))
    time.sleep(.2)
    pyautogui.click()
    time.sleep(1)
    while pyautogui.locateOnScreen("images/typeDigits.png") == None:
        time.sleep(.3)
    pyautogui.click(
        pyautogui.center(pyautogui.locateOnScreen("images/typeDigits.png")))
    time.sleep(.2)
    pyautogui.click()
    time.sleep(.2)
    pyautogui.typewrite(str(bike_number))
    time.sleep(4)
    if pyautogui.locateOnScreen("images/failed.png") != None:
        pyautogui.click(
            pyautogui.center(pyautogui.locateOnScreen("images/failedOk.png")))
        text_return = "Failed. Bike under maintenance, sorry try another bike :(..."
        send_sms.send_message(text_return)
    else:
        text_return = "Unlocking bike..."
        send_sms.send_message(text_return)
    pyautogui.click(
        pyautogui.center(pyautogui.locateOnScreen("images/limeClose.png")))
    time.sleep(1)
    pyautogui.click(
        pyautogui.center(pyautogui.locateOnScreen("images/appCenter.png")))
    return text_return
Example #4
0
def limebike_unlock(input_string):
    try:
        return unlock_function(input_string)
    except:
        try:
            close_ad_function()
            return unlock_function(input_string)
        except:
            text_return = "Sorry there was an issue with the computer :("
            send_sms.send_message(text_return)
Example #5
0
def sms_reply():
    fromNumber = request.values.get('From', None)
    body = request.values.get('Body', None)
    # Check new user
    if isNewUser(fromNumber):
        msg = (
            "Hi there! This is Uplift’s automated chat bot responding. "
            "I’m here to give you some useful insight about your genome as well as some tips to help you be the best you."
        )
        send_message(msg, fromNumber)
        STATE = NEW_USER
    else:
        STATE = getState(fromNumber)
    return reply(fromNumber, body, STATE)
def check_event():
    try:
        name_list = []
        date_now = str(current_day.day)
        month_now = str(current_day.month)
        year_now = str(current_day.year)

        if len(date_now) == 1:
            date_now = "0" + date_now
        if len(month_now) == 1:
            month_now = "0" + month_now

        query = {
            "parameters.birth_month": date_now,
            "parameters.birth_date": month_now,
            "parameters.birth_year": year_now
        }
        db_data = list(db_client["event_manager"].find(query))

        for doc in db_data:
            name_list.append(doc["name"])

        all_names = ", ".join(name_list)
        print(url)
        message_response = send_message(url, api_key, phone_number, all_names)
        logging.warn("Message response is : {}".format(message_response))

    except Exception as e:
        logging.critical("Problem occured while checking events. {}".format(e))
Example #7
0
def no_message(sender, receiver):       
    if not receiver:
        # No bot number, try to locate admin by sender
        sender_info = database.companies.find_one({'admin.phone':sender})
        if not sender_info:
            sender_info = database.jobs.find_one({'phone':sender})
            if not sender_info:
                #No bot, no admin. no user. log it
                return
            admin = database.companies.find_one({'_id':sender_info.get('company_id', None)})
            if not admin:
                #Cannot find admin. log it
                return
            ##NEED TO EMAIL ADMIN, SINCE THERE IS NO BOT RECEIVER TO TEXT FROM
            
        return
            
    admin = database.companies.find_one({'bot.phone':receiver})
    if not admin:
        #Could not locate company. log it
        return
    msg = "Empty message from " + sender
    sent = send_sms.send_message(utils.format_phone(admin.get('admin', None).get('phone', None)), receiver, msg)
    if not sent:
        #Message was not sent Log it
        return
Example #8
0
def admin_is_sender(admin, receiver, message):
    words = message.split(' ')
    if words[0] == "//":
        job_number = utils.get_job_num_from_sms(words)
        if not job_number:
            #Text admin, there is no job number to find customer
            sent = send_sms.send_message(utils.extract_phone(admin), receiver, "No job number is sms")
            return
            
        if not job_number.startswith('R'):
            job_number = "R"+job_number

        customer = database.jobs.find_one({'job_number':job_number})
        if not customer:
            sent = send_sms.send_message(utils.extract_phone(admin), receiver, "No Customer at "+job_number)
            return
        msg = " ".join(words[2:])
        sent = send_sms.send_message(customer['phone'], receiver, msg)
        if sent:
            database.jobs.update({'_id':customer['_id']},
                                {'$push':{'messages':{'text':msg, 'sender':'AIE', 'type':"", 'date': datetime.datetime.now()}}})
Example #9
0
def make_google_maps_link():
	"""Logic for creating Google Maps Directions link <3"""


	trail_name = request.form.get('trail_name')
	trail_id = request.form.get('trail_id')
	origin = request.form.get('origin')
	origin = origin.replace(',','')
	origin = origin.split()
	origin = "+".join(origin)
	print 'ORIGIN: ', origin

	destination = request.form.get('destination')
	phone_number = request.form.get('phone_number')
	print 'PHONE NUMBER: ', phone_number
	print 'DESTINATION: ', destination
	print 'TRAIL ID', trail_id
	google_maps_url = "https://www.google.com/maps/dir/" + origin + "/" + destination
	body = "Trail Quest Google Map Link to " + trail_name + ": " + google_maps_url
	send_sms.send_message(phone_number, body)
	functions.add_trek_to_users_trails(trail_id)

	return "User sent link."
Example #10
0
def employee_is_sender(employee, admin, receiver, message):
    if message[0] == '/':
        jobs = database.jobs.find({'crew.id':employee['id']})
        for job in jobs:
            if job['notifications'].get('driver_confirm_arrival_time', None).get('sent', None):
                if not job['notifications'].get('driver_confirm_arrival_time', None).get('response', None):
                    #msg = utils.replace_msg_content(utils.build_msg_parse_dict(admin.templates['driver_arrival']))
                    msg = 'Hi '+ job['name'].split(' ')[0] + ' the crew will arrive at ' + message[1:]
                    sent = send_sms.send_message(job['phone'], receiver, msg)
                    if sent:
                        update = database.jobs.find_one_and_update({'_id':job['_id']},
                                            {'$set':{'notifications.driver_confirm_arrival_time.response':datetime.datetime.now()}})
                        if not update:
                            print('No Update')
Example #11
0
def  no_sender(receiver, message):
    if not receiver:
        #Both numbers corrupt. log it
        return
    if not message:
        #no message and no sender. ignore and log it
        return
    admin = find_admin_by_bot_number(receiver)
    if not admin:
        #No sender and No Admin. log it
        return
    msg = "Message: " + message + " From unknown sender "
    sent = send_sms.send_message(utils.format_phone(admin.get('admin', None).get('phone', None)), receiver, msg)
    if not sent:
        #ignore and log it (Enable email notifications in future)
        return
Example #12
0
def send_message():

    def send_message_by_list(contacts_list):
        for num in contacts_list:
            if num:
                question = question_selector(db.get_contact_name_and_username_by_number(num))
                res = send_sms.send_message(num, question)
                # print("number: " + num + "\n" + question)

    def question_selector(contact_name_and_username_tuple):
        contact_name, username = contact_name_and_username_tuple
        q = ""
        schedule_list = db.get_schedule(username)
        week_number = log.get_week_number(log.generate_time_path_by_delta(log.get_days_delta("/logging/response/" + contact_name)))

        if week_number <= schedule_list[0] or week_number > schedule_list[1]:
            q += "Have you had any contact with " + username + " today Y/N\nIf yes, how many times?"
        elif schedule_list[0] < week_number <= schedule_list[1]:
            q += "Have you had any contact with " + username + " today by means other than 'Thinking of You' Y/N\nIf yes, how many times?"

        return q

    contact_dict = db.contact_list_extractor()
    for group in contact_dict:
        if group == "admin":
            message = "The daily message has been sent"
            contact_list = contact_dict[group]
            for number in contact_list:
                # print("number: " + number + "\n" + message)
                res = send_sms.send_message(number, message)

        elif group == "user":
            for user in contact_dict["user"]:

                contact_list = contact_dict["user"][user]
                send_message_by_list(contact_list)

    return "all message be sent"
Example #13
0
    return "Dinner"

###########################################################################

while True:
  message = client.messages.list()[0]
  if (message.direction == 'inbound' and message.body != ''):
    messageStr = message.body.lower()
    messageStr = re.sub('[^A-Za-z0-9]+', "", messageStr)
    user = client.messages.list()[0].from_,
    print(message.body)

    #Check if its a valid restaurant
    if not is_restaurant(messageStr):
      client.messages(message.sid).update(body="")
      send_sms.send_message(help(), user)
    else:
      meal_time = get_meal_time()
      menu = get_menu(get_restaurant(messageStr), meal_time)

      send_sms.send_message(menu, user)
      send_sms.send_message("Enter the menu item for nutrition fact, or type NO to exit", user)
      
      response = search.wait_until(120).lower()
      if (response == "no" or response == "n"):
        continue
      else:
        menuDict = scraper.get_menus(scraper.get_hall(get_restaurant(messageStr)))
        food_str = scraper.get_food_str(menuDict, meal_time, response)

        nutrition = scraper.get_nutrition(menuDict, meal_time, food_str)
Example #14
0
 def send_message_by_list(contacts_list):
     for num in contacts_list:
         if num:
             question = question_selector(db.get_contact_name_and_username_by_number(num))
             res = send_sms.send_message(num, question)
Example #15
0
def reply(phoneNumber, body, state):
    if state == OFF:
        msg = ("Hi there! This is Uplift’s automated chat bot responding. "
               "I’m here to give you some useful insight about your genome as well as some tips to help you be the best you.")
        send_message(msg, phoneNumber)
        setState(phoneNumber, EXISTING_USER)
        # if isNewUser(phoneNumber):
        #     state = NEW_USER
        # else:
        #     state = getState(phoneNumber)
        # reply(phoneNumber, body, state)
    elif state == NEW_USER:
        msg = "Looks like you’re a new user. What’s your name?"
        send_message(msg, phoneNumber)
        addUser(phoneNumber, 'NULL')
        setState(phoneNumber, ADDING_USER)
    elif state == ADDING_USER:
        msg = "Nice to meet you, " + body +"."
        send_message(msg, phoneNumber)
        # Set name here with body
        setName(phoneNumber, body)
        # Change state to CATEGORY INPUT
        setState(phoneNumber, CATEGORY_INPUT)
        return reply(phoneNumber, body, CATEGORY_INPUT)
    elif state == EXISTING_USER:
        msg = "Welcome back!"
        send_message(msg, phoneNumber)
        # Change state to CATEGORY INPUT
        setState(phoneNumber, CATEGORY_INPUT)
    elif state == CATEGORY_INPUT:
        msg = "What would you like to learn about today? Here are some commands you can reply with to learn more about your phenotypes:"\
                "\n“1” to learn about your physical traits"\
                "\n“2” to learn about your personality"\
                "\n“3” to learn about your food and nutrition"\
                "\n“4” to learn about your allergies"\
                "\n“5” to learn about your diseases"\
                "\n“q or quit” to leave the conversation"
        send_message(msg, phoneNumber)
        # Change state to GETTING CATEGORY
        setState(phoneNumber, GETTING_CATEGORY)
    elif state == GETTING_CATEGORY:
        if body in categoriesCommands:
            # A WHOLE LOTTA SHIT HERE
            if body == "1":
                msg_1 = "Cool, you selected physical traits! Give me a second to grab your information."
                phenotypes = getScores(phoneNumber, PHENOTYPES['trait'])
                phenotype = random.choice(list(phenotypes.keys()))
                score = phenotypes[phenotype]
                msg_2 = "Here's an interesting one: " + phenotype
                msg_3 = getPhenotypeDescription(phoneNumber, phenotype)
                msg_4 = getPhenotypeRecommendation(phenotype)
                msg_5 = "Would you like to learn more about your phenotypes?"\
                    "\n“1” to learn about your physical traits"\
                    "\n“2” to learn about your personality"\
                    "\n“3” to learn about your food and nutrition"\
                    "\n“4” to learn about your allergies"\
                    "\n“5” to learn about your diseases"\
                    "\n“q or quit” to leave the conversation"
                send_message(msg_1, phoneNumber)
                send_message(msg_2, phoneNumber)
                send_message(msg_3, phoneNumber)
                send_message(msg_4, phoneNumber)
                send_message(msg_5, phoneNumber)
                # Set state to GETTING_CATEGORY
                setState(phoneNumber, GETTING_CATEGORY)
            elif body == "2":
                msg_1 = "Cool, you selected personality! Give me a second to grab your information."
                phenotypes = getScores(phoneNumber, PHENOTYPES['personality'])
                phenotype = random.choice(list(phenotypes.keys()))
                score = phenotypes[phenotype]
                msg_2 = "Here's an interesting one: " + phenotype
                msg_3 = getPhenotypeDescription(phoneNumber, phenotype)
                msg_4 = getPhenotypeRecommendation(phenotype)
                msg_5 = "Would you like to learn more about your phenotypes?"\
                    "\n“1” to learn about your physical traits"\
                    "\n“2” to learn about your personality"\
                    "\n“3” to learn about your food and nutrition"\
                    "\n“4” to learn about your allergies"\
                    "\n“5” to learn about your diseases"\
                    "\n“q or quit” to leave the conversation"
                send_message(msg_1, phoneNumber)
                send_message(msg_2, phoneNumber)
                send_message(msg_3, phoneNumber)
                send_message(msg_4, phoneNumber)
                send_message(msg_5, phoneNumber)
                # Set state to GETTING_CATEGORY
                setState(phoneNumber, GETTING_CATEGORY)
            elif body == "3":
                msg_1 = "Cool, you selected food and nutrition! Give me a second to grab your information."
                phenotypes = getScores(phoneNumber, PHENOTYPES['food_and_nutrition'])
                phenotype = random.choice(list(phenotypes.keys()))
                score = phenotypes[phenotype]
                msg_2 = "Here's an interesting one: " + phenotype
                msg_3 = getPhenotypeDescription(phoneNumber, phenotype)
                msg_4 = getPhenotypeRecommendation(phenotype)
                msg_5 = "Would you like to learn more about your phenotypes?"\
                    "\n“1” to learn about your physical traits"\
                    "\n“2” to learn about your personality"\
                    "\n“3” to learn about your food and nutrition"\
                    "\n“4” to learn about your allergies"\
                    "\n“5” to learn about your diseases"\
                    "\n“q or quit” to leave the conversation"
                send_message(msg_1, phoneNumber)
                send_message(msg_2, phoneNumber)
                send_message(msg_3, phoneNumber)
                send_message(msg_4, phoneNumber)
                send_message(msg_5, phoneNumber)
                # Set state to GETTING_CATEGORY
                setState(phoneNumber, GETTING_CATEGORY)
            elif body == "4":
                msg_1 = "Cool, you selected allergies! Give me a second to grab your information."
                phenotypes = getScores(phoneNumber, PHENOTYPES['allergy'])
                phenotype = random.choice(list(phenotypes.keys()))
                score = phenotypes[phenotype]
                if score == 0:
                    severity = 'a very low risk'
                elif score == 1:
                    severity = 'a low risk'
                elif score == 2:
                    severity = 'an intermediate risk'
                elif score == 3:
                    severity = 'a significant risk'
                elif score == 4:
                    severity = 'a high risk'
                else:
                    severity = ''
                msg_2 = "Here's an interesting one: " + phenotype
                msg_3 = 'You have ' + severity + ' of suffering from ' + phenotype + '.'
                msg_4 = "Would you like to learn more about your phenotypes?"\
                    "\n“1” to learn about your physical traits"\
                    "\n“2” to learn about your personality"\
                    "\n“3” to learn about your food and nutrition"\
                    "\n“4” to learn about your allergies"\
                    "\n“5” to learn about your diseases"\
                    "\n“q or quit” to leave the conversation"
                send_message(msg_1, phoneNumber)
                send_message(msg_2, phoneNumber)
                send_message(msg_3, phoneNumber)
                send_message(msg_4, phoneNumber)
                # Set state to GETTING_CATEGORY
                setState(phoneNumber, GETTING_CATEGORY)
            elif body == '5':
                msg_1 = "Cool, you selected diseases! Give me a second to grab your information."
                phenotypes = getScores(phoneNumber, PHENOTYPES['disease'])
                phenotype = random.choice(list(phenotypes.keys()))
                score = phenotypes[phenotype]
                msg_2 = "Here's an interesting one: " + phenotype
                msg_3 = getPhenotypeDescription(phoneNumber, phenotype)
                msg_4 = getPhenotypeRecommendation(phenotype)
                msg_5 = "Would you like to learn more about your phenotypes?"\
                    "\n“1” to learn about your physical traits"\
                    "\n“2” to learn about your personality"\
                    "\n“3” to learn about your food and nutrition"\
                    "\n“4” to learn about your allergies"\
                    "\n“5” to learn about your diseases"\
                    "\n“q or quit” to leave the conversation"
                send_message(msg_1, phoneNumber)
                send_message(msg_2, phoneNumber)
                send_message(msg_3, phoneNumber)
                send_message(msg_4, phoneNumber)
                send_message(msg_5, phoneNumber)
                # Set state to GETTING_CATEGORY
                setState(phoneNumber, GETTING_CATEGORY)
            elif body == '6':
                msg_1 = "You are most at risk for {}, {}, and {}."
                phenotypes = getScores(phoneNumber, PHENOTYPES['disease'])
                phenotypes = OrderedDict(sorted(phenotypes.items(), key=lambda t: t[1]))
                phenotypes_ = []
                scores_ = []
                for i in range(3):
                    key, val = phenotypes.popitem()
                    phenotypes_.append(key)
                    scores_.append(val)
                msg_1 = msg_1.format(phenotypes_[0], phenotypes_[1], phenotypes_[2])
                msg_2 = getPhenotypeDescription(phoneNumber, phenotypes_[0])
                msg_3 = getPhenotypeDescription(phoneNumber, phenotypes_[1])
                msg_4 = getPhenotypeDescription(phoneNumber, phenotypes_[2])
                msg_5 = getPhenotypeRecommendation(phenotypes_[0])
                msg_6 = getPhenotypeRecommendation(phenotypes_[1])
                msg_7 = getPhenotypeRecommendation(phenotypes_[2])
                msg_8 = "Would you like to learn more about your phenotypes?"\
                    "\n“1” to learn about your physical traits"\
                    "\n“2” to learn about your personality"\
                    "\n“3” to learn about your food and nutrition"\
                    "\n“4” to learn about your allergies"\
                    "\n“5” to learn about your diseases"\
                    "\n“q or quit” to leave the conversation"
                send_message(msg_1, phoneNumber)
                send_message(msg_2, phoneNumber)
                send_message(msg_3, phoneNumber)
                send_message(msg_4, phoneNumber)
                send_message(msg_5, phoneNumber)
                send_message(msg_6, phoneNumber)
                send_message(msg_7, phoneNumber)
                send_message(msg_8, phoneNumber)
                # Set state to GETTING_CATEGORY
                setState(phoneNumber, GETTING_CATEGORY)
        elif body in quitCommands:
            msg = "Thanks for listening! Hope to hear from you soon :)"
            send_message(msg, phoneNumber)
            # Set state to OFF
            setState(phoneNumber, OFF)
        else:
            msg_1 = "Hmm... I don’t recognize that command."
            msg_2 = "Here are some commands you can reply with to learn more about your phenotypes:"\
                "\n“1” to learn about your physical traits"\
                "\n“2” to learn about your personality"\
                "\n“3” to learn about your food and nutrition"\
                "\n“4” to learn about your allergies"\
                "\n“5” to learn about your diseases"\
                "\n“q or quit” to leave the conversation"
            send_message(msg_1, phoneNumber)
            send_message(msg_2, phoneNumber)
    return str(MessagingResponse())
Example #16
0
def forward_to_admin(admin, receiver, sender_info, msg):
    msg = sender_info['name'] + " " + sender_info['job_number'] + " said: " + msg
    sent = send_sms.send_message(utils.extract_phone(admin), receiver, msg)        
Example #17
0
def send_message_wrapper(session, message):
    send_message(session, message, request.url, convert_to_twilio_outbound)