コード例 #1
0
ファイル: fix_mongo_cache.py プロジェクト: ArturFis/grab
def main(*args, **kwargs):
    bot = Spider()
    opts = {'database': kwargs['database']}
    bot.setup_cache(backend='mongo', **opts)

    ts = int(time.time())
    count = 0
    for item in bot.cache.db.cache.find({'timestamp': {'$exists': False}}, timeout=False):
        bot.cache.db.cache.update({'_id': item['_id']},
                                  {'$set': {'timestamp': ts}})
        count += 1
    print('Records updated: %d' % count)
コード例 #2
0
ファイル: fix_mongo_cache.py プロジェクト: boooka/GeoPowerOff
def main(*args, **kwargs):
    bot = Spider()
    opts = {'database': kwargs['database']}
    bot.setup_cache(backend='mongo', **opts)

    ts = int(time.time())
    count = 0
    for item in bot.cache.db.cache.find({'timestamp': {
            '$exists': False
    }},
                                        timeout=False):
        bot.cache.db.cache.update({'_id': item['_id']},
                                  {'$set': {
                                      'timestamp': ts
                                  }})
        count += 1
    print('Records updated: %d' % count)
コード例 #3
0
ファイル: fix_mysql_cache.py プロジェクト: vasia123/grab
def main(*args, **kwargs):
    bot = Spider()
    opts = {'database': kwargs['database']}
    if kwargs.get('user'):
        opts['user'] = kwargs['user']
    if kwargs.get('passwd'):
        opts['passwd'] = kwargs['passwd']
    bot.setup_cache(backend='mysql', **opts)

    cursor = bot.cache.conn.cursor()
    cursor.execute('SELECT * FROM cache LIMIT 1')
    cols = [x[0] for x in cursor.description]
    ts = int(time.time())
    if not 'timestamp' in cols:
        print 'Cache table does not have timestamp column. Adding it...'
        cursor.execute('''
            ALTER TABLE cache
            ADD COLUMN timestamp INT NOT NULL DEFAULT %s''' % ts)
コード例 #4
0
ファイル: fix_mysql_cache.py プロジェクト: sergithon/grab
def main(*args, **kwargs):
    bot = Spider()
    opts = {'database': kwargs['database']}
    if kwargs.get('user'):
        opts['user'] = kwargs['user']
    if kwargs.get('passwd'):
        opts['passwd'] = kwargs['passwd']
    bot.setup_cache(backend='mysql', **opts)

    cursor = bot.cache.conn.cursor()
    cursor.execute('SELECT * FROM cache LIMIT 1')
    cols = [x[0] for x in cursor.description]
    ts = int(time.time())
    if not 'timestamp' in cols:
        print('Cache table does not have timestamp column. Adding it...')
        cursor.execute('''
            ALTER TABLE cache
            ADD COLUMN timestamp INT NOT NULL DEFAULT %s''' % ts)
コード例 #5
0
ファイル: fix_mysql_cache.py プロジェクト: Kuznitsin/grab
def main(*args, **kwargs):
    bot = Spider()
    opts = {"database": kwargs["database"]}
    if kwargs.get("user"):
        opts["user"] = kwargs["user"]
    if kwargs.get("passwd"):
        opts["passwd"] = kwargs["passwd"]
    bot.setup_cache(backend="mysql", **opts)

    cursor = bot.cache.conn.cursor()
    cursor.execute("SELECT * FROM cache LIMIT 1")
    cols = [x[0] for x in cursor.description]
    ts = int(time.time())
    if not "timestamp" in cols:
        print("Cache table does not have timestamp column. Adding it...")
        cursor.execute(
            """
            ALTER TABLE cache
            ADD COLUMN timestamp INT NOT NULL DEFAULT %s"""
            % ts
        )