From 55d8941e09016f59285ed27e270307142a73eb68 Mon Sep 17 00:00:00 2001 From: Jiachen Wang Date: Wed, 15 Feb 2023 14:51:57 +0800 Subject: [PATCH] Update crypto_data_extraction.py Avoid empty rows when write to csv, otherwise would lead to errors when copying csv. Signed-off-by: Jiachen Wang --- crypto_tutorial/crypto_data_extraction.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto_tutorial/crypto_data_extraction.py b/crypto_tutorial/crypto_data_extraction.py index c07aa31..ca3c540 100644 --- a/crypto_tutorial/crypto_data_extraction.py +++ b/crypto_tutorial/crypto_data_extraction.py @@ -52,7 +52,7 @@ cryptoDict = dict(data1) #write to CSV -with open('coin_names.csv', mode = 'w') as test_file: +with open('coin_names.csv', mode = 'w', newline='') as test_file: test_file_writer = csv.writer(test_file, delimiter = ',', quotechar = '"', quoting=csv.QUOTE_MINIMAL) for coin in cryptoDict.values(): name = coin['Name'] @@ -79,7 +79,7 @@ res_json = json.loads(res.decode('utf-8')) data = res_json['Data'] # write required fields into csv - with open('crypto_prices.csv', mode = 'a') as test_file: + with open('crypto_prices.csv', mode = 'a', newline='') as test_file: test_file_writer = csv.writer(test_file, delimiter = ',', quotechar = '"', quoting=csv.QUOTE_MINIMAL) for day in data: rawts = day['time'] @@ -116,7 +116,7 @@ res_json = json.loads(res.decode('utf-8')) data = res_json['Data'] # write required fields into csv - with open('btc_prices.csv', mode = 'a') as test_file: + with open('btc_prices.csv', mode = 'a', newline='') as test_file: test_file_writer = csv.writer(test_file, delimiter = ',', quotechar = '"', quoting=csv.QUOTE_MINIMAL) for day in data: rawts = day['time'] @@ -147,7 +147,7 @@ res_json = json.loads(res.decode('utf-8')) data = res_json['Data'] # write required fields into csv - with open('eth_prices.csv', mode = 'a') as test_file: + with open('eth_prices.csv', mode = 'a', newline='') as test_file: test_file_writer = csv.writer(test_file, delimiter = ',', quotechar = '"', quoting=csv.QUOTE_MINIMAL) for day in data: rawts = day['time']