在GCP中希望可以將先前上傳到值區的檔案解析後在別的值區另存成csv檔
修改後會顯示OSError: [Errno 30] Read-only file system: 'emic_text_1628469624.xml.csv'
不太懂新增一個csv檔為什麼會被回報只能讀
請問問題出在哪呢,謝謝各位大大
#開啟先前上傳的檔案
def main(event, context):
download_blob(event['bucket'], event['name'], '/tmp/'+event['name'])
filename = f"{event['name']}.csv"
pat = '/tmp/'+event['name']
_emic_csv_writer(pat , filename)
upload_blob("emic-csv-cla", "/tmp/"+filename, filename)
#將該檔案解析後儲存為csv檔
def _emic_csv_writer(pat , filename):
xmlparse = ET.parse( pat )
root = xmlparse.getroot()
rows = []
cnt = 0
for i in root[1].findall('{http://emic.eoc.gov.tw/disaster_info}DISASTER_DATA'):
print(cnt)
cnt += 1
CASE_ID = i.find("{http://emic.eoc.gov.tw/disaster_info}CASE_ID").text
CASE_DT = i.find("{http://emic.eoc.gov.tw/disaster_info}CASE_DT").text
CASE_LOC = i.find("{http://emic.eoc.gov.tw/disaster_info}CASE_LOC").text
DISASTER_MAIN_TYPE_NODE = i.find("{http://emic.eoc.gov.tw/disaster_info}DISASTER_MAIN_TYPE")
DISASTER_MAIN_TYPE = "None" if DISASTER_MAIN_TYPE_NODE is None else DISASTER_MAIN_TYPE_NODE.text
CASE_DESCRIPTION = i.find("{http://emic.eoc.gov.tw/disaster_info}CASE_DESCRIPTION").text
print(CASE_ID)
rows.append({"CASE_ID": CASE_ID,
"CASE_DT": CASE_DT,
"CASE_LOC": CASE_LOC,
"DISASTER_MAIN_TYPE": DISASTER_MAIN_TYPE,
"CASE_DESCRIPTION": CASE_DESCRIPTION
})
df = pd.DataFrame(rows)
df.to_csv( filename , encoding = 'utf-8')