当前位置: 首页>>代码示例>>Python>>正文


Python models.Keyword类代码示例

本文整理汇总了Python中apostello.models.Keyword的典型用法代码示例。如果您正苦于以下问题:Python Keyword类的具体用法?Python Keyword怎么用?Python Keyword使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Keyword类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_log_consistent

def check_log_consistent(page_id):
    from apostello.models import Keyword, Recipient, SmsInbound
    check_next_page = False
    for x in twilio_client.messages.list(page=page_id, page_size=50, to=settings.TWILIO_FROM_NUM):
        sms, created = SmsInbound.objects.get_or_create(sid=x.sid)
        if created:
            sender, s_created = Recipient.objects.get_or_create(number=x.from_)
            if s_created:
                sender.first_name = 'Unknown'
                sender.last_name = 'Person'
                sender.save()

            sms.content = x.body
            sms.time_received = timezone.make_aware(x.date_created,
                                                    timezone.get_current_timezone())
            sms.sender_name = str(sender)
            sms.sender_num = x.from_
            sms.matched_keyword = str(Keyword.match(x.body.strip()))
            sms.matched_colour = Keyword.lookup_colour(x.body.strip())
            sms.is_archived = True
            sms.save()
            check_next_page = True

    if check_next_page:
        check_log_consistent.delay(page_id + 1)
开发者ID:AustinBratcher,项目名称:apostello,代码行数:25,代码来源:tasks.py

示例2: import_incoming_sms

def import_incoming_sms():
    """
    Loops over all incoming messages in Twilio's logs and adds them to our db.
    """
    try:
        sms_page = twilio_client.messages.iter(to_=settings.TWILIO_FROM_NUM)
        for x in sms_page:
            try:
                sms, created = SmsInbound.objects.get_or_create(
                    sid=x.sid,
                    time_received=timezone.now()
                )
                if created:
                    sender, s_created = Recipient.objects.get_or_create(number=x.from_)
                    if s_created:
                        sender.first_name = 'Unknown'
                        sender.last_name = 'Person'
                        sender.save()

                    sms.content = x.body
                    sms.time_received = timezone.make_aware(x.date_sent, timezone.get_current_timezone())
                    sms.sender_name = str(sender)
                    sms.sender_num = x.from_
                    matched_keyword = Keyword.match(x.body)
                    sms.matched_keyword = str(matched_keyword)
                    sms.matched_colour = Keyword.lookup_colour(x.body)
                    sms.matched_link = Keyword.get_log_link(matched_keyword)
                    sms.save()
            except Exception as e:
                print(e)

    except TwilioRestException as e:
        if e.code == 20008:
            return 'test credentials used'
开发者ID:AustinBratcher,项目名称:apostello,代码行数:34,代码来源:logs.py

示例3: test_stop_start

    def test_stop_start(self, recipients):
        sms_body = "stop "
        k_obj = Keyword.match(sms_body)
        reply_to_incoming(
            recipients['calvin'], recipients['calvin'].number, sms_body, k_obj
        )
        assert recipients['calvin'].is_blocking

        sms_body = "start"
        k_obj = Keyword.match(sms_body)
        reply_to_incoming(
            recipients['calvin'], recipients['calvin'].number, sms_body, k_obj
        )
        assert recipients['calvin'].is_blocking is False
开发者ID:gitter-badger,项目名称:apostello,代码行数:14,代码来源:test_reply.py

示例4: log_msg_in

def log_msg_in(p, t, from_pk):
    from apostello.models import Keyword, SmsInbound, Recipient
    from_ = Recipient.objects.get(pk=from_pk)
    matched_keyword = Keyword.match(p['Body'].strip())
    SmsInbound.objects.create(sid=p['MessageSid'],
                              content=p['Body'],
                              time_received=t,
                              sender_name=str(from_),
                              sender_num=p['From'],
                              matched_keyword=str(matched_keyword),
                              matched_link=Keyword.get_log_link(matched_keyword),
                              matched_colour=Keyword.lookup_colour(p['Body'].strip()))
    # check log is consistent:
    check_log_consistent.delay(0)
开发者ID:AustinBratcher,项目名称:apostello,代码行数:14,代码来源:tasks.py

示例5: sms

def sms(request):
    """
    Handles all incoming messages from Twilio.
    This is the start of the message processing pipeline.
    """
    r = twiml.Response()
    params = request.POST
    from_ = params['From']
    sms_body = params['Body'].strip()
    keyword_obj = Keyword.match(sms_body)
    # get person object and optionally ask for their name
    person_from = get_person_or_ask_for_name(from_, sms_body, keyword_obj)
    log_msg_in.delay(params, timezone.now(), person_from.pk)
    post_to_slack.delay(
        "{0}\nFrom: {1}\n(matched: {2})".format(
            sms_body, str(person_from), str(keyword_obj)
        )
    )

    reply = reply_to_incoming(person_from, from_, sms_body, keyword_obj)

    config = SiteConfiguration.get_solo()
    if not config.disable_all_replies:
        r.message(reply)

    return r
