끄적끄적 인턴생활 (2020)
Azure Blob container 관리하기 (python)
jellylucy
2021. 12. 28. 13:06
1. Microsoft 에저 블롭 코드 이용해 프레임워크 설정
출처 입력
def blob_storage_connect(container_name):
try:
connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
# Create the BlobServiceClient object which will be used to create a container client
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
# Instantiate a ContainerClient
container_client = blob_service_client.get_container_client(container_name)
blobs_list = container_client.list_blobs()
return blobs_list
except Exception as ex:
print('Exception:')
print(ex)
1. 스토리지 계정의 연결 문자열을 가져온다
2. blob_service 클래스의 인스턴스 생성
3. 그다음 모르겠음 ㅠ
2. def cut_str(s, l)
출처 입력
def cut_str(s, l):
return [int(s[i:i+l]) for i in range(0, len(s), l)]
- list comprehension
[] 가 list를 의미하고
한 줄안에다가 for i in range 쓰고 그뒤에 for문 써도 됨.
- range( temp1, temp2, temp3)
temp1 : 시작범위 (0일때 생략가능)
temp2 : 마지막범위(지정된 숫자 바로 앞까지 생성
temp3 : 간격 지정한다(생략시 1로 처리)
def strdate_to_datetime
출처 입력
def strdate_to_datetime(str_date, str_time):
_date = cut_str(str_date, 2)
_date[0] += 2000
_time = cut_str(str_time, 2)
return datetime(*_date, *_time)
*_date *_time
-> * : all
date포함한 all을 가져옴
def making_dataframe
출처 입력
def making_dataframe(col_dict):
data_frame = pd.DataFrame([col_dict])
return data_frame
DataFrame in Pandas
: 2차원 테이블 데이터 구조갖는 자료형
def converting_df_to_excel
출처 입력
# https://blockdmask.tistory.com/429
def converting_df_to_excel(df, filename):
return df.to_excel("{}.xlsx".format(filename), encoding='utf-8')
-> 문자열 인자 처리 세가지 방법