I'm trying to running my Python Scripts every day , I need a way to run my Python Scripts periodically and automatically. first I'm trying to make bat file but it always failed.. I don't know why. FYI I got 2 python exe and its makes me confuse to choose what should I use, so I try in two place but both failed.
because its failed, I tried another way which fills the arguments and starts like this, but it's failed too, when I'm trying to run the task, it's just always show command prompt and immediately closed but didn't do anything, I'm trying with ps1 too but its the same.
i tried to execute the command python emas_.py like alperindo said but its stil gives me error
here's my code in python
import pandas as pd
import requests
from bs4 import BeautifulSoup
url = "https://www.indexmundi.com/commodities/?commodity=gold&months=300"
r = requests.get(url)
html = r.text
soup = BeautifulSoup(html)
table = soup.find('table', {"class": "tblData"})
rows = table.find_all('tr')
data = []
for row in rows[1:]:
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
data.append([ele for ele in cols if ele])
result = pd.DataFrame(data, columns=['month', 'price', 'change'])
result['month'] = pd.to_datetime(result["month"])
result.to_csv("emas_.csv", index=False)
df = pd.read_csv("emas_.csv")
pd.set_option('display.max_rows', df.shape[0]+1)
print(df)
import pyodbc
from sqlalchemy import create_engine
server = 'MSHULHAN\SQLEXPRESS'
database = 'daming'
engine = create_engine('mssql+pyodbc://' + server + '/' + database + '?trusted_connection=yes&driver=ODBC+Driver+13+for+SQL+Server')
#engine = create_engine('mysql://root:@localhost/daming') # enter your password and database names here
col_names = ["month", "price", "change"]
df = pd.read_csv("emas_.csv",sep=',',quotechar='\'',encoding='utf8', names=col_names,skiprows = 1) # Replace Excel_file_name with your excel sheet name
df.to_sql('emas',con=engine,index=False,if_exists='replace') # Replace Table_name with your sql table name
I'm using NSSM for that: https://nssm.cc/
It will install your Python script as a Windows service. Just make sure that in the Application
tab, you enter the path to your Python in the Path
field and your Python script in the Arguments
field. Enter valid paths in the Error
and Output
field in the I/O
tab to be able to debug if the script doesn't start right away.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.