<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def upcoming_live_chat(self):
 """ Find any upcoming or current live chat to advertise on the home page or live chat page. These are LiveChat's with primary category of 'ask-mama' and category of 'live-chat'. The Chat date must be less than 5 days away, or happening now. """

        chat = None
        now = datetime.now()


        lcqs = self.get_query_set()
        lcqs = lcqs.filter(
            chat_ends_at__gte=now).order_by('-chat_starts_at')
        try:
            if settings.LIVECHAT_PRIMARY_CATEGORY:
                lcqs = lcqs.filter(
                    primary_category__slug=settings.LIVECHAT_PRIMARY_CATEGORY)
        except AttributeError:
            pass
        try:
            if settings.LIVECHAT_CATEGORIES:
                lcqs = lcqs.filter(
                    categories__slug__in=settings.LIVECHAT_CATEGORIES)
        except AttributeError:
            pass
        if lcqs.exists():
            chat = lcqs.latest('chat_starts_at')

        return chat