'Sync Bitbucket teams and team repositories'

def sync_teams(self):

    try:
        teams = self.paginate('https://api.bitbucket.org/2.0/teams/?role=member')
        for team in teams:
            org = self.create_organization(team)
            repos = self.paginate(team['links']['repositories']['href'])
            for repo in repos:
                self.create_repository(repo, organization=org)
    except ValueError as e:
        log.error('Error    syncing    Bitbucket    organizations:    %s', str(e), exc_info=True)
        raise Exception('Could    not    sync    your    Bitbucket    team    repositories,    try    reconnecting    your    account')
