def get_message_change_ratio(status_update):
"""Expects a status update instance, returns a number representing
how much a message has been edited (1.0 completely changed, 0.0 unchanged)
based on Levenshtein ratio.
If a status update has no associated notification, returns None
https://github.com/ztane/python-Levenshtein
"""
if hasattr(status_update, 'notification'):
author_profile = status_update.author.profile
intro_text = get_notification_intro(author_profile) + '\n\n'
return 1.0 - Levenshtein.ratio(
*[message.replace(intro_text, '')
for message in (
status_update.notification.base_message,
status_update.notification.sent_message)])
else:
return None
评论列表
文章目录