Reputation: 11
I am using both firebase Real-Time Database and Firebase Storage, and I am getting a problem with the default app. The storage commands go to the default app which is the Database app, and don't find the needed data.
!pip install pygsheets
import pygsheets
import pandas as pd
from datetime import datetime
import pytz
from pydrive.auth import GoogleAuth
from google.colab import drive
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
from firebase_admin import credentials, initialize_app, storage, db
import matplotlib.pyplot as plt
cred = credentials.Certificate('key.json')
database = initialize_app(cred, {'databaseURL': "https://project-147196781260390231-default-rtdb.europe-west1.firebasedatabase.app/"})
imgStorage = initialize_app(cred, {'storageBucket': 'project-147196781260390231.appspot.com'}, name = 'bucket')
dt = datetime.now(cairoTz)
y = dt.year
M = dt.month
d = dt.day
h = dt.hour
m = dt.minute
s = dt.second
lhour = df.loc\[(df\['Hour'\] == h) | ((df\['Hour'\] == h - 1) & (df\['Minute'\] \>= m))\]
lday = df.loc\[(df\['Day'\] == d)| ((df\['Day'\] == d - 1) & (df\['Hour'\] \>= h))\]
lall = df
tempHplt = plt.figure(figsize=(10, 3))
tempHplt_name = 'tempHplt.png'
xTemph = lhour\['Minute'\].astype(int).astype(str)
yTemph = lhour\['Temperature'\]
plt.plot(xTemph, yTemph)
plt.savefig('tempHplt.png')
file_path = tempHplt_name
bucket = storage.bucket() # storage bucket
blob = bucket.blob(file_path)
blob.upload_from_filename(file_path)
I tried putting the initialize app in a variable and calling storage function from it, but an error was given.
AttributeError: 'App' object has no attribute 'storage'
If not using the variable, the error is the following:
ValueError: Storage bucket name not specified. Specify the bucket name via the "storageBucket" option when initializing the App, or specify the bucket name explicitly when calling the storage.bucket() function.
Upvotes: 0
Views: 109
Reputation: 11
okay so the solution is specifying the app
bucket = storage.bucket(imgStorage) # storage bucket
Upvotes: 1