Skip to content

Instantly share code, notes, and snippets.

Forked from agentphantom/
Created November 6, 2018 15:47
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 kriscarilloxyz/b6c3af30c42c3b25b8cf6fe4fe5cf2f8 to your computer and use it in GitHub Desktop.
Save kriscarilloxyz/b6c3af30c42c3b25b8cf6fe4fe5cf2f8 to your computer and use it in GitHub Desktop.
A script that loads a GitHub repositories info and updates a Firebase database with it.
You will require the following database rules:
"rules": {
"repositories": {
".write": "auth != null",
".read": true
import requests
# Firebase Constants
# You can create a new username with password in the Auth section from the Firebase console.
FIREBASE_PROJECTID = "" # Example: my-project-123456
FIREBASE_NODE = "repositories" # Must be the same as the one in the rules.
GITHUB_ACCOUNT = "PhantomAppDevelopment"
ACCOUNT_TYPE = "orgs" # Can be "orgs" or "users"
def firebase_login():
"""Logins the user to your Firebase database."""
base_url = "{0}".format(
credentials = dict()
credentials["email"] = FIREBASE_EMAIL
credentials["password"] = FIREBASE_PASSWORD
credentials["returnSecureToken"] = True
with, json=credentials) as login_response:
# IF the login was successful we return the 'idToken', else we exit the program.
if login_response.status_code == 200:
return login_response.json()["idToken"]
def load_profile_repositories():
"""Loads the profile repositories and converts the relevant data into a dictionary."""
auth_token = firebase_login()
base_url = "{0}/{1}/repos".format(
with requests.get(base_url) as profile_contents:
for item in profile_contents.json():
repo_data = dict()
repo_data["id"] = item["id"]
repo_data["name"] = item["name"]
repo_data["url"] = item["url"]
repo_data["stars"] = item["stargazers_count"]
repo_data["forks"] = item["forks_count"]
repo_data["watchers"] = item["watchers_count"]
repo_data["issues"] = item["open_issues_count"]
save_to_firebase(repo_data, auth_token)
def save_to_firebase(repo_data, auth_token):
Saves the repository data to the specified Firebase node.
We use the repo name as its id for the Firebase database.
base_url = "https://{0}{1}/{2}.json?auth={3}".format(
FIREBASE_PROJECTID, FIREBASE_NODE, repo_data["name"], auth_token)
# We use the PATCH verb and send the data as a JSON string.
with requests.patch(base_url, json=repo_data) as response:
# We now determine the status of the operation.
if response.status_code == 200:
print("Successfully updated: {0}".format(repo_data["name"]))
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment