Files
apps/twitter/emptybot/robot.php

83 lines
2.2 KiB
PHP

<?php
// ---
// --- Listening to blockchain.info to get the last block
// --- Drawing the block as a Treemap
// --- Tweet it
// ---
// ---
// --- La config globale
// ---
require_once '../../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
// ---
// --- Internal dependances
// ---
require_once APP_PATH.'/blockchain/inc/block.php';
require 'inc/twitter.php';
$midnight = strtotime('today midnight');
$methode='spline';
if (isset($argv[3])) $methode=$argv[3];
$block_hash = $argv[1];
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
// ---
// --- Remercier les followers ?
// ---
// twitter::thanksFollowers();
$image_file=DATA_PATH."/$methode/".$argv[1].'.png';
if (file_exists($image_file))
{
$image_origine = imagecreatefrompng($image_file);
$image_twitter = imagecreatetruecolor(TWITTER_WIDTH, TWITTER_HEIGHT);
$fond = imagecolorallocate($image_twitter, 255, 255, 255);
//imagecolortransparent($image_twitter, $fond);
imagefilledrectangle($image_twitter, 0, 0, TWITTER_WIDTH, TWITTER_HEIGHT, $fond);
$ratio = TWITTER_HEIGHT / imagesy($image_origine);
$new_width = $ratio * imagesx($image_origine);
$xpos = floor((TWITTER_WIDTH - $new_width) / 2);
$ypos = 0;
imagecopyresized($image_twitter, $image_origine, $xpos, $ypos, 0, 0, $new_width, TWITTER_HEIGHT, imagesx($image_origine), imagesy($image_origine));
$image_file = DATA_PATH."/emptybot/".$argv[1].'.png';
imagepng($image_twitter,$image_file);
// ---
// --- Un petit peu de stéganographie ...
// ---
/* Ca fait des fichiers trop gros !
$processor = new KzykHys\Steganography\Processor();
$image = $processor->encode($image_file, 'TOPISTO is making art with block '.$the_block->height);
$image->write($image_file);
*/
// ---
// --- Tweet
// ---
$tweet = "Lucky One on #bitcoin #blockchain 's".PHP_EOL;
$tweet .= "Someone put an empty block ...".PHP_EOL;
$tweet .= "And get the reward for it !".PHP_EOL;
$tweet .= "Block height : ".$the_block->height.PHP_EOL;
$tweet .= "[ See more on www.topisto.net ]";
$success = twitter::tweet($tweet, $image_file);
}
?>