def get_for_user(cls, uid): item, inserted = get_or_insert(Feed, uid) if inserted: item.uid = uid item.put() item.schedule_update() return item
def ensure_source(url, suppress_immediate_fetch=False): url = canonical_url(url) source_id = Source.id_for_source(url) source, inserted = get_or_insert(Source, source_id) if inserted: source.url = url source.put() source.enqueue_fetch() if inserted and not suppress_immediate_fetch: source.fetch_now() return source
def ensure_article_at_url(url, force_fetch=False, force_mercury=False): id = Article.id_for_article(url, None) article, inserted = get_or_insert(Article, id) if inserted: article.added_date = datetime.datetime.now() article.added_order = 0 article.url = canonical_url(url) # article.published = datetime.datetime.now() # article.title = "A test" # article.title = None article.put() if not article.content or force_fetch: article.fetch_now(force_mercury=force_mercury) return article
def add_or_update_bookmark(uid, reading_pos, article_id=None, article_url=None): # provide EITHER article_id or article_url if not (article_id or article_url): logging.error("Attempt to update bookmark without article_id or article_url") return None if not article_id and article_url: article = ensure_article_at_url(article_url) if article: article_id = article.key.id() else: logging.error("Tried to get article {0} for bookmarking, but failed".format(article_url)) return None id = Bookmark.id_for_bookmark(uid, article_id) bookmark, inserted = get_or_insert(Bookmark, id) bookmark.article = ndb.Key(Article, article_id) if reading_pos: bookmark.reading_position = reading_pos bookmark.last_modified = datetime.datetime.now() bookmark.uid = uid bookmark.deleted = False bookmark.put() return bookmark
def set(cls, key, val): pair = util.get_or_insert(KeyValue, key, value=val) pair.value = val pair.put()