-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_repos.py
More file actions
35 lines (29 loc) · 1.21 KB
/
Copy pathpython_repos.py
File metadata and controls
35 lines (29 loc) · 1.21 KB
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
30
31
32
33
34
35
import requests
# Creating an API call AND saving the response
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
headers = {'Accept': 'application/vnd.github.v3+json'}
r = requests.get(url, headers=headers)
print(f'Status code: {r.status_code}')
# Saving the API response in a variable
response_dict = r.json()
print(f"Total repositories: {response_dict['total_count']}")
# Analyzing repository information
repo_dicts = response_dict['items']
print(f'Repositories returned: {len(repo_dicts)}')
# Analysis of the first repository
repo_dict = repo_dicts[0]
print(f'\nKeys: {len(repo_dict)}')
print('\nSelected information about each repository:\n')
for repo_dict in repo_dicts:
print(
"#----------------------------------------------#",
f"\nName: {repo_dict['name']}",
f"\nOwner: {repo_dict['owner']['login']}",
f"\nStars: {repo_dict['stargazers_count']}",
f"\nRepository: {repo_dict['html_url']}",
f"\nCreated: {repo_dict['created_at']}",
f"\nUpdated: {repo_dict['updated_at']}",
f"\nDescription: {repo_dict['description']}",
"\n#----------------------------------------------#\n")
# Processing results
print(response_dict.keys())