Пример #1
0
def search_person():
    name = request.args.get('n')
    if not name:
        return render_template('index.html', error='You must provide a name.')
    result = get_person(query=name)
    return render_template('person.html',
                           search_result=result,
                           query=name,
                           info='')
Пример #2
0
def get_r2_d2():
    return get_person(3)
Пример #3
0
def get_luke_skywalker():
    return get_person(1)
Пример #4
0
def person(person_id):
    info, jobs = get_person(person_id)
    return render_template('person.html', info=info, jobs=jobs)
Пример #5
0
def more_person_results(query, page):
    return get_person(query=query, page=page)
Пример #6
0
# pobieramy konkretny zasób
    response = requests.get(url)
    response_data = handle_response(response)

    # zwróc uwagę na konstrukcję get z domyślną wartością
    count = response_data.get('count', None)

    print(f'Ilość zasobów o nazwie "{resource_name}" wynosi: {count}')

if __name__ == '__main__':
    display_api_info()
    print('-' * 40)

    # literówka jest zamierzona
    display_resource_count(resource_name='peopxle')
    print('-' * 40)

    # bez literówki w nazwie zasobu
    display_resource_count(resource_name='people')
    print('-' * 40)

    # pobieramy listę bohaterów
    print(get_people_list())
    print('-' * 40)

    # pobieramy pełen zasób (szczegóły dotyczące bohatera #1)
    person = get_person(1)
    print(person['name'])
    print('-' * 40)
Пример #7
0
def get_people_from_range(a=1, b=10):
    # list comprehension
    return [get_person(id) for id in range(a, b)]
Пример #8
0
def save_to_plain_text(filename, data):
    with open(filename, 'w') as data_file:
        for key, value in data.items():
            data_file.write(f'{key}={value}\n')


if __name__ == '__main__':
    from helpers import get_person

    luke = get_person(1)
    save_to_plain_text('luke.txt', luke)