运行单击html按钮时将CSV转换为JSON的python脚本

python脚本最终应将其生成的JSON文件写入Firebase数据库。

import csv , json
import pandas as pd
import requests
from datetime import date
from pandas import DataFrame

url = "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/owid-covid-data.csv"
jsonFile='coviddata.json'

s = requests.get(url).content
longlat = pd.read_csv('countries.csv',keep_default_na=False,na_values=[""])
c=pd.read_csv(io.StringIO(s.decode('utf-8')))
mergedInner = pd.merge(left = c , right = longlat,left_on='location',right_on='location')
df = DataFrame(mergedInner,columns = 
['iso_code','location','date','total_cases','total_deaths','population','lat','lng'])
df.sort_values("iso_code", inplace = True) 

today = date.today()
currentDate= today.strftime("%Y-%m-%d")
dropNames = df[df['date']!= currentDate].index
df.drop(dropNames,inplace=True)

df.to_json(r'covidjson',orient="records")

我尝试使用.ajax,但是我不确定通常生成的json文件会放在哪里。

<input type="button" id='script' name="scriptbutton" value=" Run Script " onclick="goPython()">
    <script>
        function goPython(){
            $.ajax({
              url: "csvjson.py",
             context: document.body
            }).done(function() {
             alert('finished python script');;
            });
        }
    </script>