2021-09-10 20:24:22 -04:00
|
|
|
from django.conf import settings
|
2020-05-06 16:42:18 +08:00
|
|
|
|
|
|
|
|
2021-09-25 01:09:15 -04:00
|
|
|
def rating_to_emoji(score, star_mode = 0):
|
2020-05-06 16:42:18 +08:00
|
|
|
""" convert score to mastodon star emoji code """
|
|
|
|
if score is None or score == '' or score == 0:
|
|
|
|
return ''
|
|
|
|
solid_stars = score // 2
|
|
|
|
half_star = int(bool(score % 2))
|
|
|
|
empty_stars = 5 - solid_stars if not half_star else 5 - solid_stars - 1
|
2021-09-25 01:09:15 -04:00
|
|
|
if star_mode == 1:
|
|
|
|
emoji_code = "🌕" * solid_stars + "🌗" * half_star + "🌑" * empty_stars
|
|
|
|
else:
|
|
|
|
emoji_code = settings.STAR_SOLID * solid_stars + settings.STAR_HALF * half_star + settings.STAR_EMPTY * empty_stars
|
2020-05-07 06:01:22 +08:00
|
|
|
emoji_code = emoji_code.replace("::", ": :")
|
|
|
|
emoji_code = ' ' + emoji_code + ' '
|
2020-05-06 16:42:18 +08:00
|
|
|
return emoji_code
|