开发者ID:AustinBratcher,项目名称:apostello,代码行数:26,代码来源:views.py

示例6: test_other

 def test_other(self, recipients):
     sms_body = "test message"
     k_obj = Keyword.match(sms_body)
     r_new = reply_to_incoming(
         recipients['calvin'], recipients['calvin'].number, sms_body, k_obj
     )
     assert "" in str(r_new)
开发者ID:gitter-badger,项目名称:apostello,代码行数:7,代码来源:test_reply.py

示例7: test_only_one_name

 def test_only_one_name(self, recipients):
     sms_body = "name JohnCalvin"
     k_obj = Keyword.match(sms_body)
     r_new = reply_to_incoming(
         recipients['calvin'], recipients['calvin'].number, sms_body, k_obj
     )
     assert "Something went wrong" in str(r_new)
开发者ID:gitter-badger,项目名称:apostello,代码行数:7,代码来源:test_reply.py

示例8: test_name

 def test_name(self, recipients):
     sms_body = "name John Calvin"
     k_obj = Keyword.match(sms_body)
     reply = reply_to_incoming(
         recipients['calvin'], recipients['calvin'].number, sms_body, k_obj
     )
     assert "John" in str(reply)
开发者ID:gitter-badger,项目名称:apostello,代码行数:7,代码来源:test_reply.py

示例9: __init__

 def __init__(self, msg_params):
     self.msg_params = msg_params
     self.contact_number = msg_params['From']
     self.sms_body = msg_params['Body'].strip()
     # match keyword:
     self.keyword = Keyword.match(self.sms_body)
     # look up contact and determine if we need to ask for their name:
     self.contact, self.send_name_sms = self.lookup_contact()
     # construct reply sms
     self.reply = self.construct_reply()
开发者ID:mrphishxxx,项目名称:apostello,代码行数:10,代码来源:reply.py

示例10: handle_incoming_sms

def handle_incoming_sms(msg):
    """Add incoming sms to log."""
    sms, created = SmsInbound.objects.get_or_create(sid=msg.sid)
    if created:
        check_next_page = True
        sender, s_created = Recipient.objects.get_or_create(number=msg.from_)
        if s_created:
            sender.first_name = 'Unknown'
            sender.last_name = 'Person'
            sender.save()

        sms.content = msg.body
        sms.time_received = timezone.make_aware(
            msg.date_created, timezone.get_current_timezone()
        )
        sms.sender_name = str(sender)
        sms.sender_num = msg.from_
        matched_keyword = Keyword.match(msg.body)
        sms.matched_keyword = str(matched_keyword)
        sms.matched_colour = Keyword.lookup_colour(msg.body)
        sms.matched_link = Keyword.get_log_link(matched_keyword)
        sms.save()
        return check_next_page
开发者ID:monty5811,项目名称:apostello,代码行数:23,代码来源:logs.py

示例11: __init__

 def __init__(self, msg_params):
     self.msg_params = msg_params
     self.contact_number = msg_params['From']
     self.sms_body = msg_params['Body'].strip()
     # match keyword:
     self.keyword = Keyword.match(self.sms_body)
     # look up contact and determine if we need to ask for their name:
     self.contact, self.send_name_sms = self.lookup_contact()
     # construct reply sms
     self.reply = self.construct_reply()
     # add contact to keyword linked groups:
     try:
         self.keyword.add_contact_to_groups(self.contact)
     except AttributeError:
         # not a custom keyword
         pass
开发者ID:monty5811,项目名称:apostello,代码行数:16,代码来源:reply.py

示例12: test_get_log_link_str

 def test_get_log_link_str(self, keywords):
     assert Keyword.get_log_link('test_no_link') == '#'
开发者ID:icodebuster,项目名称:apostello,代码行数:2,代码来源:test_keyword.py

示例13: test_stop

 def test_stop(self):
     assert Keyword.match("Stop it!") == 'stop'
     assert Keyword.match("stop    ") == 'stop'
     assert Keyword.match("\nSTOP    ") == 'stop'
     for x in ["stopall", "unsubscribe", "cancel", "end", "quit"]:
         assert Keyword.match("{0}".format(x)) == 'stop'
开发者ID:nikolay,项目名称:apostello,代码行数:6,代码来源:test_keyword.py

示例14: test_info

 def test_info(self):
     for x in ["help", "info"]:
         assert Keyword.match("{0}".format(x)) == 'info'
开发者ID:nikolay,项目名称:apostello,代码行数:3,代码来源:test_keyword.py

示例15: test_no_match

 def test_no_match(self, keywords):
     assert Keyword.match("nope") == 'No Match'
开发者ID:nikolay,项目名称:apostello,代码行数:2,代码来源:test_keyword.py


注:本文中的apostello.models.Keyword类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。