这是文件代码python,我将其加载到aws ec2,如何在启动ec2时自动运行此文件。我使用它将数据从数据github自动更新为超集
def get_nameFile_current():
import datetime
#File dữ liá»u Äược lấy là file trÆ°á»c ngà y hiá»n tại 1 ngà y
Previous_Date = datetime.datetime.today() - datetime.timedelta(days=1)
Previous_Date = Previous_Date.strftime("%m-%d-%Y")
name_File = Previous_Date + ".csv"
return (name_File)
def importCsvIntoMySQL(url,table_name):
import pandas as pd
from sqlalchemy import create_engine, types
df = pd.read_csv(url, index_col=False)
print(df.head())
engine = create_engine(
'mysql://admin:tranduy2906@doan.c3ftrgdgjym4.us-east-1.rds.amazonaws.com/DATA') # enter your password and database names here
df.to_sql(table_name, con=engine, index=False, if_exists='append') # Replace Table_name with your sql table name
if __name__ == '__main__':
file_name=get_nameFile_current()
# cáºp nháºt dữ liá»u và o database thế giá»i
url_world='https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/'+file_name
importCsvIntoMySQL(url_world,'COVID_19')
# Cáºp nháºt dữ liá»u và o database US
url_us = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports_us/' + file_name
importCsvIntoMySQL(url_us, 'data_covid_us')