Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created March 26, 2010 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igaiga/344539 to your computer and use it in GitHub Desktop.
Save igaiga/344539 to your computer and use it in GitHub Desktop.
twitter dm sender
#! ruby -Ku
# -*- coding: utf-8 -*-
# twitter DM sender to any users.
# via http://cheebow.info/chemt/archives/2007/11/twitterdm.html
require 'net/http'
require 'kconv'
require 'yaml'
conf_file = ARGV.shift || 'default.yaml'
conf = YAML.load_file(conf_file)
to_list = conf['to_list']
status = conf['status']
username = conf['account']['username']
password = conf['account']['password']
to_list.each{|id|
req = Net::HTTP::Post.new('/direct_messages/new.xml')#
req.basic_auth(username, password)
req.body = 'user=' + id + '&text=' + URI.encode(status)
Net::HTTP.start('twitter.com') do |http|
res = http.request(req)
if res.body.include?('<created_at>')
puts '@' + id + ': message was sent'
else
puts '@' + id + ': ERROR!'
end
end
}
=begin
default.yaml
account:
username: igaiga555
password: pass
status: こんにちは!テストです!
to_list:
- igaiga555
- twym555
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment