Skip to content

Instantly share code, notes, and snippets.

View jsj14's full-sized avatar
💜
Tinkering

Julian jsj14

💜
Tinkering
View GitHub Profile
from google.cloud import storage
storage_client = storage.Client(project='your-project-id')
def list_blobs(bucket_name):
"""Lists all the blobs in the bucket"""
blobs = storage_client.list_blobs(bucket_name)
for blob in blobs:
print(blob.name)
from google.cloud import storage
storage_client = storage.Client(project='your-project-id') #add your ProjectID here
def delete_bucket(bucket_name):
"""Deletes a bucket. The bucket must be empty."""
# bucket_name = "your-bucket-name"
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
bucket.delete()
print("Bucket {} deleted".format(bucket.name))
from google.cloud import storage
storage_client = storage.Client(project='your-project-id') #add your ProjectID here
def create_bucket(dataset_name):
"""Creates a new bucket"""
print('function create_bucket called')
bucket = storage_client.create_bucket(dataset_name)
print('Bucket {} created'.format(bucket.name))
@jsj14
jsj14 / upload_from_memory_to_gcs
Created February 3, 2022 12:57
upload data from memory to gcs
def upload_blob(bucket_name, source_data, destination_blob_name):
"""Uploads a file to the bucket."""
print('function upload_blob called')
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_string(source_data)
print('File {} uploaded to {}.'.format(destination_blob_name, bucket_name))
@jsj14
jsj14 / fetch_data_upload_to_gcs
Last active February 4, 2022 03:47
Fetch public data and upload to a cloud storage
from flask import jsonify
from geopy.geocoders import Nominatim
import requests
from google.cloud import storage
import json
storage_client = storage.Client(project='your-project-id') #replace with your projectID from Home
def weather(request):
data = {"success": False}