# Path: lib/_db.py
# def get_collection(db_name, collection_name, client='mongo'):
#     client = client_db_map.get(client)
#     db = getattr(client, db_name, None)
#     return getattr(db, collection_name, None)


import _env
from lib._db import get_collection
from config.config import CONFIG
def is_uploaded(title):
    doc = _COLL.find_one({'title': title})
    if doc is None:
        return False
    return True


def insert_uploaded(title):
    _COLL.update(
        {'title': title},
        {
            '$set': {'title': title}
        },
        True
    )


def exist_or_insert(title):
    """不存在则插入并返回Flase
    存在直接返回True"""
    if not title:    # None or '' as True
        return True
    if not is_uploaded(title):
        insert_uploaded(title)
        return False
    else:
        return True


if __name__ == '__main__':

# Path: lib/_db.py
# def get_collection(db_name, collection_name, client='mongo'):
#     client = client_db_map.get(client)
#     db = getattr(client, db_name, None)
#     return getattr(db, collection_name, None)


# Path: crawler/judge_upload.py
import _env
from lib._db import get_collection
from config.config import CONFIG

def is_uploaded(title):
    doc = _COLL.find_one({'title': title})
    if doc is None:
        return False
    return True


def insert_uploaded(title):
    _COLL.update(
        {'title': title},
        {
            '$set': {'title': title}
        },
        True
    )


def exist_or_insert(title):
    """不存在则插入并返回Flase
    存在直接返回True"""
    if not title:    # None or '' as True
        return True
    if not is_uploaded(title):
        insert_uploaded(title)
        return False
    else:
        return True


if __name__ == '__main__':

    print DB