Пример #1
0
def trigger_send_reply(record, browser):
    current_chunk = record['current_chunk']
    current_message = record['result'][current_chunk]
    print("Staged Message: " + str(current_message))
    # try:
    #     number = record['from']
    #     initiate_gv_send(number, browser, current_message)
    #     mongo.change_db_user_value(record, "current_sms_id", record['sms_id'])
    #     updated_record = {
    #         "current_sms_id": record['sms_id'],
    #         "current_chunk": (current_chunk + 1)
    #     }
    #     mongo.update_record(record, updated_record, mongo.message_records)
    #     mongo.change_db_message_value(record, "current_sms_id", record['sms_id'])
    # except:
    #     print("Error inside Trigger_send_reply")
    #     # This is a trouble spot
    # try:
    number = record['from']
    initiate_gv_send(number, browser, current_message)
    mongo.change_db_user_value(record, "current_sms_id", record['sms_id'])
    updated_record = {
        "current_sms_id": record['sms_id'],
        "current_chunk": (current_chunk + 1)
    }
    mongo.update_record(record, updated_record, mongo.message_records)
    mongo.change_db_message_value(record, "current_sms_id", record['sms_id'])
    # except:
    #     print("Error inside Trigger_send_reply")
    #     # This is a trouble spot

    updated_message = mongo.message_records.find_one(
        {"sms_id": record['sms_id']})
    return updated_message
Пример #2
0
def store_reply_in_mongo(result,
                         sender_info,
                         topic,
                         send_all_chunks="SINGLE_CHUNKS",
                         launch_time="NOW"):
    message_copy = mongo.message_records.find_one(
        {"sms_id": sender_info['sms_id']})
    time.sleep(1)
    tia_sign_off = "\n\n--😘,\n✨ Tia ✨ Text" \
        " 📲 me another request, " + str(
            message_copy['name']) + ", or text HELP"
    result = str(topic) + " for " + str(
        message_copy['name']) + "!\n\n" + result + tia_sign_off

    result = gv.sizing_sms_chunks(result, send_all_chunks)
    chunk_len = result[0]
    chunk_reply = result[1]

    db_changes = {
        "result": chunk_reply,
        "status": "completed processing",
        "launch_time": launch_time,
        "send_all_chunks": send_all_chunks,
        "current_chunk": 0,
        "chunk_len": chunk_len
    }

    mongo.update_record(message_copy, db_changes, mongo.message_records)
Пример #3
0
def trigger_cancel_all(sender_info):
    name = mongo.fetch_name_from_db(sender_info)
    for message in mongo.timed_records.find({"from": sender_info['from']}):
        db_changes = {"deactivate": "YES", "scheduled": "NO"}
        mongo.update_record(message, db_changes, mongo.timed_records)
    result = "👌 Sure thing, " + name + "! 🛑 I've cancelled all of your scheduled ⌚ notifications! \n\n--😘,\n✨ Tia ✨"
    send_cancel_receipt(sender_info, result)
Пример #4
0
def trigger_cancel(sender_info):
    message_array = []
    name = mongo.fetch_name_from_db(sender_info)
    for message in mongo.timed_records.find({"from": sender_info['from']}):
        message_array.append(message)

    most_recent = message_array[0]
    for i in range(0, len(message_array)):
        if most_recent['created_at'] < message_array[i]['created_at']:
            most_recent = message_array[i]
    result = "👌 Sure thing, " + name + '!' + " I've 🛑 your most recently scheduled ⌚ message, '" + str(
        most_recent['orig_request']).capitalize(
        ) + "'. To 🚫 all notifications, text 📲 CANCEL ALL. \n\n--😘,\n✨ Tia ✨"
    # print(result)
    db_changes = {"deactivate": "YES", "scheduled": "NO"}
    mongo.update_record(most_recent, db_changes, mongo.timed_records)
    send_cancel_receipt(sender_info, result)
Пример #5
0
def transfer_preset_timers_to_timer_queue():

    for message in mongo.timed_records.find({"scheduled": "NO"}):
        # message = mongo.convert_message_from_bytes(message)

        connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
        channel = connection.channel()
        channel.queue_declare(queue='timer_queue', durable=True)
        channel.basic_publish(exchange='',
                              routing_key='timer_queue',
                              body=str(message['sms_id']),
                              properties=pika.BasicProperties(
                              delivery_mode = 2, # make message persistent
                              ))
        print("Worker Timer Body: " + str(message))
        mongo.update_record(message, {"scheduled": "IN PROCESS"}, mongo.timed_records)

        mongo.change_db_message_value(message, "status", "timer-processing-setting")
        print("\n\n[x] Sent Message To TIMED MESSAGES QUEUE %r" % str(message['body']))
Пример #6
0
def store_jokes_in_mongo(result,
                         sender_info,
                         topic,
                         send_all_chunks="SINGLE_CHUNKS",
                         launch_time="NOW"):
    message_copy = mongo.message_records.find_one(
        {"sms_id": sender_info['sms_id']})
    time.sleep(1)
    # result = eval(result)
    print("Result type: " + str(type(result)))
    print("result[1], chunk_result: " + str(result[1]))
    print("result[0], chunk_len: " + str(result[0]))
    db_changes = {
        "result": result[1],
        "status": "completed processing",
        "launch_time": launch_time,
        "send_all_chunks": send_all_chunks,
        "current_chunk": 0,
        "chunk_len": result[0]
    }

    mongo.update_record(message_copy, db_changes, mongo.message_records)
Пример #7
0
def store_reply_in_mongo_no_header(result,
                                   sender_info,
                                   send_all_chunks="ALL_CHUNKS",
                                   launch_time="NOW"):
    message_copy = mongo.message_records.find_one(
        {"sms_id": sender_info['sms_id']})
    time.sleep(1)

    result = gv.sizing_sms_chunks(result, send_all_chunks)
    chunk_len = result[0]
    chunk_reply = result[1]

    db_changes = {
        "result": chunk_reply,
        "status": "completed processing",
        "launch_time": launch_time,
        "send_all_chunks": send_all_chunks,
        "current_chunk": 0,
        "chunk_len": chunk_len
    }

    mongo.update_record(message_copy, db_changes, mongo.message_records)
Пример #8
0
def add_geo_data_to_db(command, sender_info):
    try:
        home_str = sender_info['home']
        if home_str == "NO ADDRESS GIVEN":
            home_str = sender_info['body']
            home_str = re.sub("new home", "", home_str.lower())
    except:
        home_str = sender_info['body']

    print("Home_str: " + str(home_str))

    home_lat_long = geo.lat_long_single_location(command)

    print("home_lat_long: " + str(home_lat_long))
    time_zone_list = convert_coords_to_time_zone(str(home_lat_long[0]),
                                                 str(home_lat_long[1]))
    zone_name = time_zone_list[0]
    local_current_time = time_zone_list[1]

    home_zip = weather.get_zip(home_str)

    time_zone_change = convert_wit_zone_to_home(zone_name)
    print("time_zone_change: " + str(time_zone_change))

    message_copy = mongo.message_records.find_one(
        {"sms_id": sender_info['sms_id']})
    db_changes = {
        "offset_time_zone": time_zone_change,
        "local_current_time": local_current_time,
        "zone_name": zone_name,
        "home_lat_long": home_lat_long,
        "home_zip": home_zip
    }
    mongo.update_record(message_copy, db_changes, mongo.message_records)
    user_data = mongo.user_records.find_one({'phone': sender_info['from']})
    mongo.update_record(user_data, db_changes, mongo.user_records)
    return time_zone_change