How Do I Run A Python Script Automatically Every Day Online?

Asked one year ago
Answer 1
Viewed 462
1

Running a Python content could be basically as simple as opening your IDE or word processor and tapping the run button; be that as it may, assuming that the content must be executed day to day or week after week, you would rather not sit around idly rehashing these means again and again.

All things considered, you could computerize those contents by planning position that run your Python scripts at explicit times. In this article, I'll tell you the best way to do this on Macintosh and Windows utilizing the crontab and the assignment scheduler.

Booking Position on macOS
The Python script we will robotize it's calledexample.py. You can utilize any content you need to track.

import requests
import pandas as pd
from bs4 import BeautifulSoup

Date = today

headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
    'Accept-Language': 'en-US, en;q=0.5'}
URL = ['https://www.amazon.com/Dove-Intensive-Concentrate-Technology-Protects/dp/B0B1VVXTKL',
             'https://www.amazon.com/Dove-Intensive-Concentrate-Conditioner-Technology/dp/B0B1VXFLQ2']
data = []
for url in URL:
    webpage = requests.get(url, headers=headers)
    soup = BeautifulSoup(webpage.content)
    data.append({
        'Rank': soup.select_one('#detailBulletsWrapper_feature_div span:-soup-contains("Best Seller")').contents[2].get_text().split()[0],
        'Category': " ".join(soup.select_one('#detailBulletsWrapper_feature_div span:-soup-contains("Best Seller")').contents[2].get_text().split()[2:6]),
        'Date': Date
    })
    
df = pd.DataFrame(data)
# to local file
#pd.DataFrame(df).to_csv('myfile.csv', index=False)

#Export to onedrive
local_path = '/Users/ja/OneDrive - insidemedia.net/amzbestranktest.csv'
df.to_csv(local_path, index = False)

Greetings folks, I'm attempting to plan this content to run consistently at 8am. I have: I'm attempting to utilize timetable and print the present moment this. Yet, I don't know how to utilize that with the content that I have.

 

def amzbestrank():
    print()
    
Schedule.every().day.at("12:45").do(amzbestrank())

While True:
    schedule.run_pending()
    time.sleep(1)

#local drive Append 
#df.to_csv('myfile.csv', mode='a', header=False, index=False)

#Onedrive Append 
#df.to_csv(local_path, mode='a', header=False, index=False))
Read Also : How to find the best digital marketing agency for your business?
Answered one year ago Mercado   WolskiMercado Wolski