You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.7 KiB

#! /usr/bin/env ruby
require 'twitter'
require 'yaml'
require 'net/http'
require 'uri'
#Specify and load config
CONFIG_FILE = 'config.yaml'
$config = YAML::load(, CONFIG_FILE)))
client = 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']
# Read last known status from cache
last_status = $config['worker']['last_status'].to_s
#puts "last status #{last_status}"
# Get current status from web
uri = URI.parse('')
http =, uri.port)
request =
response = http.request(request)
result = JSON.parse(response.body)
$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 == "false")
tweet = "Der Raum ist jetzt GESCHLOSSEN. #ctdo"
status = "false"
#puts "offlinestatus getwittert"
elsif ($current_status == "true")
tweet = "Der Raum ist jetzt OFFEN. #ctdo."
status = "true"
#puts "onlinestatus getwittert"
tweet = "Raumstatus UNBEKANNT."
status = "unknown"
#puts "unbekannt getwittert"
$config['worker']['last_status'] = status, CONFIG_FILE), 'w') { |f| YAML.dump($config, f) }
#puts tweet
client.update(tweet, {:lat => "51.527611", :lon => "7.464944", :display_coordinates => "true"})
rescue Exception => e
puts e
# Nothing to do here