Mstb

aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Zur Navigation springenZur Suche springen

Dieses Projekt ist Out Of Order

MetaSense twitter bot

Nimmt den status vom metalab schloss und tweeted ihn, wenn er sich ändert.

http://twitter.com/metastate

#!/usr/bin/perl

use Strict;
use vars qw($auth_token, @text);
use HTTP::Lite;


$auth_token="XXXXXXXXXXXXXXXX";
@text=("the metalab door has just been locked",
"the metalab door has just been unlocked");

sub get_lock_status{
        my $http = new HTTP::Lite;
        my $req=
        $http->request("http://exodus.metalab.at/metasense/status_lock.txt")
        or die "unable to contact metastate";
        if ($req != 200) { die "metasense http: $req"}
        return $http->body();
        }

sub send_twitter_status{
        my $http = new HTTP::Lite;
        my %post= ('status' =>  shift);
        $http->add_req_header("Authorization: Basic ".$auth_token);
        $http->prepare_post(\%post);
        $req=$http->request("http://twitter.com/statuses/update.xml") or die
        "unable to contact twitter.com";
        if ($req != 200) { die "twitter.com http: $req"}
        }

my $newstate=get_lock_status();
open (FL, "mstb.state");
my $oldstate=<FL>;
close(FL);
if ($oldstate != $newstate) {
        send_twitter_status($text[$newstate]);
        open(FL, ">mstb.state");
        print FL $newstate;
        close(FL);
        }

Twitter-Nachrichten senden in anderen Sprachen: TwitterMeThis.