本文整理汇总了Python中apostello.models.Keyword.lookup_colour方法的典型用法代码示例。如果您正苦于以下问题:Python Keyword.lookup_colour方法的具体用法?Python Keyword.lookup_colour怎么用?Python Keyword.lookup_colour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apostello.models.Keyword
的用法示例。
在下文中一共展示了Keyword.lookup_colour方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_incoming_sms
# 需要导入模块: from apostello.models import Keyword [as 别名]
# 或者: from apostello.models.Keyword import lookup_colour [as 别名]
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'
示例2: check_log_consistent
# 需要导入模块: from apostello.models import Keyword [as 别名]
# 或者: from apostello.models.Keyword import lookup_colour [as 别名]
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)
示例3: log_msg_in
# 需要导入模块: from apostello.models import Keyword [as 别名]
# 或者: from apostello.models.Keyword import lookup_colour [as 别名]
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)
示例4: handle_incoming_sms
# 需要导入模块: from apostello.models import Keyword [as 别名]
# 或者: from apostello.models.Keyword import lookup_colour [as 别名]
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
示例5: test_lookup_colour_test
# 需要导入模块: from apostello.models import Keyword [as 别名]
# 或者: from apostello.models.Keyword import lookup_colour [as 别名]
def test_lookup_colour_test(self, keywords):
assert Keyword.lookup_colour('test') == '#098f6b'
示例6: test_lookup_colour_none
# 需要导入模块: from apostello.models import Keyword [as 别名]
# 或者: from apostello.models.Keyword import lookup_colour [as 别名]
def test_lookup_colour_none(self):
assert Keyword.lookup_colour('nope') == '#B6B6B6'
示例7: test_lookup_colour_name
# 需要导入模块: from apostello.models import Keyword [as 别名]
# 或者: from apostello.models.Keyword import lookup_colour [as 别名]
def test_lookup_colour_name(self):
assert Keyword.lookup_colour('name John Calvin') == '#BBDEFB'
示例8: test_lookup_colour_stop
# 需要导入模块: from apostello.models import Keyword [as 别名]
# 或者: from apostello.models.Keyword import lookup_colour [as 别名]
def test_lookup_colour_stop(self):
assert Keyword.lookup_colour('stop') == '#FFCDD2'