def integrity_check(config, wiggle=0):
    for suite in config.suites:
        for view in suite.views:
            matches = defaultdict(list)
            for couch in config.couches:
                params = {
                    'reduce': 'false',
                    'limit': 0
                }
                resp = requests.get("{uri}/{database}/{view}".format(uri=couch.uri,
                                                                    database=suite.database,
                                                                    view=view),
                    params=params,
                    headers=couch.headers)

                content = json.loads(resp.content)
                try:
                    total_rows = content['total_rows']
                except __HOLE__:
                    print "Problem getting `total_rows`. Is this a valid couch database?  {}"\
                        .format(suite.database)
                else:
                    matched = False
                    for wiggle_range, couches in matches.items():
                        if wiggle_range[0] <= total_rows <= wiggle_range[1]:
                            matches[wiggle_range].append((couch.uri, total_rows))
                            matched = True

                    if not matched:
                        new_wiggle_range = (total_rows - wiggle, total_rows + wiggle)
                        matches[new_wiggle_range].append((couch.uri, total_rows))

            print_result(matches, view, suite.database)
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/cleanup/management/commands/couch_integrity.py/integrity_check