I am experimenting with Python. What I would like to achieve is using the Github API, I would like to fetch the top 10 most starred public repositories that are written in Python language and are created since last month. Could anyone give me tips on how I could achieve that?
Until now I have managed to achieve the following:
import pandas as pd
import requests
from datetime import datetime
df = pd.DataFrame(columns=['repository_ID', 'name', 'URL', 'created_date', 'description', 'number_of_stars'])
results = requests.get('https://api.github.com/search/repositories?q=language:python&sort=stars&order=desc').json()
for repo in results['items']:
d_tmp = {'repository_ID': repo['id'],
'name': repo['name'],
'URL': repo['html_url'],
'created_date': datetime.strptime(repo['created_at'], '%Y-%m-%dT%H:%M:%SZ'),
'number_of_stars': repo['stargazers_count']}
df = df.append(d_tmp, ignore_index=True)
print d_tmp
This gives me the following result for the most viewed sorted by star descending:
{'URL': u'https://github.com/faif/python-patterns', 'repository_ID': 4578002, 'number_of_stars': 18103, 'name': u'python-patterns', 'created_date': datetime.datetime(2012, 6, 6, 21, 2, 35)}
What I am stuck on is : How to get the same result for last two months and for top 10 repositories? I am thankful for all the valueable information.
1. freeCodeCamp / freeCodeCamp (⭐341k ) It's impossible you haven't heard of freeCodeCamp but you may not know it's the most starred repository in GitHub. Several free developer certificates are available at freeCodeCamp.org.
Hitting https://api.github.com/users/USERNAME/repos will list public repositories for the user USERNAME.
The Check Runs API enables you to build GitHub Apps that run powerful checks against code changes in a repository. You can create apps that perform continuous integration, code linting, or code scanning services and provide detailed feedback on commits.
Being the vast code repertoire it is, GitHub does a wonderful job of not just giving you the knowledge about Python, but it does so by giving you a hands-on feel of working with a source code management platform. Being this versatile naturally makes Python an easy choice for various projects today.
You can use the created
parameter of the github api. So to get the python repos since month 9 sorted by stars you can do the following request.
https://api.github.com/search/repositories?q=created:">2018-09-30"language:python&sort=stars&order=desc
Then to get the top 10 repos you can do:
top_ten = results['items'][0:10]
If you want to restrict the number of items returned on the api call, you can use the per_page=10
parameter. The query below does the same as above, but returns only 10 results.
https://api.github.com/search/repositories?q=created:">2018-09-30"language:python&sort=stars&order=desc&per_page=10
Good luck on your projects!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With