示例#1
0
def get_all_products(only_monitoring=True):
    if only_monitoring:  # only update those are monitored
        monitoring = Monitor.query(Monitor.switch == True).fetch()
        product_ids = {_.target for _ in monitoring}
        products = [Product.get_by_id(key) for key in product_ids]
    else:
        products = Product.query().fetch()
    return products
示例#2
0
def fetch_by_urlsafe_key(key, urlsafe=True):
    if urlsafe:
        entity_key = ndb.Key(urlsafe=key)
        entity = entity_key.get()
        return entity
    else:
        product = Product.get_by_id(id=key)
        return product
示例#3
0
def create_product_entity(link, currency, current, history, meta):
    product = Product.get_by_id(id=meta["asin"])
    if product is not None:
        return product.key
    else:
        product = Product(id=meta["asin"],
                          link=link,
                          currency=currency,
                          current=current,
                          history=history,
                          meta=meta)
        key = product.put()
        return key
示例#4
0
def get_monitoring(uid):
    monitoring = Monitor.query(
        ndb.AND(Monitor.user == uid, Monitor.switch == True)).fetch()
    products = ndb.get_multi(
        [Product.get_by_id(m.target).key for m in monitoring])
    return zip(monitoring, products)