From d7c34f06105b8ee34f1e7a0f37709590b791bd84 Mon Sep 17 00:00:00 2001 From: Simon Szustkowski Date: Wed, 3 Sep 2014 10:41:50 +0200 Subject: [PATCH] Finished reworking --- bot.rb | 31 +++++++++++++++---------------- config.yaml | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/bot.rb b/bot.rb index 70708f0..734e3da 100755 --- a/bot.rb +++ b/bot.rb @@ -9,15 +9,12 @@ require 'uri' CONFIG_FILE = 'config.yaml' $config = YAML::load(File.open(File.join(File.dirname(__FILE__), CONFIG_FILE))) -## Configure and create the twitter client -#Twitter.configure do |config| -# config.consumer_key = $config['oauth']['consumer_key'] -# config.consumer_secret = $config['oauth']['consumer_secret'] -# config.oauth_token = $config['oauth']['request_token'] -# config.oauth_token_secret = $config['oauth']['request_secret'] -#end - -#client = Twitter::Client.new +client = Twitter::REST::Client.new do |config| + config.consumer_key = $config['oauth']['consumer_key'] + config.consumer_secret = $config['oauth']['consumer_secret'] + config.access_token = $config['oauth']['request_token'] + config.access_token_secret = $config['oauth']['request_secret'] +end # Read last known status from cache 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) response = http.request(request) 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 (last_status != $current_status) - if ($current_status == "offline") + if ($current_status == "false") tweet = "Der Raum ist jetzt GESCHLOSSEN. #ctdo" - status = "offline" + status = "false" #puts "offlinestatus getwittert" - elsif ($current_status == "online") + elsif ($current_status == "true") tweet = "Der Raum ist jetzt OFFEN. #ctdo." - status = "online" + status = "true" #puts "onlinestatus getwittert" else tweet = "Raumstatus UNBEKANNT." @@ -46,10 +45,10 @@ if (last_status != $current_status) #puts "unbekannt getwittert" end $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 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 puts e # Nothing to do here diff --git a/config.yaml b/config.yaml index 2cd93f5..ac7d09b 100644 --- a/config.yaml +++ b/config.yaml @@ -5,4 +5,4 @@ oauth: request_token: 873661934-15exavg3cWFux0ON5WGhfHMXthcPeKVUrRk8nCBK request_secret: 9kJoWvYMVEEbWIEUGtqpb4ib1QUfegQp2BGK6dw worker: - last_status: unknown + last_status: 'false'