Exemplo n.º 1
0
def author_creator(author):
    tmp = get_db_session().query(Author)    \
     .filter(Author.author == author) \
     .scalar()
    if tmp:
        return tmp
    return Author(author=author)
Exemplo n.º 2
0
def set_feed_article_meta(feedid, new_data):
    global QIDIAN_META_CACHE
    # if feedid in QIDIAN_META_CACHE:
    # 	if QIDIAN_META_CACHE[feedid] == new_data:
    # 		return

    sess = get_db_session(flask_sess_if_possible=False)
    have = sess.query(QidianFeedPostMeta).filter(
        QidianFeedPostMeta.contentid == feedid).scalar()
    if have:
        if have.meta != new_data:
            print("Updating item: ", have, have.contentid)
            print("	old -> ", have.meta)
            print("	new -> ", new_data)
            have.meta = new_data
        else:
            print("Item has not changed. Nothing to do!")
    else:
        print("New item: ", feedid, new_data)
        new = QidianFeedPostMeta(
            contentid=feedid,
            meta=new_data,
        )
        sess.add(new)

    sess.commit()

    try:
        QIDIAN_META_CACHE[feedid] = new_data
    except KeyError:
        QIDIAN_META_CACHE = cachetools.TTLCache(maxsize=5000, ttl=60 * 5)
        QIDIAN_META_CACHE[feedid] = new_data

    return
Exemplo n.º 3
0
def author_creator(author):
	tmp = get_db_session().query(Author)    \
		.filter(Author.author == author) \
		.scalar()
	if tmp:
		return tmp
	return Author(author=author)
Exemplo n.º 4
0
def tag_creator(tag):
    tmp = get_db_session().query(Tags) \
     .filter(Tags.tag == tag)    \
     .scalar()
    if tmp:
        return tmp

    return Tags(tag=tag)
Exemplo n.º 5
0
def tag_creator(tag):

	tmp = get_db_session().query(Tags) \
		.filter(Tags.tag == tag)    \
		.scalar()
	if tmp:
		return tmp

	return Tags(tag=tag)
Exemplo n.º 6
0
def get_feed_article_meta(feedid):
    global QIDIAN_META_CACHE
    if feedid in QIDIAN_META_CACHE:
        return QIDIAN_META_CACHE[feedid]

    sess = get_db_session(flask_sess_if_possible=False)
    have = sess.query(QidianFeedPostMeta).filter(
        QidianFeedPostMeta.contentid == feedid).scalar()
    if have:
        ret = have.meta
    else:
        ret = {}

    sess.commit()

    try:
        QIDIAN_META_CACHE[feedid] = ret
    except KeyError:
        QIDIAN_META_CACHE = cachetools.TTLCache(maxsize=5000, ttl=60 * 5)
        QIDIAN_META_CACHE[feedid] = ret

    return ret