当前位置: 首页>>代码示例>>Python>>正文


Python pymongo.Connection方法代码示例

本文整理汇总了Python中pymongo.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python pymongo.Connection方法的具体用法?Python pymongo.Connection怎么用?Python pymongo.Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo的用法示例。


在下文中一共展示了pymongo.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: depiler

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def depiler(pile, pile_deleted, pile_catchup, pile_medias, mongoconf, locale, exit_event, debug=False):
    db = MongoClient(mongoconf['host'], mongoconf['port'])[mongoconf['db']]
    coll = db['tweets']
    while not exit_event.is_set() or not pile.empty() or not pile_deleted.empty():
        while not pile_deleted.empty():
            todelete = pile_deleted.get()
            coll.update({'_id': todelete}, {'$set': {'deleted': True}}, upsert=True)

        todo = []
        while not pile.empty():
            todo.append(pile.get())
        stored = 0
        for t in prepare_tweets(todo, locale):
            if pile_medias and t["medias"]:
                pile_medias.put(t)
            if pile_catchup and t["in_reply_to_status_id_str"]:
                if not coll.find_one({"_id": t["in_reply_to_status_id_str"]}):
                    pile_catchup.put(t["in_reply_to_status_id_str"])
            tid = coll.update({'_id': t['_id']}, {'$set': t}, upsert=True)
            stored += 1
        if debug and stored:
            log("DEBUG", "Saved %s tweets in MongoDB" % stored)
        breakable_sleep(2, exit_event)
    log("INFO", "FINISHED depiler") 
开发者ID:medialab,项目名称:gazouilloire,代码行数:26,代码来源:run.py

示例2: after_login

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def after_login(self, response):
        connection = pymongo.Connection("localhost", 27017)
        self.db = connection["zhihu"]
        self.zh_user_col = self.db["zh_user"]

        for key in ["高新科技", "互联网", "电子商务", "电子游戏", "计算机软件", "计算机硬件"]:
            users = self.zh_user_col.find({"industry": key})
            # print users.count()
            for user in users:
                # questions
                num = int(user['ask_num']) if "ask_num" in user.keys() else 0
                page_num = num / 20
                page_num += 1 if num % 20 else 0
                for i in xrange(page_num):
                    url = host + "/people/" + user["username"] + '/asks?page=%d' % (i + 1)
                    yield Request(url, callback=self.parse_ask) 
开发者ID:openslack,项目名称:openslack-crawler,代码行数:18,代码来源:zhihu_ask_spider.py

示例3: after_login

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def after_login(self, response):
        connection = pymongo.Connection("localhost", 27017)
        self.db = connection["zhihu"]
        self.zh_user_col = self.db["zh_user"]

        for key in ["高新科技", "互联网", "电子商务", "电子游戏", "计算机软件", "计算机硬件"]:
            users = self.zh_user_col.find({"industry": key})
            # print users.count()
            for user in users:
                # answers
                num = int(user['answer_num']) if "answer_num" in user.keys()  else 0
                page_num = num / 20
                page_num += 1 if num % 20 else 0
                for i in xrange(page_num):
                    yield Request(host + "/people/" + user["username"] + '/answers?page=%d' % (i + 1),
                                  callback=self.parse_ans) 
开发者ID:openslack,项目名称:openslack-crawler,代码行数:18,代码来源:zhihu_answer_spider.py

示例4: get_connection

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def get_connection():
    global _connection
    if not _connection:
        _connection = Connection(
            host=getattr(settings, 'MONGODB_HOST', None),
            port=getattr(settings, 'MONGODB_PORT', None)
        )
        username = getattr(settings, 'MONGODB_USERNAME', None)
        password = getattr(settings, 'MONGODB_PASSWORD', None)
        db = _connection[settings.MONGODB_DATABASE]
        if username and password:
            db.authenticate(username, password)
        return db
    return _connection[settings.MONGODB_DATABASE] 
开发者ID:arguman,项目名称:arguman.org,代码行数:16,代码来源:utils.py

示例5: __init__

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def __init__(self, **kwargs):
        super(MongoDB, self).__init__(**kwargs)
        if self._connection is None:
            self._connection = Connection(*self.connection_args, **self.connection_kwargs)
        if not self.database:
            self.database = self.session
        self._db = self._connection[self.database]
        self._records = self._db['task_records']
        self._records.ensure_index('msg_id', unique=True)
        self._records.ensure_index('submitted') # for sorting history
        # for rec in self._records.find 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:mongodb.py

