From 9fdccb85ed084546d9642ccd00a3206797a09508 Mon Sep 17 00:00:00 2001 From: Simon Szustkowski Date: Thu, 11 Oct 2012 15:52:31 +0200 Subject: [PATCH] Initial commit --- bot.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ config.yaml | 8 ++++++++ 2 files changed, 57 insertions(+) create mode 100755 bot.rb create mode 100644 config.yaml diff --git a/bot.rb b/bot.rb new file mode 100755 index 0000000..653f535 --- /dev/null +++ b/bot.rb @@ -0,0 +1,49 @@ +#! /usr/bin/env ruby + +require 'twitter' +require 'yaml' +require 'net/http' +require 'uri' + +#Specify and load config +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 + +# Read last known status from cache +last_status = $config['worker']['last_status'].to_s + +# Get current status from web +url = URI.parse('http://www.chaostreff-dortmund.de/') +res = Net::HTTP.start(url.host, url.port) {|http| + http.get('/raumstatus.php?txt') +} +$current_status = res.body.to_s.strip + + +# If status differs from last time checked, put the announcement +if (last_status != $current_status) + if ($current_status == "offline") + puts "Der Raum ist jetzt OFFLINE." + status = "offline" + elsif ($current_status == "online") + puts "Der Raum ist jetzt ONLINE." + status = "online" + else + puts "Raumstatus UNBEKANNT." + status = "unknown" + end + $config['worker']['last_status'] = status + File.open(CONFIG_FILE, 'w') { |f| YAML.dump($config, f) } +else + puts "Raumstatus unveraendert" +end \ No newline at end of file diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..411802c --- /dev/null +++ b/config.yaml @@ -0,0 +1,8 @@ +--- +oauth: + consumer_key: + consumer_secret: + request_token: + request_secret: +worker: + last_status: offline