0

I have a CSV file staged daily in a Firebase storage bucket. I want to download this updated CSV file to my local machine on daily basis.

Using the following Python code, I am able to generate a link where I can click and the download the file. However, I am wondering if I can download it without any need of clicking the link generated.

import datetime
import firebase_admin
from firebase_admin import credentials
from firebase_admin import storage

### Fetch the service account key JSON file contents
cred = credentials.Certificate("SDK_key.json")

### Initialize the app with a service account, granting admin privileges
app = firebase_admin.initialize_app(cred, {'storageBucket': 'XYZ.appspot.com',}, name='storage')

bucket = storage.bucket(app=app)

### Address of file to downloaded
blob = bucket.blob("test.csv")

### Generate a link and clicking on the link downloads the file
print(blob.generate_signed_url(datetime.timedelta(seconds=300), method='GET'))
Chris
  • 112,704
  • 77
  • 249
  • 231
  • I found solution to my problem through selenium automation to open the generated link dynamically and downloads the file on my local machine. I can read it in python from local machine and proceed For .json or .text files, we can again use selenium in python along with BeautifulSoup to directly copy text/json data in a variable. Refer to https://stackoverflow.com/questions/26661808/how-to-grab-from-json-in-selenium-python – Harpreet Singh Jul 21 '20 at 08:48

1 Answers1

0

I think you'll find your answer here.

@James Daniels points out that getSignedURL() is the key component for retrieving your designated file, but you can do so by using the Firebase Admin SDK (acts as a wrapper for Google's Cloud Storage SDK).

Alex Douglas
  • 183
  • 7
  • Last command in above given python code is generating the download link for me. That's not a problem. I want to download the file from this link directly through python itself without any manual intervention. As of now, I have to open this URL manually and then file gets downloaded – Harpreet Singh Jul 16 '20 at 04:07