Finished reworking

This commit is contained in:
Simon Szustkowski 2014-09-03 10:41:50 +02:00
parent 425aef81fa
commit d7c34f0610
2 changed files with 16 additions and 17 deletions

31
bot.rb
View File

@ -9,15 +9,12 @@ require 'uri'
CONFIG_FILE = 'config.yaml' CONFIG_FILE = 'config.yaml'
$config = YAML::load(File.open(File.join(File.dirname(__FILE__), CONFIG_FILE))) $config = YAML::load(File.open(File.join(File.dirname(__FILE__), CONFIG_FILE)))
## Configure and create the twitter client client = Twitter::REST::Client.new do |config|
#Twitter.configure do |config| config.consumer_key = $config['oauth']['consumer_key']
# config.consumer_key = $config['oauth']['consumer_key'] config.consumer_secret = $config['oauth']['consumer_secret']
# config.consumer_secret = $config['oauth']['consumer_secret'] config.access_token = $config['oauth']['request_token']
# config.oauth_token = $config['oauth']['request_token'] config.access_token_secret = $config['oauth']['request_secret']
# config.oauth_token_secret = $config['oauth']['request_secret'] end
#end
#client = Twitter::Client.new
# Read last known status from cache # Read last known status from cache
last_status = $config['worker']['last_status'].to_s last_status = $config['worker']['last_status'].to_s
@ -28,17 +25,19 @@ http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri) request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request) response = http.request(request)
result = JSON.parse(response.body) result = JSON.parse(response.body)
p result $current_status = result["state"]["open"].to_s
p $current_status
p last_status
# If status differs from last time checked, put the announcement # If status differs from last time checked, put the announcement
if (last_status != $current_status) if (last_status != $current_status)
if ($current_status == "offline") if ($current_status == "false")
tweet = "Der Raum ist jetzt GESCHLOSSEN. #ctdo" tweet = "Der Raum ist jetzt GESCHLOSSEN. #ctdo"
status = "offline" status = "false"
#puts "offlinestatus getwittert" #puts "offlinestatus getwittert"
elsif ($current_status == "online") elsif ($current_status == "true")
tweet = "Der Raum ist jetzt OFFEN. #ctdo." tweet = "Der Raum ist jetzt OFFEN. #ctdo."
status = "online" status = "true"
#puts "onlinestatus getwittert" #puts "onlinestatus getwittert"
else else
tweet = "Raumstatus UNBEKANNT." tweet = "Raumstatus UNBEKANNT."
@ -46,10 +45,10 @@ if (last_status != $current_status)
#puts "unbekannt getwittert" #puts "unbekannt getwittert"
end end
$config['worker']['last_status'] = status $config['worker']['last_status'] = status
#File.open(File.join(File.dirname(__FILE__), CONFIG_FILE), 'w') { |f| YAML.dump($config, f) } File.open(File.join(File.dirname(__FILE__), CONFIG_FILE), 'w') { |f| YAML.dump($config, f) }
begin begin
puts tweet puts tweet
#client.update(tweet, {:lat => "51.527611", :lon => "7.464944", :display_coordinates => "true"}) client.update(tweet, {:lat => "51.527611", :lon => "7.464944", :display_coordinates => "true"})
rescue Exception => e rescue Exception => e
puts e puts e
# Nothing to do here # Nothing to do here

View File

@ -5,4 +5,4 @@ oauth:
request_token: 873661934-15exavg3cWFux0ON5WGhfHMXthcPeKVUrRk8nCBK request_token: 873661934-15exavg3cWFux0ON5WGhfHMXthcPeKVUrRk8nCBK
request_secret: 9kJoWvYMVEEbWIEUGtqpb4ib1QUfegQp2BGK6dw request_secret: 9kJoWvYMVEEbWIEUGtqpb4ib1QUfegQp2BGK6dw
worker: worker:
last_status: unknown last_status: 'false'