-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_repos.py
More file actions
40 lines (30 loc) · 1.39 KB
/
python_repos.py
File metadata and controls
40 lines (30 loc) · 1.39 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
36
37
38
39
40
import requests
def call_api():
"""Creates the api call and checks the response"""
url = "https://api.github.com/search/repositories"
query = "?q=language:python+sort:stars+stars:>10000"
api_query_url = "".join([url, query])
headers = {"Accept": "application/vnd.github.v3+json"}
response = requests.get(api_query_url, headers=headers)
# covnert the response into a dictionary
response_dict = response.json()
print(f"Status code: {response.status_code}")
print(f"Total repositories: {response_dict['total_count']}")
print(f"Complete results: {not response_dict['incomplete_results']}")
# check length of responses
repo_dicts = response_dict["items"]
print(f"Repositories returned: {len(repo_dicts)}")
return repo_dicts
def print_selected_info():
"""prints summary information about repos"""
repo_dicts = call_api()
print("\nSelected information about first repository:\n")
# loop through the dictionary and print the summary info, limiting descrptions to 200 chars
for repo in repo_dicts:
print(f"\nName: {repo['name']}")
print(f"Owner: {repo['owner']['login']}")
print(f"Stars: {repo['stargazers_count']}")
print(f"Respository: {repo['html_url']}")
print(f"Created: {repo['created_at']}")
print(f"Updated: {repo['updated_at']}")
print(f"Description: {repo['description']}"[:200])