示例#1
0
def update_next_cell(value):
    for index in range(len(spreadsheet.header_row)):
        print('index: {}, current value: {}'.format(
            index, spreadsheet.today[index].value))
        # Get the next cell that hasn't been filled in yet
        if not spreadsheet.today[index].value:
            header = spreadsheet.header_row[index]

            row = spreadsheet.today_row_num
            col = index + 2  # There's a leftmost column that's just dates and it's also 1-indexed

            print('updating "{}" at {},{} with {}'.format(
                header.value, row, col, value))
            spreadsheet.worksheet.update_cell(row, col, value)
            break

    # `index` is now the location of the last answered question
    if index + 1 < len(spreadsheet.header_row):
        next_message = "{}) {}".format(index + 2,
                                       spreadsheet.header_row[index + 1].value)
    else:
        next_message = "You're all set. Put your phone away and sleep."

    sent = Twilio().messages.create(to=TO_NUMBER,
                                    from_=TWILIO_FROM_NUMBER,
                                    body=next_message)
    print(sent)
示例#2
0
def workflow(body: dict, settings: dict) -> None:
    """
    CATCH WORKFLOW allows you to run a code function given an API POST request
    @rtype: null
    @param settings: dictionary of settings params of the workflow
    """
    hrflow_client = Hrflow(api_secret=settings["API_KEY"],
                           api_user=settings["USER_EMAIL"])
    twilio_client = Twilio(settings["TWILIO_SID"],
                           settings["TWILIO_TOKEN"])  # from twilio.com/console
    sms = ReceivedSMS(body)
    try:
        sms_parsing = hrflow_client.document.parsing.post(
            text=sms.Body).get("data")
    except requests.exceptions.RequestException:
        raise Exception("Parsing sms with SmsSid: %s failed " % (sms.SmsSid))
    skills = [
        sms.Body[ent["start"]:ent["end"]].lower()
        for ent in sms_parsing["ents"]
        if ent["label"] in ["HardSkill", "SoftSkill"]
    ]
    if skills:
        message = "Here is the list of parsed skills from the SMS: "
        message += ", ".join(skills)
    else:
        message = "Sorry, no skills found! Please try another message."
    sms_sent = twilio_client.messages.create(to=sms.From,
                                             from_=sms.To,
                                             body=message)
示例#3
0
def send_sms(phone_number, content):
    account_sid = 'AC4d3a68850fdbae49d26518b29c1e0404'
    auth_token = '65890d206e6755cf15afc2b3b5e6c0ee'
    client = Twilio(account_sid, auth_token)

    message = client.messages.create(body=content,
                                     from_='+12243081374',
                                     to=phone_number)
def initialize_twilio_client():
    global twilio_client
    twilio_client = Twilio(twilio_sid, twilio_auth_token)
示例#5
0
    def _create_user(self, email_or_phone, password, fullname, gender,
                     birthday, is_staff, is_superuser, **extra_fields):
        """ Create EmailPhoneUser with the given email or phone and password.
        :param str email_or_phone: user email or phone
        :param str password: user password
        :param bool is_staff: whether user staff or not
        :param bool is_superuser: whether user admin or not
        :return settings.AUTH_USER_MODEL user: user
        :raise ValueError: email or phone is not set
        :raise NumberParseException: phone does not have correct format
        """
        if not email_or_phone:
            raise ValueError('The given email_or_phone must be set')

        if "@" in email_or_phone:
            email_or_phone = self.normalize_email(email_or_phone)

            api_key = 'a0447053ba64e12d58c6f18ee42bcfc5'
            api_secret = '03d7d5b3791148902dcffd64edb62dbb'
            mailjet = Client(auth=(api_key, api_secret), version='v3.1')

            signup_code = datetime.now().strftime('%M%m%H')

            data = {
                'Messages': [{
                    "From": {
                        "Email": "*****@*****.**",
                        "Name": "euame"
                    },
                    "To": [{
                        "Email": email_or_phone,
                        "Name": fullname
                    }],
                    "Subject":
                    "Your euame account verification code",
                    "TextPart":
                    "your code is: " + signup_code,
                    "HTMLPart":
                    "<h3>Dear new customer, your account verification code is:"
                    + signup_code +
                    "</h3><br />please fill your code in the verfication screen of euame app"
                }]
            }

            result = mailjet.send.create(data=data)
            print(result.status_code)
            print(result.json())

            username, email, phone = (email_or_phone, email_or_phone, "")

        else:
            phone = self.normalize_phone(email_or_phone)
            username, email = (email_or_phone, "")

            signup_code = datetime.now().strftime('%M%m%H')
            account_sid = 'AC4d3a68850fdbae49d26518b29c1e0404'
            auth_token = '65890d206e6755cf15afc2b3b5e6c0ee'
            client = Twilio(account_sid, auth_token)

            message = client.messages.create(
                body='your euame verification code: ' + signup_code,
                from_='+12243081374',
                to=phone)
            print(message.sid)

        now = timezone.now()
        is_active = extra_fields.pop("is_active", False)

        user = User.objects.create_user(username=username, password=password)
        user = self.model(user=user,
                          email_or_phone=email_or_phone,
                          email=email,
                          phone=phone,
                          fullname=fullname,
                          gender=gender,
                          birthday=birthday,
                          signup_code=signup_code,
                          is_staff=is_staff,
                          is_active=is_active,
                          is_superuser=is_superuser,
                          last_login=now,
                          date_joined=now,
                          **extra_fields)
        user.save(using=self._db)
        return user
示例#6
0
    def __init__(self, username=None, password=None):
        self.username = username or os.environ.get('TWILIO_ACCOUNT_SID')
        self.password = password or os.environ.get('TWILIO_AUTH_TOKEN')

        self.client = Twilio(self.username, self.password)
示例#7
0
def deliver_text(content):
    return Twilio().messages.create(to=TO_NUMBER,
                                    from_=TWILIO_FROM_NUMBER,
                                    body=content)
示例#8
0
from google.cloud import storage

from twilio_caller.models import TwilioCall
from utility import phone_number_parser, send_simple_message
from audio_pipeline import run_audio_pipeline

# TODO: https://stackoverflow.com/a/3856947/554487
sys.path.append(
    path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))
import audio_tools
from keystone_asr import wav_to_flac, transcribe_gcs, upload_folder, transcribe_slices, transcribe_in_parallel
from pprint import pprint
from keyword_search import index_audio_url, audio_search, phrase_search
from keystone import generate_speaker_lines, sort_words, confidence_to_hex, add_speakers

twilio = Twilio(environ.get('TWILIO_ACCOUNT_SID'),
                environ.get('TWILIO_AUTH_TOKEN'))

UPLOAD_ORIGINAL = True
DO_TRANSCRIPTS = False
DO_INDEXING = True
DO_PHRASE_DETECTION = True
NUM_KEYWORDS = 4
DEFAULT_PHRASE_TIME_SEC = 15
BAD_PHRASES = ['', ' ']

sqs = boto3.resource('sqs')
print('using queue: {}'.format(settings.RECORDING_QUEUE))
recording_queue = sqs.get_queue_by_name(QueueName=settings.RECORDING_QUEUE)


class ReusableForm(forms.Form):