first commit

This commit is contained in:
2018-09-02 10:26:34 +02:00
commit a62ea0fa19
53 changed files with 3823 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- La config globale
// ---
require_once '../../global/inc/config.php';
// ---
// --- External dependances
// ---
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
$width = 840;
$height = 104;
$h = $height*6;
$final_hash = 'default';
$img = imagecreatetruecolor($width, $h);
$tr = imagecolorallocate($img, 220, 220, 220);
imagecolortransparent($img, $tr);
imagefilledrectangle($img, 0, 0, $width, $height*6, $tr);
$handle = fopen(DATA_PATH.'/hashes2hashes/liste.txt', 'r');
if ($handle) {
while (($hash = fgets($handle, 4096)) !== false) {
$hash = preg_replace('~[[:cntrl:]]~', '', $hash);
$split = explode(' ', $hash);
$hash = $split[1];
if ($final_hash == 'default') $final_hash = $hash;
$hash = DATA_PATH.'/hashes/'.$hash.'.png';
if (file_exists($hash))
{
$h -= $height;
$src_img = imagecreatefrompng($hash);
if ($src_img)
{
if (FALSE === imagecopy($img, $src_img, 0, $h, 0, 0, $width, $height))
echo "Erreur : problème de copie image".PHP_EOL;
} else echo "Erreur: ".$hash." ne semble pas être une image PNG".PHP_EOL;
} else echo "Erreur: ".$hash." n'a pas été trouvé".PHP_EOL;
}
if (!feof($handle)) {
echo "Erreur: fgets() a échoué".PHP_EOL;
}
fclose($handle);
} else echo "Erreur: fopen('".DATA_PATH."/hashes2hashes/liste.txt') a échoué".PHP_EOL;
imagepng($img, DATA_PATH.'/hashes2hashes/'.$final_hash.'.png');
imagedestroy($img);
?>

60
methode/hashes/robot.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
// ---
// --- Listening to blockchain.info to get the last block
// ---
// ---
// --- 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';
// ---
// --- Par défaut on cherche le dernier block
// ---
$block_hash = 'LAST';
// ---
// --- Le cas échéant, on cherche block passé en argument
// ---
if (isset($argv[1])) $block_hash = $argv[1];
$mode=rand(0, 5);
if (isset($argv[2])) $mode=intval($argv[2]);
$the_block = blockchain::getBlockWithHash($block_hash);
if ($the_block === FALSE) die();
$bandeau = 50;
$marge = 0;
$text_border = 20;
$width = GRAPH_WIDTH;
$height = 2;
// Pour que l'image simple ait les proportions que l'image full
$width = $marge + ($width*2) + (2*$text_border);
$height = $marge + ($height*2);
$img_w = $width;
$img_h = $height+(2*$bandeau);
// création d'une image plus haute pour inclure bandeaux haut et bas
$img = imagecreatetruecolor($img_w, $img_h);
blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau);
imagepng($img, DATA_PATH.'/hashes/'.$the_block->hash.'.png');
imagedestroy($img);
?>

42
methode/hashes/robot.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
flag=$TMP_PATH/hashes_bot.flag
date=`date +%Y%m%d0000`
if [ -f $flag ];
then
echo "hashes_bot is already running !"
exit 0
fi
touch $flag
cd $APPS_PATH/methode/hashes
for BLOCK in `grep LAST $DATA_PATH/block_list.txt | awk '{print $2}'`
do
if [ ! -f $DATA_PATH/hashes/$BLOCK.png ]
then
BLOCK_HEIGHT=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $3}'`
php robot.php $BLOCK $((RANDOM % 6))
echo $BLOCK_HEIGHT $BLOCK >> $DATA_PATH/hashes2hashes/liste.txt
mv $DATA_PATH/hashes2hashes/liste.txt $DATA_PATH/hashes2hashes/liste.new
sort -k1 -n $DATA_PATH/hashes2hashes/liste.new > $DATA_PATH/hashes2hashes/liste.txt
rm -f $DATA_PATH/hashes2hashes/liste.new
COMPTEUR=`wc -l $DATA_PATH/hashes2hashes/liste.txt | awk '{print $1}' `
if [ $COMPTEUR -eq 6 ]
then
php assemble.php
rm -f $DATA_PATH/hashes2hashes/liste.old
mv $DATA_PATH/hashes2hashes/liste.txt $DATA_PATH/hashes2hashes/liste.old
fi
fi
BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'`
if [ "$BNAME" == "LAST" ]
then
touch $DATA_PATH/hashes/$BLOCK.png
else
touch -t $date $DATA_PATH/hashes/$BLOCK.png
fi
done
rm -f $flag