-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_repos.py
35 lines (29 loc) · 1.42 KB
/
python_repos.py
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
# Make an API call and store the response.
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars' #Store the URL of the API call
headers = {'Accepts': 'appliaction/vnd.github+json'}
r = requests.get(url, headers=headers)
print(f"Status code: {r.status_code}") #A status code of 200 indicates a successful response.
# Store API response in a variable.
response_dict = r.json()
print(f"Totla repositories: {response_dict['total_count']}")
#Explore information about the repositories.
repo_dicts = response_dict['items']
print(f"Repositories returned: {len(repo_dicts)}")
# Examine the first repository.
#repo_dict = repo_dicts[0]
print("\nSelected information about each repository: ")
for repo_dict in repo_dicts:
print("\nSelected information about first repository: ")
print(f"Name: {repo_dict['name']}") #Name of the repository
print(f"Owner: {repo_dict['owner']['login']}") #Owner of the repository
print(f"Stars: {repo_dict['stargazers_count']}") #Stars on the repository
print(f"Repository: {repo_dict['html_url']}") #Repository URL
print(f"Created: {repo_dict['created_at']}") #Date of creation
print(f"Updated: {repo_dict['updated_at']}") #Last Update
print(f"Description: {repo_dict['description']}") #Description of the repository
#print(f"\nKeys: {len(repo_dict)}")
#for key in sorted(repo_dict.keys()):
# print(key)
# Process results.
#print(response_dict.keys())