Beispiel #1
0
def venues(venue, chains):
    if venue:
        current_showings = Showing.query.filter_by(venue=int(venue)).all()
        if not current_showings:
            abort(404)
        if chains:
            chain_length = int(request.args.get('length', 2))
            if chain_length > 4:
                abort(403)
            response = {
                'chain_length':
                chain_length,
                'chains':
                sneakercore.find_chains([(s, s.start, s.end)
                                         for s in current_showings],
                                        chain_length=chain_length)
            }

        else:
            response = {'showings': current_showings}
    else:
        zipcode = request.args.get('zipcode')
        if zipcode:
            matching_venues = get_venues(zipcode)
            if not matching_venues:
                matching_venues = get_showtimes_parse(zipcode)

            response = {'venues': matching_venues}
        else:
            matching_venues = Venue.query.all()
            response = {'venues': matching_venues}

    return jsonify(response)
Beispiel #2
0
    def setUp(self):
        FILENAME = 'test_parse.pkl'

        # if the file isn't there we can't do this test, so it fails
        if not os.path.exists(FILENAME):
            raise Exception("Need a test case pickle to test")

        theatre = cPickle.load(open(FILENAME))
        # this is how the pickle was derived
        # fp = FlixsterParser("94043")
        # theatre = fp.get_theatres()['theatres'][0]
        # cPickle.dump(theatre,open(FILENAME,'w'))


        showtimes = []
        for movie in theatre['movies']:
            for showtime in movie['showtimes']:
                showtimes.append((movie['name'],showtime['start'],showtime['end']))

        self.showtimes = showtimes
        self.chains = sneakercore.find_chains(showtimes,chain_length=CHAIN_LENGTH)
Beispiel #3
0
def get_chains(request,theatre, date=None):
    date = _parse_date(date)

    chain_length = int(request.GET.get('length',3))
    if chain_length > 4:
        return HttpResponse(json.dumps({"error":"No chains longer than 4 items supported"}))

    cache_key = "t%s_%s_%d"%(theatre,date.strftime("%Y-%m-%d"),chain_length)
    chains_json = cache.get(cache_key)
    if not chains_json:
        showings = Showing.objects.filter(venue__id=theatre,start__range=(date.replace(hour=0,minute=0,second=0,microsecond=0),date.replace(hour=23,minute=59,second=59,microsecond=0)))
        showtimes = []
        for showing in showings:
            showtimes.append((showing.movie.id,showing.start,showing.end))
        chains_raw = sneakercore.find_chains(showtimes,chain_length=chain_length)
        chains = {"chains":[]}
        for raw_chain in chains_raw:
            chain = []
            for movie_id,start,end in raw_chain:
                chain.append({"name":Movie.objects.get(id=movie_id).name,"id":movie_id,"start":start,"end":end})
            chains["chains"].append(chain)
        chains_json = json.dumps(chains, cls=DjangoJSONEncoder, indent=1)
        cache.set(cache_key,chains_json)
    return HttpResponse(chains_json)