Skip to content

Instantly share code, notes, and snippets.

View shashankm28's full-sized avatar

Shashank Mishra shashankm28

View GitHub Profile
@shashankm28
shashankm28 / list_blob_to_csv.py
Last active March 9, 2021 13:20
List Azure container blobs using Python and write the output to a CSV file.
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
import csv
import sys
def create_csv(blob_list):
try:
header = ["blob_name"] # csv file header row (first row)
file_name = "blob_list_output.csv" # csv filename
with open(file_name, 'w', newline='', encoding="utf-8") as csv_file:
@shashankm28
shashankm28 / azure_create_csv.py
Created July 27, 2020 21:35
Create CSV file using iterator object | Azure Container
def create_csv(blob_list):
try:
header = ["blob_name"] # csv file header row (first row)
file_name = "blob_list_output.csv" # csv filename
with open(file_name, 'w', newline='', encoding="utf-8") as csv_file:
writer = csv.writer(csv_file)
writer.writerow(header) # write header
for blob in blob_list:
writer.writerow([blob])
@shashankm28
shashankm28 / azure_list_blobs.py
Last active July 27, 2020 21:36
List Azure container blobs using Python
def container_content_list(connection_instance, blob_path):
try:
blob_name_list = []
source_blob_list = connection_instance.list_blobs(name_starts_with=blob_path)
print (source_blob_list)
for blob in source_blob_list:
blob_name = blob.name.rsplit('/',1)[1]
blob_name_list.append(blob_name)
print (blob_name)
@shashankm28
shashankm28 / azure_sas_token.py
Created July 27, 2020 20:27
Connect to Azure Container using SAS Token
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
def azure_connect_sas_token(token, account_url, source_container_name):
try:
blob_source_service_client = BlobServiceClient(account_url = account_url, credential = token)
source_container_client = blob_source_service_client.get_container_client(source_container_name)
print ("SAS Token -- Connected.")
return source_container_client
except Exception as ex:
@shashankm28
shashankm28 / azure_sas_url.py
Last active July 27, 2020 20:18
Connect to Azure Container using SAS URL
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
def azure_connect_sas_url(source_container_sas_url, source_container_name):
try:
blob_source_service_client = BlobServiceClient(source_container_sas_url)
source_container_client = blob_source_service_client.get_container_client(source_container_name)
print ("SAS URL -- Connected.")
return source_container_client
except Exception as ex:
@shashankm28
shashankm28 / azure_connection_string.py
Created July 27, 2020 19:36
Connect to Azure Container using Connection String
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
def azure_connect_conn_string(source_container_connection_string, source_container_name):
try:
blob_source_service_client = BlobServiceClient.from_connection_string(source_container_connection_string)
source_container_client = blob_source_service_client.get_container_client(source_container_name)
print ("Connection String -- Connected.")
return source_container_client
except Exception as ex:
@shashankm28
shashankm28 / windows_no_lock.py
Last active January 28, 2022 17:14
Prevent Windows from locking by simulating keypress | Python
## This script will simulate a keypress and prevent Windows from locking
import pyautogui
import time
def no_lock(button):
try:
print ('Press CTRL+C to stop.')
while True:
pyautogui.press(button) # Key pressed