firebase.py 619 B

12345678910111213141516171819
  1. import firebase_admin
  2. from firebase_admin import credentials
  3. from firebase_admin import db
  4. # Loads the parsed data into the Firebase DB
  5. def pushToFirebase(data):
  6. # Fetch the service account key JSON file contents
  7. cred = credentials.Certificate('key/serviceAccountKey.json')
  8. # Initialize the app with a service account, granting admin privileges
  9. firebase_admin.initialize_app(cred, {
  10. 'databaseURL': open('key/databaseURL.txt', 'r').read()
  11. })
  12. # As an admin, the app has access to read and write all data, regradless of Security Rules
  13. ref = db.reference('/table')
  14. ref.set(data)