-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_remote_csv.py
33 lines (27 loc) · 999 Bytes
/
load_remote_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
import os
def load_remote_csv():
"""
Downloads a CSV file from a remote URL and saves it to a temporary location.
Returns:
None
Raises:
requests.RequestException: If the download fails.
"""
# URL of the remote CSV file (replace with actual URL)
url = "https://github.com/batchayw/tech-data-analysis/blob/main/broadband_data_zipcode.csv"
# Send a GET request to download the file
try:
response = requests.get(url)
response.raise_for_status() # Check for HTTP errors
except requests.RequestException as e:
print(f"Failed to download CSV: {e}")
raise
# Ensure the /tmp directory exists
os.makedirs("/tmp", exist_ok=True)
# Save the file to /tmp/remote_data.csv
with open("/tmp/remote_data.csv", "wb") as f:
f.write(response.content)
print("CSV file downloaded successfully to /tmp/remote_data.csv")
if __name__ == "__main__":
load_remote_csv()