Created
October 1, 2014 19:18
-
-
Save fsiddiqi/f692270d7f6b63828067 to your computer and use it in GitHub Desktop.
Read projects list from GitHub and insert MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
# Get list of projects from Github | |
def getProjects(): | |
url = "https://api.github.com/search/repositories?q=forks%3A%22%3E+100%22&sort=stars&order=desc" | |
r = requests.get(url) | |
projects = r.json() | |
return projects | |
# Insert projects into MongoDB using REST API | |
def addProjects(projects): | |
apiKey = "<Mongolab API KEY HERE>" | |
database = "ossrank" | |
collection = "projects" | |
url = "https://api.mongolab.com/api/1/databases/"+ database \ | |
+"/collections/"+ collection +"?apiKey=" + apiKey | |
headers = {'content-type': 'application/json'} | |
for p in projects['items']: | |
r = requests.post(url, data=json.dumps(p), headers=headers) | |
ret = r.json() | |
print ret | |
if __name__ == '__main__': | |
projects = getProjects() | |
addProjects(projects) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment