vulture/vulture.rb

39 lines
1.0 KiB
Ruby

#!/usr/bin/env ruby
require 'logger'
require 'sequel'
require 'sqlite3'
require_relative 'lib/config.rb'
# Load configuration
conf = Config.new(File.join(__dir__, 'data/defaults.yaml'))
# Initialize logging
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
# Load the Sequel timestamps plugin
Sequel::Model.plugin :timestamps
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('database.database'))
# Load models
require_relative 'lib/models/post.rb'
# Main program loop
while true
# Let the user know something is going on
logger.info('Checking for new social media posts to make public...')
# Search for posts that are due to be published
to_post = Post.dataset.where(published: false).where{publish_at < Time.now}
# If we have posts to handle, let's do it!
to_post.each { |post|
puts "Posting tweet: #{post.text}"
post.update(published: true)
}
# Wait for the specified wait period
sleep(conf.get('vulture.run_interval') * 60)
end