示例6: __init__

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def __init__(self, host = db_config['DB_HOST'], 
                        port = db_config['DB_PORT'],
                        user = db_config['DB_USER'], 
                        passwd = db_config['DB_PSW'], 
                        db = db_config['DB_NAME'], 
                        charset = db_config['DB_CHARSET']):
        
        self.connection = pymongo.Connection(host, port)
        self.db = self.connection[db]
        self.db.authenticate(user, passwd) 
开发者ID:NetEaseGame,项目名称:iOS-private-api-checker,代码行数:12,代码来源:Mongo.py

示例7: setUp

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def setUp(self):
        self.client = pymongo.Connection(os.environ.get("TEST_MONGODB"))
        self.db = self.client.test_queue
        self.collection = self.db.locks 
开发者ID:ydf0509,项目名称:distributed_framework,代码行数:6,代码来源:test.py

示例8: __init__

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def __init__(self):
        self.server = settings['MONGODB_SERVER']
        self.port = settings['MONGODB_PORT']
        self.db = settings['MONGODB_DB']
        self.col = settings['MONGODB_COLLECTION']
        connection = pymongo.Connection(self.server, self.port)
        db = connection[self.db]
        self.collection = db[self.col] 
开发者ID:lamjack,项目名称:LotteryTicket,代码行数:10,代码来源:pipelines.py

示例9: __init__

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def __init__(self):
        conn = pymongo.Connection(
            settings['MONGO_CONF']['host'],
            settings['MONGO_CONF']['port']
        )
        db = conn[settings['MONGO_CONF']['db']]
        self.news_collection = db[settings['MONGO_CONF']['collection']] 
开发者ID:BillBillBillBill,项目名称:NewsCrawler,代码行数:9,代码来源:pipelines.py

示例10: nosql

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def nosql():
    import pymongo
    import json
    conn = pymongo.Connection('127.0.0.1', port=27017)
    df = ts.get_tick_data('600848',date='2014-12-22')
    print(df.to_json(orient='records'))
    
    conn.db.tickdata.insert(json.loads(df.to_json(orient='records')))
    
#     print conn.db.tickdata.find() 
开发者ID:waditu,项目名称:tushare,代码行数:12,代码来源:storing_test.py

示例11: connect_to_db_collection

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def connect_to_db_collection(db_name, collection_name):
    '''
    Retrieve collection from given database name and collection name

    '''
    connection = pymongo.Connection('localhost', 27017)
    db = connection[db_name]
    collection = db[collection_name]
    return collection 
开发者ID:McGillX,项目名称:edx_data_research,代码行数:11,代码来源:mongo_forum_to_mongod.py

示例12: connect_to_db_collection

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def connect_to_db_collection(db_name, collection_name):
    '''
    Return collection of a given database name and collection name
    
    '''
    connection = pymongo.Connection('localhost', 27017)
    db = connection[db_name]
    collection = db[collection_name]
    return collection 
开发者ID:McGillX,项目名称:edx_data_research,代码行数:11,代码来源:reference_problem_ids_collection.py

示例13: connect_to_db_collection

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def connect_to_db_collection(db, collection):
    db_name = db
    collection_name = collection
    
    # Get database connection and collections
    connection = pymongo.Connection('localhost', 27017)
    db = connection[db_name]
    tracking = db[collection_name]
    tracking_imported = db[collection_name + "_imported"]
    return tracking, tracking_imported 
开发者ID:McGillX,项目名称:edx_data_research,代码行数:12,代码来源:load_tracking_logs_to_mongo.py

示例14: connectMongo

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def connectMongo(self):
        """连接MongoDB数据库"""
        try:
            self.__mongoConnection = Connection()
            self.__mongoConnected = True
            self.__mongoTickDB = self.__mongoConnection['TickDB']
            self.writeLog(u'回测引擎连接MongoDB成功')
        except ConnectionFailure:
            self.writeLog(u'回测引擎连接MongoDB失败') 
            
    #---------------------------------------------------------------------- 
开发者ID:sunshinelover,项目名称:chanlun,代码行数:13,代码来源:backtestingEngine.py

示例15: __connectMongo

# 需要导入模块: import pymongo [as 别名]
# 或者: from pymongo import Connection [as 别名]
def __connectMongo(self):
        """连接MongoDB数据库"""
        try:
            self.__mongoConnection = Connection()
            self.__mongoConnected = True
            self.__mongoTickDB = self.__mongoConnection['TickDB']
            self.writeLog(u'策略引擎连接MongoDB成功')
        except ConnectionFailure:
            self.writeLog(u'策略引擎连接MongoDB失败')

    #---------------------------------------------------------------------- 
开发者ID:sunshinelover,项目名称:chanlun,代码行数:13,代码来源:strategyEngine.py


注:本文中的pymongo.Connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。