-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathtask-1.py
More file actions
29 lines (26 loc) · 950 Bytes
/
task-1.py
File metadata and controls
29 lines (26 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
1. Посмотреть документацию к API GitHub, разобраться как вывести список репозиториев для конкретного пользователя,
сохранить JSON-вывод в файле *.json.
"""
import requests
import json
def get_json(url: str) -> dict:
"""
Получение json по url
:param url: Ссылка
:return:
"""
response = requests.get(url)
if response.status_code != 200:
raise requests.ConnectionError
return response.json()
USERNAME = 'eadevlab'
url = 'https://api.github.com/users/%s/repos' % USERNAME
try:
repos_info = get_json(url)
repo_names = [_['name'] for _ in repos_info ]
with open('./repos.json', 'w') as f:
json.dump(repo_names, f)
print('Список репозиториев:', *repo_names, sep='\n')
except requests.ConnectionError:
print('Возникла ошибка')