Finished reworking

master
Simon Szustkowski 8 years ago
parent 425aef81fa
commit d7c34f0610
  1. 31
      bot.rb
  2. 2
      config.yaml

@ -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

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

Loading…
Cancel
Save