Created
March 26, 2010 05:06
-
-
Save igaiga/344539 to your computer and use it in GitHub Desktop.
twitter dm sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! 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