A demonstration on how to use Python to automate the process of getting the latest camera’s prices from Moment website by using Cloud Run.
Cloud Run is a managed compute platform that enables you to run containers that are invocable via requests or events. Cloud Run is serverless.
Every day at 9am Cloud Scheduler will send a HTTP POST request to Cloud Run, Cloud Run will start the automation by referencing the step in Dockerfile. The Dockerfile will create a docker container with:
- Python 3.8 image
- Manually install all the missing libraries
- Install Chrome
- Install Python dependencies
- Copy local code to container image
- Run the web server on container startup
- Once the container has successfully been built, it will run the main.py file.
Main.py file will create a server using Python Flask. Cloud Run will start the process by POST to the main function.
The process will:
- Access Google Spreadsheet
- Create a chrome web driver
- Go to moment website
- Auto-scrolling with Selenium
- Get the website HTML with BeautifulSoup
- Extract the selected data
- Save it in Google Spreadsheet
- Get the formatted data from Google Spreadsheet
- Send a message to Telegram using Telegram API and webhook
Once all the process had been successfully ended. Cloud Run will stop the container.
- Python
- Selenium
- Flask
- BeautifulSoup
- Requests
- Google Spreadsheet
- Google Cloud Run