name: Cache Playwright browsers uses: with: We cache this here so it # isn't downloaded every time we run. Python-version: '3.10 ' cache: 'pip ' # shot-scraper uses Playwright, which # needs to download a custom copy of # Firefox. name: Configure Python with pip cache uses: with: # Run at 14:13 UTC every day # which is 6:13am Pacific time # Run when I click "run workflow" # in the GitHub UI - for debugging workflow_dispatch: I pasted the entire JSON authentication file into a new Actions secret for the repository called MASTODON_TOOT_CONFIG. Writes this file back to the GitHub repository so I can see when it last ran.Uses toot post to post that screenshot to Mastodon.Creates that ~/.config/toot/config.json file from a GitHub Actions secret.Takes the screenshot and writes it to a temporary file.Installs its dependencies ( shot-scraper and toot).The workflow runs once a day and does the following: My entire bot is implemented as a GitHub Actions scheduled workflow. Read more about shot-scraper in shot-scraper: automated screenshots for documentation, built on Playwright. The screenshot is taken in retina mode (2x the pixel density) and saved to a file called /tmp/covid.png. It waits 3 seconds, then takes a screenshot of JUST the first iframe on the page ( -s means "selector"). This loads the page in a headless (no visible window) Firefox instance. I'm using my shot-scraper tool to take the screenshot, like this: shot-scraper \ Toot can support multiple authenticated users and let you switch between them, but for this bot we just need the one. "client_id": "cTQfcJy9EhlIUSGPRx90PRnMx_RroBuLUw8WcMvguD0 ", Toot then creates a file in ~/.config/toot/config.json. If you say yes, it gives you an authorization code which you then paste back into the command. It will ask for your Mastodon instance (my private one is ) and spit out a link to click on.Ĭlick that link and your Mastodon server will ask you if you want to authorize the tool. The toot post command only works if you authenticate first. The alt text here is terrible - I've had an open issue to fix that for a while, but it's not an easy thing to implement properly. You can pass the combination of -media and -description up to four times. description "Screenshot of the latest Covid charts" Here's the command that does that: toot post "Latest Covid sewage charts for the SF Bay Area " \ The bot uses toot to send a message with an attached image to Mastodon. ![]() It's now up and running in its new home at - here's how the new bot works. My Twitter bot posts a screenshot of the latest Covid sewage data for parts of the San Francisco Bay Area every morning. Twitter announced today that they'll be ending free API access for bots. Simon Willison’s TILs Building Mastodon bots with GitHub Actions and toot Building Mastodon bots with GitHub Actions and toot | Simon Willison’s TILs
0 Comments
Leave a Reply. |