My homework is to plot some data using canvasJS. My source has to be gotten from
ID: 3912691 • Letter: M
Question
My homework is to plot some data using canvasJS. My source has to be gotten from a website, where they have a download option to provide a csv file with the date. I know how to read the csv file and plot it using canvasJS. What I do not know, is how to code the part where the programs go to the URL whatever and download it to bring the CSV file.
At the moment, what I have is that I manually copy a csv file in my local directory and do the rest. My issue is how to get it automatically. I am working with js, python, ...
$.get("name_of_the_file.csv"), function(data) { ......
Explanation / Answer
Programs go to the URL whatever and download it to bring the CSV file:
import requests
file_url = "YOUR_CSV_FILE_URL_HERE"
# URL of the csv file to be downloaded is defined as file_url
r = requests.get(file_url) # create HTTP response object
# send a HTTP request to the server and save
# the HTTP response in a response object called r
with open("python_demo.csv",'wb') as f:
# Saving received content of file in
# binary format
# write the contents of the response (r.content)
# to a new file in binary mode.
f.write(r.content)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.