Mstb: Unterschied zwischen den Versionen

aus Metalab, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: http://twitter.com/metastate <pre> #!/usr/bin/perl use Strict; use vars qw($auth_token); use HTTP::Lite; $auth_token="XXXXXXXXXXXXXXXX"; sub get_lock_status{ ...)
 
 
(2 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 1: Zeile 1:
 +
==[[MetaSense]] [http://twitter.com twitter] bot==
 +
Nimmt den status vom metalab schloss und tweeted ihn, wenn er sich ändert.
 +
 
http://twitter.com/metastate  
 
http://twitter.com/metastate  
  
Zeile 5: Zeile 8:
  
 
use Strict;
 
use Strict;
use vars qw($auth_token);
+
use vars qw($auth_token, @text);
 
use HTTP::Lite;
 
use HTTP::Lite;
  
  
 
$auth_token="XXXXXXXXXXXXXXXX";
 
$auth_token="XXXXXXXXXXXXXXXX";
 +
@text=("the metalab door has just been locked",
 +
"the metalab door has just been unlocked");
  
 
sub get_lock_status{
 
sub get_lock_status{
Zeile 16: Zeile 21:
 
         $http->request("http://exodus.metalab.at/metasense/status_lock.txt")
 
         $http->request("http://exodus.metalab.at/metasense/status_lock.txt")
 
         or die "unable to contact metastate";
 
         or die "unable to contact metastate";
 +
        if ($req != 200) { die "metasense http: $req"}
 
         return $http->body();
 
         return $http->body();
 
         }
 
         }
  
 
sub send_twitter_status{
 
sub send_twitter_status{
        my $status=shift;
 
 
         my $http = new HTTP::Lite;
 
         my $http = new HTTP::Lite;
         my %post;
+
         my %post= ('status' =>  shift);
        $post{'status'}=$status;
+
 
         $http->add_req_header("Authorization: Basic ".$auth_token);
 
         $http->add_req_header("Authorization: Basic ".$auth_token);
 
         $http->prepare_post(\%post);
 
         $http->prepare_post(\%post);
         $http->request("http://twitter.com/statuses/update.xml") or die
+
         $req=$http->request("http://twitter.com/statuses/update.xml") or die
 
         "unable to contact twitter.com";
 
         "unable to contact twitter.com";
 +
        if ($req != 200) { die "twitter.com http: $req"}
 
         }
 
         }
  
Zeile 34: Zeile 39:
 
my $oldstate=<FL>;
 
my $oldstate=<FL>;
 
close(FL);
 
close(FL);
my @text=("the metalab door has just been locked",
 
"the metalab door has just been unlocked");
 
 
if ($oldstate != $newstate) {
 
if ($oldstate != $newstate) {
 
         send_twitter_status($text[$newstate]);
 
         send_twitter_status($text[$newstate]);
Zeile 42: Zeile 45:
 
         close(FL);
 
         close(FL);
 
         }
 
         }
 
 
</pre>
 
</pre>
 +
 +
Twitter-Nachrichten senden in anderen Sprachen: [[TwitterMeThis]].
 +
 +
[[Kategorie:Projekte]]

Aktuelle Version vom 4. April 2007, 17:05 Uhr

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.