示例#1
0
def check_reminders(bms, reminder):
    try:
        event_code = bms.get_event_code(reminder.name,
                                        reminder.language,
                                        dimension=reminder.dimension)
        active_theaters = TheaterLink.objects.filter(reminder=reminder,
                                                     found=False)
        theaters = [link.theater for link in active_theaters]
        showtimes = bms.get_showtimes_by_venue(event_code, theaters,
                                               reminder.date)
        formatted_date = reminder.date.strftime("%a, %B %d %Y")
        formatted_shows = format_shows_list(showtimes)

        theaters_found = [show['venue'] for show in showtimes]
        if len(theaters_found) > 1:
            subject = f"{reminder.name} tickets out at {theaters_found[0].name} and more!"
        else:
            subject = f"{reminder.name} tickets out at {theaters_found[0].name}!"

        email = BaseEmailMessage(
            template_name='email_reminder.html',
            context={
                'subject': subject,
                'reminder': reminder,
                'formatted_date': formatted_date,
                'shows': formatted_shows,
            },
        )

        email.send(
            from_email=settings.DEFAULT_FROM_EMAIL,
            to=[reminder.user.email],
            reply_to=[settings.DEFAULT_REPLY_TO],
        )

        for theater in theaters_found:
            TheaterLink.objects.filter(reminder=reminder,
                                       theater=theater).update(
                                           found=True,
                                           found_at=timezone.localtime())

        if TheaterLink.objects.filter(reminder=reminder,
                                      found=False).count() == 0:
            reminder.completed = True
        reminder.save()
        logger.info("Hit on {}".format(str(reminder)))
    except BMSError as e:
        logger.info("Miss on {}. Reason: {}".format(str(reminder), e))
        reminder.save()
示例#2
0
def find_movies(task):
    region_code = task.city.code
    region_name = task.city.name
    key = task.movie_name
    language = task.movie_language
    dimension = task.movie_dimension
    date = task.movie_date
    formatted_date = date.strftime("%a, %B %d %Y")

    bms = BMS(region_code, region_name)
    
    try:
        showtimes = bms.get_showtimes(key, language, date, dimension)
        movie_url = bms.get_movie_url(key, language, date, dimension)
        shows = format_shows_list(showtimes)

        email = BaseEmailMessage(
                template_name='email.html',
                context={
                        'task': task,
                        'formatted_date': formatted_date,
                        'shows': shows,
                        'movie_url': movie_url,
                        },
        )

        email.send(
                from_email=settings.DEFAULT_FROM_EMAIL,
                to=[task.user.email],
                reply_to=[settings.DEFAULT_REPLY_TO],
        )

        task.task_completed = True
        task.save()
        logger.info("Hit on {}".format(str(task)))
    except BMSError as e:
        task.search_count += 1
        if task.search_count > config.SEARCH_COUNT_LIMIT:
            task.dropped = True
            logger.info("Dropping {}. Reason: {}".format(str(task), e))
        else:
            logger.info("Miss on {}. Reason: {}".format(str(task), e))
        task.save()