Scheduling tweets at specific times for twitter_ebooks bots

Published: June 2, 2017

Tags:

In the documentation for twitter_ebooks you’ll see the following code.

 def on_startup
  scheduler.every '24h' do
    # Tweet something every 24 hours
    # See https://github.com/jmettraux/rufus-scheduler
    # tweet("hi")
    # pictweet("hi", "cuteselfie.jpg")
  end
end

This will cause your ebooks_bot to tweet every 24 hours. However, what if you want your bot to Tweet at a specific schedule every day? We’ll take a look at how to set that up here…

Cron Expressions in Rufus Scheduler

In the code above, scheduler refers to an a Rufus::Scheduler instance (as the comments suggest)

Rufus Scheduler supports cron expressions. For example, if you wanted your bot to tweet at 06:00 and 18:00 every day you’d just update as follows…

def on_startup
  scheduler.cron '6,18 0 * * *' do
    tweet("hi")
  end
end

A Note On Timezones

Rufus Scheduler also allows you to specify a timezone, which will override the server timezone. In my case, I want to tweet at New York time. Specifying a timezone is very simple…

def on_startup
  scheduler.cron '6,18 0 * * * America/New_York' do
    tweet("hi")
  end
end

:bulb:Did you enjoy this blog post?

If so, please consider checking out my side project Domain Clamp. It's a SaaS which monitors domains and SSL certificates and sends notifications before anything expires. If you work at an agency, then you're probably not the registrant for your client's domains or the SSL certificate owner. This means you won't get expiration notifications. You don't want a client's domain or SSL certificate to expire under your watch. Believe me, I've been there.

Domain Clamp solves this problem by letting you monitor the SSL certificate and registration for any domain you'd damn please. Free accounts are available so please head on over »