Esempio n. 1
0
    def get(self):
        start, end = dates_from_request(self.request)
        if start and end and start > end:
            self.abort(400)
    
        query = LunchOrder.all()
        if start:
            query.filter("date >= ", start)
        if end:
            query.filter("date <= ", end)
        
        totals = defaultdict(int)
        for lunch_order in query.run():
            totals[(lunch_order.person.name, lunch_order.person.key().name())] += 1
            
        template_values = {'totals': totals, 'updated_at': Scraper.all().get().last_scrape}
        if start:
            template_values['start_str'] = start.strftime("%m/%d/%Y")
            template_values['start'] = start.strftime("%Y%m%d")
        else:
            template_values['start_str'] = "the beginning of time"
        if end:
            template_values['end_str'] = end.strftime("%m/%d/%Y")
            template_values['end'] = end.strftime("%Y%m%d")
        else:
            template_values['end_str'] = "the end of time"

        template = JINJA_ENVIRONMENT.get_template('order_summary.html')
        self.response.write(template.render(template_values))
Esempio n. 2
0
    def get(self, name):
        start, end = dates_from_request(self.request)
        if start and end and start > end:
            self.abort(400)
            
        person = Person.get_by_key_name(name)
        if not person:
            self.abort(404)

        query = person.lunch_orders
        if start:
            query.filter("date >= ", start)
        if end:
            query.filter("date <= ", end)
        query.order("date")

        template_values = {'count': query.count(),
                           'query': query,
                           'person': person,
                           'updated_at': Scraper.all().get().last_scrape}
        if start:
            template_values['start_str'] = start.strftime("%m/%d/%Y")
        else:
            template_values['start_str'] = "the beginning of time"
        if end:
            template_values['end_str'] = end.strftime("%m/%d/%Y")
        else:
            template_values['end_str'] = "the end of time"

        template = JINJA_ENVIRONMENT.get_template('person_summary.html')
        self.response.write(template.render(template_values))
Esempio n. 3
0
 def scrape(self):
     scraper = Scraper.all().get()
     scraper.scrape()