def index(): """Lists the coffeez""" coffees = memcache.get(ALL_COFFEES_KEY) if not coffees: coffees = Coffee.query(Coffee.active == True).fetch() # cannot store all images into memcached due to size limits for coffee in coffees: coffee.image = None memcache.set(ALL_COFFEES_KEY, coffees) roaster_query = memcache.get(ALL_ROASTERS_KEY) if not roaster_query: roaster_query = Coffee.query(projection=["roaster"], distinct=True).fetch() memcache.set(ALL_ROASTERS_KEY, roaster_query) roasters = [data.roaster for data in roaster_query] return render_template('index.html', coffees=coffees, roasters=roasters)
def add_or_update_coffee(coffee_data, coffees_updated, coffees_entered, error_coffees): old_coffees = Coffee.query(Coffee.name == coffee_data['name'], Coffee.roaster == coffee_data['roaster'], Coffee.active == True).fetch() if old_coffees: if len(old_coffees) > 1: logging.warning( "Query for coffee name: {}, roaster: {} returned {} results. Result are {}" .format(coffee_data['name'], coffee_data['roaster'], len(old_coffees), old_coffees)) for key, value in coffee_data.iteritems(): setattr(old_coffees[0], key, value) try: old_coffees[0].put() coffees_updated += 1 except AttributeError: # error putting the coffee into the datastore error_coffees.append(coffee_data['product_page']) else: coffee = Coffee(**coffee_data) try: coffee.put() coffees_entered += 1 except AttributeError: # error putting the coffee into the datastore error_coffees.append(coffee_data['product_page']) return [coffees_updated, coffees_entered, error_coffees]
def cron_update(): """ Checks active coffees to see if theyre inactive """ coffees = Coffee.query(Coffee.active==True).fetch() logging.info('Checking for inactive coffees. Currently {} coffees are active'.format(len(coffees))) inactive_coffees = 0 for coffee in coffees: if coffee.date_updated < datetime.datetime.now() - datetime.timedelta(days=2): coffee.active = False coffee.date_removed = datetime.datetime.now() coffee.put() logging.info('Coffee {} was marked inactive'.format(coffee.name)) inactive_coffees += 1 logging.info("{} coffees were newly marked inactive".format(inactive_coffees)) return "Finished checking active coffees"
def cron_update(): """ Checks active coffees to see if theyre inactive """ coffees = Coffee.query(Coffee.active == True).fetch() logging.info( 'Checking for inactive coffees. Currently {} coffees are active'. format(len(coffees))) inactive_coffees = 0 for coffee in coffees: if coffee.date_updated < datetime.datetime.now() - datetime.timedelta( days=2): coffee.active = False coffee.date_removed = datetime.datetime.now() coffee.put() logging.info('Coffee {} was marked inactive'.format(coffee.name)) inactive_coffees += 1 logging.info( "{} coffees were newly marked inactive".format(inactive_coffees)) return "Finished checking active coffees"
def add_or_update_coffee(coffee_data, coffees_updated, coffees_entered, error_coffees): old_coffees = Coffee.query(Coffee.name == coffee_data['name'], Coffee.roaster == coffee_data['roaster'], Coffee.active==True).fetch() if old_coffees: if len(old_coffees) > 1: logging.warning("Query for coffee name: {}, roaster: {} returned {} results. Result are {}".format(coffee_data['name'], coffee_data['roaster'], len(old_coffees), old_coffees)) for key, value in coffee_data.iteritems(): setattr(old_coffees[0], key, value) try: old_coffees[0].put() coffees_updated +=1 except AttributeError: # error putting the coffee into the datastore error_coffees.append(coffee_data['product_page']) else: coffee=Coffee(**coffee_data) try: coffee.put() coffees_entered +=1 except AttributeError: # error putting the coffee into the datastore error_coffees.append(coffee_data['product_page']) return [coffees_updated, coffees_entered, error_coffees]