示例#1
0
def search_gists(username, description=None, file_name=None):
    if not description and not file_name:
        print("At least one serach parameter must be specified")
        return

    gists = get_gists(username)
    if gists is None:
        print("Couldn't find gists for user {}".format(username))
        return

    results = []
    for gist in gists:
        if description and description.lower(
        ) not in gist['description'].lower():
            continue
        if file_name:
            macthed = False
            for fname, fbody in gists['files'].items():
                if file_name in fname:
                    matched = True
                    break
            if not macthed:
                continue

        results.append(gist)
    return results
示例#2
0
def search_gists(username, description=None, file_name=None):
    if not description and not file_name:
        print("At least one search parameter must be specified")
        return

    results = []

    gists = get_gists(username)

    if gists is None:
        print("User {} has no gists to share".format(username))

        return  # By default this will return None

    for gist in gists:

        if description and description.lower(
        ) not in gist['description'].lower():
            continue

        if file_name:
            matched = False  #Defining this just so we don't have to append gist inside the for loop and we can use break/continue.
            for fname, fbody in gist['files'].items():
                if file_name in fname:
                    matches = True
                    break
                if not matched:
                    continue
        results.append(gist)

    return results
示例#3
0
def search_gists(username, description=None, file_name=None):
    if not description and not file_name:
        print("At least one search parameter must be specified")
        return
    gists = get_gists(username)

    result = []

    for gist in gists:
        #first condition description
        if description and description.lower(
        ) not in gist['description'].lower():
            continue

        #second condition file_name
        if file_name:
            matched = False
            for key, values in gist['files'].items():
                if file_name.lower() in key.lower():
                    matched = True
            if not matched:
                continue

        result.append(gist)

    return result
示例#4
0
def search_gists(username, description=None, file_name=None):
    if not description and not file_name:
        print("At least one search parameter must be specified")
        return
    gists = get_gists(username)
    if gists is None:
        print('Invalid username {}'.format(username))
        return

    results = []
    for gist in gists:
        if description and description.lower(
        ) not in gist['description'].lower():
            continue

        if file_name:
            found = False
            for f_name in gist['files']:
                found = True
            if not found:
                continue

        results.append(gist)

    return results
示例#5
0
def search_gists(username, description=None, file_name=None):
    if not description and not file_name:
        print("At least one search parameter must be specified")
        return

    gists = get_gists(username)
    if gists is None:
        print('Request failed')
        return
    if gists == []:
        print('Couldnt find gists for user {}'.format(username))
        return

    #Solution 1
    results = []
    for gist in gists:
        if description and description.lower(
        ) not in gist['description'].lower():
            continue
        if file_name:
            matched = False
            for json_fname in gist['files']:
                if file_name in json_fname:
                    matched = True
                    break
            if not matched:
                continue
        results.append(gist)
    return results
示例#6
0
def search_gists(username, description=None, file_name=None):
    if not description and not file_name:
        print("At least one search parameter must be specified")
        return
    
    results = []
    
    gists = get_gists(username)
    
    for gist in gists:
        if description and description.lower() not in gist['description'].lower():
            continue
            
        if file_name:
            found = False
            
            for fname, fbody in gist['files'].items():
                if file_name in fname:
                    found = True
                    break
            if not found:
                continue
            
        results.append(gist)
        
    return results
示例#7
0
def search_gists(username, description=None, file_name=None):
    if not description and not file_name:
        print("At least one search parameter must be specified")
        return None

    users_gists = get_gists(username)
    results = []

    for gist in users_gists:
        if description and description not in gist['description']:
            continue

        if file_name:
            matched = False

            for fname in gist['files']:
                if file_name.lower() in fname.lower():
                    matched = True
                    break

            if not matched:
                continue

#         if id and id not in gist['id']:
#             continue

        results.append(gist)
    return results
示例#8
0
def search_gists(username, description=None, file_name=None):
    if not description and not file_name:
        print("At least one search parameter must be specified")
        return None
    user_gists = get_gists(username)
    result = []

    for gist in user_gists:
        if description and description not in gist["description"]:
            continue
        if file_name:
            match = False
            for fname in gist["files"]:
                if file_name.lower() in fname.lower():
                    match = True
                    break
                if not match:
                    continue
        result.append(gist)
    return result
示例#9
0
def test_get_gists_user_not_found():
    responses.add(responses.GET, USER_NOT_FOUND_GIST_URL, status=404)
    gists = get_gists('xyznotexists')
    assert gists is None
示例#10
0
def test_get_gists():
    responses.add(responses.GET, USER_GIST_URL, json=test_data.SAMPLE_GISTS)
    gists = get_gists('santiagobasulto')
    assert len(gists) == 2