def get(self):
        send_res = []
        reservations = yield get_reservations()
        past_email = pickle.load(open(
            './data/emails.pkl', 'rb'))
        for reservation in reservations:
            show_id = reservation['showtime_id']
            show_meta = yield get_showtime(show_id)
            date_str = show_meta['date_str']
            user_id = reservation['user_id']
            user = yield get_user(user_id)
            name = user['name']
            email = user['email']
            if email in past_email:
                continue
            try:
                yield send_reminder(email, name, date_str)
                send_res.append(email)
            except Exception as e:
                print("Exception while sending out emails: {0}".format(e))
                os.makedirs("./data/", exist_ok=True)
            yield gen.sleep(10)
        send_res.extend(past_email)
        with open('./data/emails.pkl', 'wb+') as fd:
            pickle.dump(send_res, fd)

        return self.api_response({'reminder_status': "all sent!"})
    def get(self):
        send_res = []
        reservations = yield get_reservations()
        past_email = pickle.load(open('./data/emails.pkl', 'rb'))
        for reservation in reservations:
            show_id = reservation['showtime_id']
            show_meta = yield get_showtime(show_id)
            date_str = show_meta['date_str']
            user_id = reservation['user_id']
            user = yield get_user(user_id)
            name = user['name']
            email = user['email']
            if email in past_email:
                continue
            try:
                yield send_reminder(email, name, date_str)
                send_res.append(email)
            except Exception as e:
                print("Exception while sending out emails: {0}".format(e))
                os.makedirs("./data/", exist_ok=True)
            yield gen.sleep(10)
        send_res.extend(past_email)
        with open('./data/emails.pkl', 'wb+') as fd:
            pickle.dump(send_res, fd)

        return self.api_response({'reminder_status': "all sent!"})
    def get(self):
        # inefficient databse query, figure out how to perform this query in
        # db.

        # remove all expired tickets
        yield remove_expired_tickets()

        showtimes = yield get_showtimes()
        reservations = yield get_reservations()
        showtime_map = {}  # Tuple (normal_tickets, shitty_tickets)
        for reservation in reservations:
            ticket_id = reservation["showtime_id"]
            ticketTuple = showtime_map.get(ticket_id, (0, 0))
            if reservation['is_shitty']:
                ticketTuple = (ticketTuple[0], ticketTuple[1]+1)
            else:
                ticketTuple = (ticketTuple[0]+1, ticketTuple[1])
            showtime_map[ticket_id] = ticketTuple

        result = []
        for showtime in showtimes:
            showid = showtime["id"]
            dateString = showtime["date_str"]

            if showid in showtime_map:
                available_tickets = \
                    showtime["max_normal_booking"]\
                    - showtime_map[showid][0]
                if available_tickets < 0:
                    available_tickets = 0
                available_shitty_tickets = \
                    showtime["max_shitty_booking"]\
                    - showtime_map[showid][1]
                if available_shitty_tickets < 0:
                    available_shitty_tickets = 0
            else:
                available_tickets = showtime["max_normal_booking"]
                available_shitty_tickets = showtime["max_shitty_booking"]
            result.append({
                "id": showid,
                "date": dateString,
                "available_tickets": available_tickets,
                "shitty_tickets": available_shitty_tickets
            })
        self.api_response(result)
Esempio n. 4
0
    def get(self):
        # inefficient databse query, figure out how to perform this query in
        # db.

        # remove all expired tickets
        yield remove_expired_tickets()

        showtimes = yield get_showtimes()
        reservations = yield get_reservations()
        showtime_map = {}
        for reservation in reservations:
            ticket_id = reservation["showtime_id"]
            if ticket_id in showtime_map:
                showtime_map[ticket_id] += 1
            else:
                showtime_map[ticket_id] = 1

        result = []
        timezone = tz.gettz(CONFIG.get('timezone'))
        timeformat = "%A %d, %B - %I:%M%p"
        for showtime in showtimes:
            showid = showtime["id"]
            dateString = showtime["date"]. \
                astimezone(timezone). \
                strftime(timeformat)

            if showid in showtime_map:
                available_tickets = \
                        showtime["max_booking"] - showtime_map[showid]
                if available_tickets < 0:
                    available_tickets = 0
            else:
                available_tickets = showtime["max_booking"]
            result.append({
                "id": showid,
                "date": dateString,
                "available_tickets": available_tickets,
            })
        self.api_response(result)
Esempio n. 5
0
    def get(self):
        # inefficient databse query, figure out how to perform this query in
        # db.

        # remove all expired tickets
        yield remove_expired_tickets()

        showtimes = yield get_showtimes()
        reservations = yield get_reservations()
        showtime_map = {}
        for reservation in reservations:
            ticket_id = reservation["showtime_id"]
            if ticket_id in showtime_map:
                showtime_map[ticket_id] += 1
            else:
                showtime_map[ticket_id] = 1

        result = []
        timezone = tz.gettz(CONFIG.get('timezone'))
        timeformat = "%A %d, %B - %I:%M%p"
        for showtime in showtimes:
            showid = showtime["id"]
            dateString = showtime["date"]. \
                astimezone(timezone). \
                strftime(timeformat)

            if showid in showtime_map:
                available_tickets = \
                        showtime["max_booking"] - showtime_map[showid]
                if available_tickets < 0:
                    available_tickets = 0
            else:
                available_tickets = showtime["max_booking"]
            result.append({
                "id": showid,
                "date": dateString,
                "available_tickets": available_tickets,
            })
        self.api_response(result)