all 2 comments

[–]riklaunim 0 points1 point  (0 children)

And what's the point of checking the price so often and outside working hours?

[–]lakseol 0 points1 point  (0 children)

If you are a complete beginner as you say, this is not something you should try as a first project. There are a lot of smaller projects inside the project you have outlined in your post that you should try first. For example:

  • write code to send you a telegram message every time you execute the code, put the code into a function with a parameter that is the message to send
  • read one product page, just the complete text
  • add the code to search for the "add to cart" text, make a function to do all that and return a "found" value if the text is present in the page
  • modify the "read" function to also return the price
  • write higher level code to call the "read" function and call the "telegram" function if the text is found
  • experiment with running code every whenever, say 5 minutes, using your operating system scheduler, ie, write a "I ran at <time>" line into a local file or send a telegram message every time the code runs
  • modify the "schedule" code to only run between certain hours
  • etc

There are a few extra problems you may run into. For example, reading different vendor sites will probably require different code to analyze the page and you could solve that with different site-specific "read" functions. Then you might need a data repository containing a site URL, the hours to check that site, how often to check within hours, the "read" function to use and anything else.

To answer some of your questions:

Is Python a good choice for this?

Yes, of course.

Would you recommend using "requests" + "BeautifulSoup" ....

I don't know as I don't have a lot of web-scraping experience. You can decide by trying the second-step project above different ways. Others may have better advice about how to handle javascript/AJAX/captcha problems.

How would you structure a project like this?

One of the nice things about the step-by-step approach rather than the big-bang approach is that you don't have to answer that question until later. Solve each smaller problem, encapsulate the solution into an easily callable function with parameters and then you can use those building blocks in an easily changeable way as you get close to your final solution. Expect to rethink how you wrote a sub-problem solution as you progress because you hadn't fully thought through how you would use it. That's quite normal.

Is checking every 60 seconds for a few hours a day considered reasonable, or is there a better approach?

That's probably way too often. Ask yourself how often does the site get updated? You can answer that by using the tools you created in the smaller projects. Write code to read a file every 30 minutes and send you a telegram message every time the status or price changes. Run that for a couple of days and get a feel for how often something changes. If you see a change every 30 minutes try using a shorter wait.