LipousseBlog

Aller au contenu | Aller au menu | Aller à la recherche

Tag - twitter

Fil des billets

samedi, juillet 18 2009

Mes bots sur Twitter

Hier, j'ai joué un peu avec Twitter pour me faire des bots.

https://twitter.com/legwebbot

Pour faire un Watcher, c'est assez simple en utilisant phptwitterbot

lundi, mai 4 2009

Redémarrer votre PC avec Twitter sous Linux avec php

Sous Linux pour redémarrer, arrêter ou cloture une session de son ordinateur à distance

Fichier command_twitter.php

#!/usr/bin/php -q

<?php

 $login = "LoginTwitter:PassTwitter";  
   
 $tweets = "http://twitter.com/statuses/friends_timeline.xml?count=1";  
   
 $tw = curl_init();  
   
 curl_setopt($tw, CURLOPT_URL, $tweets);  
   
 curl_setopt($tw, CURLOPT_USERPWD, $login);  
   
 curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);  
   
 $twi = curl_exec($tw);  
   
 $tweeters = new SimpleXMLElement($twi);  

foreach ($tweeters->status as $twit1) {  
   
$text = trim($twit1->text);
$created = trim($twit1->created_at);

if (ereg("([0-9]{2}):([0-9]{2}):([0-9]{2})", $created, $regs)) {

    $created = "$regs[1]:$regs[2]:$regs[3]";
    $now = date("H:i:s",strtotime("-2 hour"));
    $lasttenminute = date("H:i:s",time()-6600);

        if($created <= $now && $created >= $lasttenminute)
                exec($text);
        else
                echo 'no action';

} else {
    echo "Format de date invalide : $date";
}
}
?>

Dans le crontab

*/1 * * * * root $HOME/bin/command_twitter.php > /dev/null 2> /dev/null

Depuis n'importe quel ordinateur, on lance la commande suivante pour donner un ordre.

curl -u LoginTwitter:PassTwitter -d status="reboot" http://twitter.com/statuses/update.xml

TweetMyPC est utile sous Windows, mais pas sous Linux ou Mac.

Un equivalent en bash