From f597fc4995ce77a93fd111646c13272b5b363333 Mon Sep 17 00:00:00 2001 From: MEUNIER Thibaud Date: Sun, 27 Jan 2019 07:28:31 +0100 Subject: [PATCH] ajout de emptybot --- blockchain/robot.php | 5 +- blockchain/robot.sh | 6 +- scripts/blocks2.sh | 8 +-- scripts/clean_data.sh | 9 +++ scripts/tweet.sh | 16 ++++- twitter/emptybot/followers.json.example | 1 + twitter/emptybot/inc/twitter.php | 88 +++++++++++++++++++++++++ twitter/emptybot/robot.php | 81 +++++++++++++++++++++++ twitter/emptybot/robot.sh | 38 +++++++++++ 9 files changed, 242 insertions(+), 10 deletions(-) create mode 100644 twitter/emptybot/followers.json.example create mode 100644 twitter/emptybot/inc/twitter.php create mode 100644 twitter/emptybot/robot.php create mode 100755 twitter/emptybot/robot.sh diff --git a/blockchain/robot.php b/blockchain/robot.php index d7f59e4..92dc41c 100644 --- a/blockchain/robot.php +++ b/blockchain/robot.php @@ -33,6 +33,9 @@ if ($the_block === FALSE) die(); echo $block_hash.' '.$the_block->hash." ".$the_block->height." ".$the_block->n_tx.PHP_EOL; if ($block_hash == 'LAST') +{ + // On a demandé le dernier block + // On remonte sur les huits derniers pour accélerer les prochaines navigations for($max=0;($max<8)&&(!file_exists(DATA_PATH.'/json/'.$the_block->prev_block.'.zip'));$max++) { $block_hash = $the_block->prev_block; @@ -40,5 +43,5 @@ if ($block_hash == 'LAST') if ($the_block === FALSE) die(); echo 'CACHE '.$the_block->hash." ".$the_block->height." ".$the_block->n_tx.PHP_EOL; } - +} ?> diff --git a/blockchain/robot.sh b/blockchain/robot.sh index a447267..1f815a2 100755 --- a/blockchain/robot.sh +++ b/blockchain/robot.sh @@ -13,12 +13,12 @@ cd $APPS_PATH/blockchain rm -f $DATA_PATH/block_list.tmp -LISTBLOCKS="LAST \ - GENESIS THE_ANSWER LUCIFER LEET \ +LISTBLOCKS="GENESIS THE_ANSWER LUCIFER LEET \ TOPISTO PIZZA HALVING_1 WHALE201311 \ HALVING_2 BIP_91_LOCK BCC SEGWIT_LOCK \ SEGWIT HURRICANE_1 WHALE201810 \ - BLOCK21E800" + BLOCK21E800 \ + LAST" for BLOCK in $LISTBLOCKS do diff --git a/scripts/blocks2.sh b/scripts/blocks2.sh index 7b408f1..4afbceb 100755 --- a/scripts/blocks2.sh +++ b/scripts/blocks2.sh @@ -68,29 +68,27 @@ while IFS='' read -r line || [[ -n "$line" ]]; do LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v treemap | grep -v robot | shuf | head -n 1` fi + cd $APPS_PATH/methode2 for METHODE in $LISTE_METHODE do if [ ! -d $DATA_PATH/$METHODE ] then mkdir -p $DATA_PATH/$METHODE fi - + echo $BLOCK $NAME $METHODE if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ] then - cd $APPS_PATH/methode2 php robot.php $METHODE $BLOCK $((RANDOM % 6)) $2 cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/$METHODE/$BLOCK.png - cd - >> /dev/null fi done + cd - >> /dev/null if [ ! -f $DATA_PATH/hasard/$BLOCK.png ] then cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png fi - touch $DATA_PATH/hasard/$BLOCK.png - rm -f $flag done < $DATA_PATH/block_list.txt diff --git a/scripts/clean_data.sh b/scripts/clean_data.sh index 820f2c9..ae8e22c 100755 --- a/scripts/clean_data.sh +++ b/scripts/clean_data.sh @@ -1,5 +1,14 @@ #!/bin/bash +# Antidater les données des blocks connus +date=`date +%Y%m%d0000` +touch -t $date $DATA_PATH/emptybot/* +for BLOCK in `grep -v LAST $DATA_PATH/block_list.txt | grep -v CACHE | awk '{print $2}'` +do + touch -t $date $DATA_PATH/*/$BLOCK.* +done + +# Effacer ce qui trop vieux if [ "$#" -eq "0" ] then if [ -d $DATA_PATH ] diff --git a/scripts/tweet.sh b/scripts/tweet.sh index 94725c9..982bf42 100755 --- a/scripts/tweet.sh +++ b/scripts/tweet.sh @@ -53,9 +53,23 @@ then echec fi +if [ ! -d $DATA_PATH/twitterbot ] +then + mkdir -p $DATA_PATH/twitterbot +fi + +if [ ! -d $DATA_PATH/emptybot ] +then + mkdir -p $DATA_PATH/emptybot +fi + # # TWEET # + +# tweet Topisto : empty blocks +$APPS_PATH/twitter/emptybot/robot.sh 2>&1 + TWEET=8 if [ $((MINUTE % $TWEET)) -eq 0 ] then @@ -67,7 +81,7 @@ then # "auto likes" from Topisto $APPS_PATH/twitter/likebot/robot.sh 2>&1 else - debug "no TWEET" + debug "skip TWEET" fi # diff --git a/twitter/emptybot/followers.json.example b/twitter/emptybot/followers.json.example new file mode 100644 index 0000000..9e62de5 --- /dev/null +++ b/twitter/emptybot/followers.json.example @@ -0,0 +1 @@ +["topisto42","UnnaxPayments","aureliusdrusus","solacedotcom","omgbtc","ohiobitcoin","LogicScience","redunisproject","Cryptocracy2020","fullstache","callblockapp","marketranger","TheCryptodamus","crypt0co","CryptoassetsUSA","Nadeem_nadi797","cryptomoneyz","BaseCyberSec","Tweetsintoabyss","anthkell98","grattonboy","mac_a_dam","devnullius","123wolfArmy","03018333860","JeffinkoGuru","BitJob_Team","rugigana","Crypto_info321","cointopic_","Chef_JeanPierre","Cienencom","btcltcdigger","AdzCoin_Gift","treyptrsn","n2yolo","SHL0M0ABADD0N","EdwardCulligan","promote_crypto","TheFutureShift","ErickCoval","RIMCorpPK","arhiezvanhoute1","ttoff85","actu_fintech","BeautyBubble","PDX_Trader","Yasirperdesi","cre8hyperledger","Thurse8","cre8capital","icobountyprogs","rob67803423","AphexTwin4ever"] \ No newline at end of file diff --git a/twitter/emptybot/inc/twitter.php b/twitter/emptybot/inc/twitter.php new file mode 100644 index 0000000..3b14f5d --- /dev/null +++ b/twitter/emptybot/inc/twitter.php @@ -0,0 +1,88 @@ +get('account/verify_credentials'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $parameters = array("status" => $message); + + if (($media != NULL)&&($media != '')) + { + $imageMedia = $twitter->upload('media/upload', array('media' => $media)); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $parameters = array( + "status" => $message, + "media_ids" => $imageMedia->media_id_string); + } + + $statuses = $twitter->post("statuses/update", $parameters); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + return TRUE; + } + + public static function thanksRetweet() + { + $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); + $content = $twitter->get('account/verify_credentials'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $results = $twitter->get('statuses/retweets_of_me'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + /* TO DO */ + + return TRUE; + } + + public static function thanksFollowers() + { + $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); + $content = $twitter->get('account/verify_credentials'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $results = $twitter->get('followers/list'); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + + $followers = json_decode(file_get_contents('followers.json')); + foreach($results->users as $user) + if (!in_array($user->screen_name, $followers)) + { + $parameters = array("status" => '@'.$user->screen_name.' thanks following me !'); + $followers[] = $user->screen_name; + $statuses = $twitter->post("statuses/update", $parameters); + if ($twitter->getLastHttpCode() !== 200) return FALSE; + break; // Un à la fois ... + } + file_put_contents('followers.json', json_encode($followers)); + + return TRUE; + } + +} + +?> diff --git a/twitter/emptybot/robot.php b/twitter/emptybot/robot.php new file mode 100644 index 0000000..a62c537 --- /dev/null +++ b/twitter/emptybot/robot.php @@ -0,0 +1,81 @@ +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 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); +} + +?> diff --git a/twitter/emptybot/robot.sh b/twitter/emptybot/robot.sh new file mode 100755 index 0000000..1115e08 --- /dev/null +++ b/twitter/emptybot/robot.sh @@ -0,0 +1,38 @@ +#!/bin/bash +flag=$TMP_PATH/emptybot_bot.flag + +if [ -f $flag ]; +then + echo "empty_bot is already running !" + exit 0 +fi + +touch $flag + +cd $APPS_PATH/twitter/emptybot + +# +# Se lancer pour un tweet sur un block unique +# +BLOCK_LINE=`grep LAST $DATA_PATH/block_list.txt` +BLOCK_HASH=`echo ${BLOCK_LINE} | awk '{print $2}'` +BLOCK_NAME=`echo ${BLOCK_LINE} | awk '{print $1}'` +BLOCK_HEIGHT=`echo ${BLOCK_LINE} | awk '{print $3}'` +BLOCK_SIZE=`echo ${BLOCK_LINE} | awk '{print $4}'` + +if [ $BLOCK_SIZE -eq 1 ] +then + if [ -f $DATA_PATH/hasard/$BLOCK_HASH.png ] + then + if [ ! -f $DATA_PATH/emptybot/$BLOCK_HASH.png ] + then + echo Tweet EmptyBlock for $BLOCK_HASH + echo $BLOCK_LINE >> $DATA_PATH/emptybot/list.txt + php robot.php $BLOCK_HASH $BLOCK_NAME hasard $BLOCK_HEIGHT + # Don't TWEET it again ... + touch $DATA_PATH/twitterbot/$BLOCK_HASH + fi + fi +fi + +rm -f $flag