我这样做对吗?我试图用这种方法从索引中删除一个实体,这是我第一次尝试,所以我不知道它是否有效:
def get(self):
timeline = datetime.now () - timedelta (days = 59)
edge = datetime.now () - timedelta (days = 60)
ads = Ad.all().filter("published =", True).filter("modified <", timeline).filter("url IN", ['www.koolbusiness.com']).filter("modified >", edge)
for ad in ads:
if ad.title:
subject= ad.title
else:
subject = 'Reminder'
message = mail.EmailMessage(sender='admin@koolbusiness.com', subject=subject)
reminder = 'You can renew your advertisement'
message.body = ('%s \nhttp://www.koolbusiness.com/vi/%d %s') % (reminder, ad.key().id(), '\nIf you like, you can also add us on Facebook \nhttp://apps.facebook.com/koolbusiness')
message.to=ad.email
message.bcc='fridge@koolbusiness.com'
message.send()
index = search.Index(name='ad',
consistency=Index.PER_DOCUMENT_CONSISTENT)
index.remove(str(ad.key())
上面的代码应该为超时的广告发送提醒,然后从索引中删除。如果广告被更新,它可以再次添加到索引中。它会起作用吗?