A
A
ADMIN INDIGO2018-11-07 12:25:17
Bots
ADMIN INDIGO, 2018-11-07 12:25:17

What is the best way to write a bot?

We need a bot that will check the status in the database and if the status is 1, it should post a post to the Instagramm.
I wrote this in php, here is the bot itself

<?php
set_time_limit(0);
date_default_timezone_set('UTC');
require "rb/database.php";
require __DIR__.'/../vendor/autoload.php';
/////// CONFIG ///////
$username = '';
$password = '';
$debug = true;
$truncatedDebug = false;




$status = R::getAll("SELECT * FROM `user` WHERE status = 0");


if (!empty($status) && !empty($status[0])) {
  
  $status_photo = $status['0']['name'];
    echo $status_photo ;
    echo "\n" ;



$photoFilename = "images/".$status_photo;;
$captionText = 'Тест 2 2';
//////////////////////
$ig = new \InstagramAPI\Instagram($debug, $truncatedDebug);
try {
    $ig->login($username, $password);
} catch (\Exception $e) {
    echo 'Something went wrong: '.$e->getMessage()."\n";
    exit(0);
}
try {
    // The most basic upload command, if you're sure that your photo file is
    // valid on Instagram (that it fits all requirements), is the following:
    // $ig->timeline->uploadPhoto($photoFilename, ['caption' => $captionText]);
    // However, if you want to guarantee that the file is valid (correct format,
    // width, height and aspect ratio), then you can run it through our
    // automatic photo processing class. It is pretty fast, and only does any
    // work when the input file is invalid, so you may want to always use it.
    // You have nothing to worry about, since the class uses temporary files if
    // the input needs processing, and it never overwrites your original file.
    //
    // Also note that it has lots of options, so read its class documentation!
    $photo = new \InstagramAPI\Media\Photo\InstagramPhoto($photoFilename);
    $ig->timeline->uploadPhoto($photo->getFile(), ['caption' => $captionText]);
} catch (\Exception $e) {
    echo 'Something went wrong: '.$e->getMessage()."\n";
}

}

else {
    echo "11111111111111111111111111111111111111111";
    echo "\n" ;
}

?>

Everything works and posts as it should. But I need it so that, as in node.js, it was possible to loop the process so that it makes a request to the database every 5s and if there is a line with status 1, it posts a post.
It is necessary that the bot is constantly authorized so that the inst does not burn that it is a bot.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mShpakov, 2018-11-07
@INDIGO1

And what prevents the crown from pulling a ready-made script?

S
SagePtr, 2018-11-07
@SagePtr

But I need it like in node.js

What's stopping you from doing it with nodejs? As a last resort, make a loop for checking the availability of the necessary data on nodejs, and when the condition is triggered, pull the php script from nodejs as many times as you like (if this script is rewritten into scrap on nodejs).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question