Skip to content

Instantly share code, notes, and snippets.

@fsiddiqi
Created October 1, 2014 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsiddiqi/f692270d7f6b63828067 to your computer and use it in GitHub Desktop.
Save fsiddiqi/f692270d7f6b63828067 to your computer and use it in GitHub Desktop.
Read projects list from GitHub and insert MongoDB
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