<commit_before>#!/usr/bin/env ruby
# encoding: utf-8

require 'yaml'
require 'twitter'

def users
  @users ||= (YAML::load(File.open('users.yml')) || [])
end
def messages
  @messages ||= (YAML::load(File.open('messages.yml')) || [])
end
def production?
  ENV['HELOCK_ENV'] != 'development'
end
def config
  unless production?
    [10.seconds, 'dev ;)']
  else
    [1.day, 'wake up', :at => ENV['WAKEUP_TIME']]
  end
end
def log_direct_message user, message
  puts "#{Time.now}: dm to @#{user} #{message}"
end
def send_direct_message user, message
  Twitter.configure do |config|
    config.consumer_key       = ENV['CONSUMER_KEY']
    config.consumer_secret    = ENV['CONSUMER_SECRET']
    config.oauth_token        = ENV['OAUTH_TOKEN']
    config.oauth_token_secret = ENV['OAUTH_TOKEN_SECRET']
  end
  log_direct_message user, message
  Twitter.direct_message_create user, message
end

every(*config) do
  today = Time.now.wday
  action = production? ? 'send' : 'log'
  users.each do |user|
    message = messages[today].shuffle.first
    send("#{action}_direct_message".to_sym, *[user, message])
  end
end<commit_msg>Add timeout handling<commit_after>#!/usr/bin/env ruby
# encoding: utf-8

require 'yaml'
require 'twitter'

def users
  @users ||= (YAML::load(File.open('users.yml')) || [])
end
def messages
  @messages ||= (YAML::load(File.open('messages.yml')) || [])
end
def production?
  ENV['HELOCK_ENV'] != 'development'
end
def config
  unless production?
    [10.seconds, 'dev ;)']
  else
    [1.day, 'wake up', :at => ENV['WAKEUP_TIME']]
  end
end
def log_direct_message user, message
  puts "#{Time.now}: dm to @#{user} #{message}"
end
def send_direct_message user, message
  Twitter.configure do |config|
    config.consumer_key       = ENV['CONSUMER_KEY']
    config.consumer_secret    = ENV['CONSUMER_SECRET']
    config.oauth_token        = ENV['OAUTH_TOKEN']
    config.oauth_token_secret = ENV['OAUTH_TOKEN_SECRET']
  end
  log_direct_message user, message
  Twitter.direct_message_create user, message
end

every(*config) do
  today = Time.now.wday
  action = production? ? 'send' : 'log'
  users.each do |user|
    message = messages[today].shuffle.first
    begin
      send("#{action}_direct_message".to_sym, *[user, message])
    rescue Errno::ETIMEDOUT
      puts "Time out Error :/"
    end
  end
end
{'fraction_non_alphanumeric': 0.14716006884681584, 'fraction_numerical': 0.0034423407917383822, 'mean_word_length': 4.1098901098901095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3886758', 'n_tokens_mistral': 848, 'n_tokens_neox': 825, 'n_words': 187}