Mstb
aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Version vom 26. März 2007, 19:27 Uhr von Mihi (Diskussion | Beiträge) (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{ ...)
#!/usr/bin/perl use Strict; use vars qw($auth_token); use HTTP::Lite; $auth_token="XXXXXXXXXXXXXXXX"; 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"; return $http->body(); } sub send_twitter_status{ my $status=shift; my $http = new HTTP::Lite; my %post; $post{'status'}=$status; $http->add_req_header("Authorization: Basic ".$auth_token); $http->prepare_post(\%post); $http->request("http://twitter.com/statuses/update.xml") or die "unable to contact twitter.com"; } my $newstate=get_lock_status(); open (FL, "mstb.state"); my $oldstate=<FL>; close(FL); my @text=("the metalab door has just been locked", "the metalab door has just been unlocked"); if ($oldstate != $newstate) { send_twitter_status($text[$newstate]); open(FL, ">mstb.state"); print FL $newstate; close(FL); }