Take screenshots from a list of urls using playright and checks them into the repo using github actions. Based on Simon Willison's shotscraper
Watch the video tutorial:
This example shows how to run a Python script as cron job with GitHub Actions. It calls an API once a week (could be any schedule you want), logs the response in status.log
, and automatically pushes the changes to this repo.
- The code to automatically take a screenshot with playright is implemented in
main.py
- Inspect and configure cron job in GitHub Action
.github/workflows/actions.yml
- It installs and use third party packages from
requirements.txt
- Secret environment variables can be used. Set secrets in Settings/Secrets/Actions -> 'New repository secret'. Use the same secret name inside
actions.yml
andmain.py
The configuration is done via a TOML file called config.toml It contains a list of locations. Each location can have several streets. Every location/street must have an URL. Example:
>>> config = {
... 'Location1': {
... 'StreetA': {
... 'url': '<https://www.google.com/maps/>...'
... },
... 'StreetB': {
... 'url': '<https://www.google.com/maps/>...'
... }
... },
... 'Location2': {
... 'StreetC': {
... 'url': '<https://www.google.com/maps/>...'
... }
... }
... }
First, a GUI must be started to click on a map at what position the colors must be sampled.
python measure_points_gui.py shots/leuven_geldenaaksevest_20231017-114230.png -direction from
A visualisation of the screenshot of the argument will appear. It's handy to use the magnifier glass on osx: Press option-command 8
Next click in the position were colors must be sampled.
Press q.
In this case, the following will be added to the config.yml file:
"point_from": [ [ 887, 78,], ..., [ 418, 712,],]
Open notebook get_traffic_info_from_screenshot.ipynb.
Adapt the global variables LOCATION, STREET and DIRECTION in the third cell:
# Which street to analyse and in what direction
LOCATION = "leuven"
STREET = "tiensestraat"
DIRECTION = "to" # must be "to" the crossing or away "from" the crossing
Run the notebook until the end. The results are in the figs directory.
To locally test main.py python script follow these steps:
Make sure you have Python 3.11 or later installed on your system.
To install Poetry, you can use the official installer provided by Poetry. Do not use pip.
Clone the repo filedrukte_tiensepoort
repository from GitHub:
git clone hhttps://github.com/cast42/filedrukte_tiensepoort
Use Poetry to install the package and its dependencies:
poetry install
or you can create a virtualenv with poetry and install the dependencies
poetry shell
poetry install