Mstb: Unterschied zwischen den Versionen

aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Zur Navigation springenZur Suche springen
(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{ ...)
 
 
(3 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
 +
Dieses Projekt ist Out Of Order
 +
 +
==[[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 10:
  
 
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 23:
 
         $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 41:
 
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 47:
 
         close(FL);
 
         close(FL);
 
         }
 
         }
 +
</pre>
  
</pre>
+
Twitter-Nachrichten senden in anderen Sprachen: [[TwitterMeThis]].
 +
 
 +
[[Kategorie:Projekte]]

Aktuelle Version vom 26. März 2019, 16:32 Uhr

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.