DEV Community

Martin Ratinaud
Martin Ratinaud

Posted on • Edited on

Github optimal cron for twitter posting

Hi all

Working on a FREE online staking and rewards crypto rates comparator, I wanted to tweet stuff based on the data I collect. For example, an increase of a rate, or a new coin.

For this, when I retrieve the data, I populate a mongo collection with the text I want to share and the destination network (mainly twitter and reddit).

I also made a whole framework to have different variations of texts and, of course, markdown version (for reddit) and text version (for twitter)

Now, with this collection filled, I wanted to tweet those informations on the best schedule possible, as Buffer does.

To do this, I discovered Github Actions cron functionality.

name: optimal-cron-for-twitter

on:
  schedule:
    - cron: '58 17 * * MON'
    - cron: '49 17 * * MON'
    - cron: '32 13 * * TUE'
    - cron: '58 17 * * TUE'
    - cron: '49 21 * * TUE'
    - cron: '32 13 * * WED'
    - cron: '58 17 * * WED'
    - cron: '49 21 * * WED'
    - cron: '32 13 * * THU'
    - cron: '58 17 * * THU'
    - cron: '49 21 * * THU'
    - cron: '32 13 * * FRI'
    - cron: '58 17 * * FRI'
    - cron: '49 21 * * FRI'
    - cron: '32 13 * * SAT'
    - cron: '58 17 * * SAT'
    - cron: '49 21 * * SAT'
    - cron: '32 13 * * SUN'
    - cron: '58 17 * * SUN'
    - cron: '49 21 * * SUN'

jobs:
  cron:
    runs-on: ubuntu-latest
    steps:
      - name: optimal-cron-for-twitter
        run: |
          curl --request POST \
          --url 'https://stakingcrypto.io/api/cron/optimal-cron-for-twitter' \
          --header 'Authorization: Bearer ${{ secrets.CRON_APP_KEY }}'


Enter fullscreen mode Exit fullscreen mode

This basically will, every perfect time for posting, get back one tweet and post it to my twitter account @stakingcryptoio.

Github cron is setup for the GMT timezone and I adapted the best times for New York.

What about you, what schedule do you use to post on twitter optimally?

Top comments (0)