Skip to content

Instantly share code, notes, and snippets.

@hokorobi
Created August 29, 2010 12:27
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 hokorobi/556250 to your computer and use it in GitHub Desktop.
Save hokorobi/556250 to your computer and use it in GitHub Desktop.
twitterclient.rb
# -*- encoding: utf-8 -*-
if ARGV.size < 1
exit 1
else
tweet = ARGV[0].encode('UTF-8', 'Windows-31J')
end
# メッセージボックス表示
require 'win32ole'
def show(msg)
wsh = WIN32OLE.new('WScript.Shell')
title = "Message"
wsh.Popup(msg, 0, title, 0 + 64 + 0x40000)
end
# 設定ファイル読み込み
require "yaml"
tn = Time.now
configFile = String.new("#{ENV['HOME']}/.twitter")
if File.readable?(configFile) then
begin
config = File.read(configFile)
configObj = YAML.load(config)
rescue => ex
show(ex.message)
exit 1
end
else
printf("make %s\n", configFile)
exit 1
end
# 呟きの長さチェック
if tweet.length > 140 then
require "Jmp"
require "uri"
if URI.extract(tweet) then
jmp = Jmp.new(configObj['jmpuser'], configObj['jmpapikey'], tweet)
tweet = jmp.shorten()
end
if tweet.length> 140 then
show("文字列が長すぎます。#{tweet.length}")
exit 1
end
end
# twitter へ post
require 'rubygems'
require 'twitter'
#puts configObj['token']
#puts configObj['secret']
#puts configObj['atoken']
#puts configObj['asecret']
begin
oauth = Twitter::OAuth.new(configObj['token'], configObj['secret'])
oauth.authorize_from_access(configObj['atoken'], configObj['asecret'])
client = Twitter::Base.new(oauth)
client.update(tweet)
rescue
show("Tweet failed.")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment