Python Forum
How to implement APScheduler in Python 3.6?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to implement APScheduler in Python 3.6?
#1
Hi All,

I have written a python script (myfile.py) which scrapes the product related data from an e-commerce site and store in mysql db.

Now I want to schedule this script to refresh once a week.

I have installed the APScheduler for this work but need your help to implement this-
https://apscheduler.readthedocs.io/en/la...guide.html

Can anyone please share his knowledge?
Reply
#2
you should know the drill already - what have you tried, post code and ask questions, etc...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Read first the provided examples: https://github.com/agronholm/apscheduler...schedulers

https://github.com/agronholm/apscheduler...kground.py
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
Yes, I have seen the examples.
But I am not sure where to use my python script (myfile.py) in a scheduler.
Reply
#5
following is the content of my python script-
def get_soup(url):
soup = None
try:
    response = requests.get(url)
    if response.status_code == 200:
        html = response.content
        soup = BeautifulSoup(html, "html.parser")
    return soup

def get_category_urls(url):
soup = get_soup(url)
cat_urls = []
try:
    categories = soup.find('div', attrs={'id': 'menu_oc'})
    if categories is not None:
        for c in categories.findAll('a'):
            if c['href'] is not None:
                cat_urls.append(c['href'])
    return cat_urls

def get_product_urls(url):
 soup = get_soup(url)
 prod_urls = []
 if soup.find('div', attrs={'class': 'pagination'}):
     for link in soup.select('div.links a'):
         if link.string.isdecimal():  # dump next and last links
             prod_urls.append(link['href'])
 print("Found following product urls::", prod_urls)
 return prod_urls

if __name__ == '__main__':
category_urls = get_category_urls(URL)
product_urls = get_product_urls(URL)
#TODO upload in db
Now I have created a scheduler-refresh.py with following content
import schedule
import time
def job():
    //how to call myfile.py here?
    print("refreshing...")
schedule.every().week.at("10:30").do(job)
while 1:
    schedule.run_pending()
    time.sleep(1)
Here I don;t know how to call myfile.py. Can you help me?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use python to implement one QA task taiqixp 2 3,078 Jan-10-2018, 12:28 PM
Last Post: squenson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020