https://github.com/bcit-ci/CodeIgniter
This Live Follower / Following count is the same as the page for calculating yutube subcriber in real time. Here I am trying to use Codeigniter as a framework. For web page display I use bootstrap and to animate the numbers I use odometer. As for the data I take directly from the Steemit API.
Download Codeigniter on its official website https://codeigniter.com/download
Extract it in htdoc folder and rename it as follower
Open it on your editor. Here I use Visual studio code
Open Application > Config > config.php and search $config['base_url'] then add the value with your base url
Open Application > Config > autoload.php and search $autoload['helper'] then add url as array value
Open Application > Config > routes.php and search $route['default_controller'] then change the value from welcome to follower. This is to set the default controller.
Open Application > Controller then create new php file and rename it as Follower.php
Then add this code to the Follower.php file
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Follower extends CI_Controller {
public function index()
{
$this->load->view('follower');
// to load the display page in application > view
}
}
Now go to Application > View and create new php file as follower.php. Why ? because in Controller file you load the page with name is follower, so you should create with the same name.
Add html:5 component to follower.php and add some text in body then run on your browser to see the result
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Live Count</title>
</head>
<body>
Hello Word
</body>
</html>
head component. For more detail you can read here : https://getbootstrap.com/docs/4.3/getting-started/introduction/<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<nav class="navbar navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">Live Count </a>
</div>
</nav>
result :
card class. One for follower and one other for following.<div class="container">
<div class="row mt-5">
<div class="col-sm-6">
<div class="card text-center">
<div class="card-header">
Following count
</div>
<div class="card-body">
test
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-center">
<div class="card-header">
Follower count
</div>
<div class="card-body">
test
</div>
</div>
</div>
</div>
</div>
result :
odometer-car-themeasset in root. Then create 2 new folder again in asset. Its jsand cssodometer.js in asset > js.odometer.js in js folderodometer-theme-car.css in your css folder.odometer-theme-car.css file.head element<script src="asset/js/odometer.js"></script>
<link rel="stylesheet" href="asset/css/odometer-theme-car.css">
card-body class<div id="following" class="odometer">1999</div>
If you see like this that mean the odometer is run as possible
Now add <div id="follower" class="odometer"></div> in card-body for follower and <div id="following" class="odometer"></div> for following like this
follower.php file<script src="//cdn.steemjs.com/lib/latest/steem.min.js"></script>
Open <script> element under </body> then add ready function like this
Add the query from steem js to get the follower and following count. Then get the following and follower count and add it to html element with follower and following id. like this.
steem.api.getFollowCount('team2dev', function(err, result) {
$('#following').html(result.following_count);
$('#follower').html(result.follower_count);
});
result :
setInterval function like this :$(document).ready(function(){
setInterval(function() {
steem.api.getFollowCount('team2dev', function(err, result) {
$('#following').html(result.following_count);
$('#follower').html(result.follower_count);
});
}, 1000);
// 1000 is 1 second
})
Now try to run your live count page in one browser and in other browser you try to follow and unfollow some account, you will see the live count here.
Done, Now we have the some webpage for live follower and following count of steemit account. You can modify it as you want.