Created
September 7, 2014 02:49
-
-
Save ayafujiaya/b53d9ebaa18e16854c1a to your computer and use it in GitHub Desktop.
imhere_project_update_with_media
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
require 'twitter' | |
require 'oauth' | |
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE | |
# Consumer key, Secretの設定 | |
CONSUMER_KEY = "UloNCeJPWkQJeuYFVpwxTYUpZ" | |
CONSUMER_SECRET = "IcfPrDQNCrgRwUXC0ouGdSTW6xdGNELEJaNeVYAlslUhiLvkb7" | |
# Access Token Key, Secretの設定 | |
ACCESS_TOKEN_KEY = "2793009290-iUkAwnOAqrDKodplRQxDziaYqlTth78AVEqHkuT" | |
ACCESS_SECRET = "a9B6wlbX5T27o70Mar8BA35NP5MNczrWYN6Hr0gE7loap" | |
filenames = [] | |
preFilenames = [] | |
newItem = "" | |
count = 0 | |
begin | |
client = Twitter::REST::Client.new do |config| | |
config.consumer_key = CONSUMER_KEY | |
config.consumer_secret = CONSUMER_SECRET | |
config.access_token = ACCESS_TOKEN_KEY | |
config.access_token_secret = ACCESS_SECRET | |
end | |
while true do | |
sleep(3) | |
# Dir::foreachを使った例 | |
Dir::foreach('./media') {|f| | |
#puts f #{}"#{f}: #{File::mtime(f)}" | |
filenames.push(f) | |
} | |
filenames.each{|name| | |
same = false | |
preFilenames.each { |name2| | |
if name == name2 then | |
same = true | |
break | |
else | |
same = false | |
end | |
} | |
if same == false and count != 0 then | |
puts "new item discovering!!" | |
puts name | |
newItem = name | |
end | |
} | |
# ツイート文設定 | |
str_out = "hello, Im here." | |
#media = open("./media/twitter.jpg") | |
latitude = "37.76893497" | |
longtitude = "-122.42284884" | |
if newItem != "" then | |
puts "uploading....." | |
imagePath = "./media/" + newItem | |
image = open(imagePath) | |
client.update_with_media(str_out, image, {:lat => latitude, :long => longtitude}) # <= 画像添付が有る場合 | |
end | |
puts "/******************* current file list ******************/" | |
puts filenames | |
puts "/********************************************************/" | |
preFilenames = filenames | |
filenames = [] | |
newItem = "" | |
count = count + 1 | |
end | |
rescue => e | |
STDERR.puts "[EXCEPTION] " + e.to_s | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment