create account

Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04 by yanosh01

View this thread on: hive.blogpeakd.comecency.com
· @yanosh01 · (edited)
$1.90
Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04
### Preview
![preview.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656006/wvouk7myt3bycxj7jzvb.png)

### Description
If you have your own Bid Bot, you are probably looking for more delegation.
This script is the First part of a Full Guide.

My Bid Bot for Minnows is @astrobot.
Read more on this article: https://steemit.com/astrobot/@astrobot/introducing-astrobot-a-new-bidding-upvote-bot

This source Code, It's a PHP  code integrated with Python for STEEM Blockchain and  used for:

- Permit users to delegate Steem Power - To Your BOT
- Permit everyone to check who is delegating Vest to Your BOT and how Much

In the second part we will calculate proportionally how much every users should earn, based on the Slogan Schema:

### The Bot Slogan

You can earn daily passive income by delegating your Steem Power (Vest) to @astrobot and You can undelegate your SP anytime you want (it takes one week)
#### How much will I earn?
It depends on your SP contribution and how much the bot has earned on previous day. The bot distributes 80% rewards to all delegators next next day. Consider this scenary example: There are two delegators - 'Pippo' & 'Pluto'.
Pippo delegated 900 VP & Pluto delegated 100 VP: Astrobot VP is 1000 VP

Pippo delegated 90% of Total Astrobot VP & Pluto delegated 10% of Total Astrobot VP

Astrobot earned $100 SBD on previous day. Next day it is going to distribute the 80% of $100 SBD to all delegators.

Pippo will receive the 90% of 80% earned by astrobot & Pluto will receive the 10% of 80% earned by astrobot

Pippo will receive $72 SBD & Pluto will receive $8 SBD

If the bot earns no money on previous day, nobody will get paid on the following day.



### Requirements:

- Apache2 modules
- Php modules
- Python 3

### Install Requirements:

APACHE2:

sudo apt-get update sudo apt-get install apache2 sudo ufw allow 'Apache Full' sudo systemctl status apache2 sudo systemctl enable apache2

PHP:

sudo apt-get install -y php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-common php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql php7.0-mcrypt php7.0-zip sudo systemctl restart apache2.service

PYTHON3:

sudo add-apt-repository ppa:jonathonf/python-3.6 sudo apt update sudo apt install python3.6

### Script Components:

https://github.com/yanosh01/Steem-Power-calculator-and-delegator-on-PHP.git

- Index.php
- Delegator.py
- astrobot.jpg

### Source Code:

Thanks to @twinner for this Python source code:

https://steemit.com/steemdata/@twinner/2-python-scripts-for-steemdata-to-get-a-list-of-all-steempower-delegators-or-delegatees-for-a-specific-account

I'll rewrite it for give users the possibility to have the code complete

Delegator.py
``` 
from steemdata import SteemData
from collections import Counter
import sys

s = SteemData()

delegations = s.Operations.find( {
    '$and': [
        {'type' : 'delegate_vesting_shares'},
        {'delegatee': sys.argv[1]}
    ]
} )             

delegation_map = dict()

for delegation in delegations:
    delegator = str(delegation['delegator'])
    vestings = delegation['vesting_shares']
    amount = vestings['amount']
    delegation_map[delegator] = amount

i=1

for key in sorted(delegation_map):
    if delegation_map[key] > 0:
        print('|' + str(i) + '|' + key + '|' + str(delegation_map[key])+ '|')
        i += 1


```

Index.php

``` 
<html>
<body>
<script>
function process()
{
var url="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=" + document.getElementById("url").value +"&delegatee=astrobot&vesting_shares="+document.getElementById("steempower").value +"%20VESTS";
location.href=url;
return false;
}
</script>

<form onSubmit="return process();">
<center>
<h2 style="color:Black;"> Welcome to <a href="https://steemit.com/@astrobot">@astrobot</a> Delegation service. </h2><p>
<center><img src="/images/astrobot.jpg">
</p>
<p>
</p>
You can earn daily passive income by delegating your Steem Power (Vest) to <a href="https://steemit.com/@astrobot">@astrobot</a>. However You can undelegate your SP anytime you want (it takes one week)

<h2 style="color:Black;"> How much will I earn?</h2>
It depends on your SP contribution and how much the bot has earned on previous day. The bot distributes 80% rewards to all delegators next next day. 
Consider this scenary example:
There are two delegators - 'Pippo' & 'Pluto'.
<p>
Pippo delegated 900 VP & Pluto delegated 100 VP: Astrobot VP is 1000 VP
<p>
<p>
Pippo delegated 90% of Total Astrobot VP & Pluto delegated 10% of Total Astrobot VP
<p>
<p>
Astrobot earned $100 SBD on previous day.
Next day it is going to distribute the 80% of $100 SBD to all delegators. 
<p>
<p>
Pippo will receive the 90% of 80% earned by astrobot & Pluto will receive the 10% of 80% earned by astrobot
<p>
<p>
Pippo will receive $72 SBD & Pluto will receive $8  SBD
<p>
<p>

If the bot earns no money on previous day, nobody will get paid on the following day.
<p>
<hr>
<p>
Select The Amount Of Steem Power You Wish To Delegate and Enter Your Steemit Username Below To Get Started.</p>
Select Amount Of Steem Power To Delegate: 
<select id="steempower">
<option value="51376.58419">25 Steem Power</option>
<option value="102753.16839">50 Steem Power</option>
<option value="205506.33678">100 Steem Power</option>
<option value="411012.67356">200 Steem Power</option>
<option value="1027530.168390">500 Steem Power</option>
<option value="2055060.336780">1000 Steem Power</option>
</select>
</br>
Enter Steemit Username:<input type="text" name="url" id="url"> <input type="submit" value="Delegate Now">

</center>
</form>
<p>
<h2>This service use Steemconnect for authenticate users and does not store any passwords</h2>

<hr>
This is the list of Delegator and their Vest:
<p>

<?php
$output = shell_exec("python3 delegator.py astrobot");
echo nl2br($output);
?>


</body> 
</html>

```

### How to start the project?

Copy files into folder /var/www/html and edit index.PHP as you need

### Explanation

The file Delegator.py is used to calculate who is delegating Vest. To integrate into php code we use:

![deleg.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656217/b2i7oqntc6g7v0zvlwtj.png)

Php part to run the python script and print output on web page:

```
<? php
$output = shell_exec("python3 delegator.py astrobot");
echo nl2br($output);
?>

```
nl2br tell to wordwrap output.
Change "astrobot" with the username of your bot

This is the form where you can delegate SP based on Predefined Value

![howmuch.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656348/vf6ecghzt7mrnndixuvm.png)


```
var url="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=" + document.getElementById("url").value +"&delegatee=astrobot&vesting_shares="+document.getElementById("steempower").value +"%20VESTS";

```

This variable is used to delegate vest based on the form field you insert.
Remember to change astrobot with your bot

All the rest is like the HTML code


### Remember to upvote me as your Witness and to Join on my [discord channel](https://discord.gg/cX3KvsY)

https://steemit.com/~witnesses

![DQmbVGHGMJNhUpmqUTeDvvMGaevzaNFdib24Sa9XhVS48XM.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656513/xlvikgysvitfotauds9k.gif)

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@yanosh01/php-site-for-bid-bot-part-1-calculate-vest-of-all-steem-delegators-and-give-the-possibility-to-new-users-to-delegate-vest-on">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authoryanosh01
permlinkphp-site-for-bid-bot-part-1-calculate-vest-of-all-steem-delegators-and-give-the-possibility-to-new-users-to-delegate-vest-on
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":126212273,"name":"Steem-Power-calculator-and-delegator-on-PHP","full_name":"yanosh01/Steem-Power-calculator-and-delegator-on-PHP","html_url":"https://github.com/yanosh01/Steem-Power-calculator-and-delegator-on-PHP","fork":false,"owner":{"login":"yanosh01"}},"pullRequests":[],"platform":"github","type":"development","tags":["utopian-io","developer","bot","script","python"],"users":["astrobot.","astrobot","twinner","yanosh01"],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656006/wvouk7myt3bycxj7jzvb.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656217/b2i7oqntc6g7v0zvlwtj.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656348/vf6ecghzt7mrnndixuvm.png","https://discord.gg/cX3KvsY","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656513/xlvikgysvitfotauds9k.gif"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656006/wvouk7myt3bycxj7jzvb.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656217/b2i7oqntc6g7v0zvlwtj.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656348/vf6ecghzt7mrnndixuvm.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1521656513/xlvikgysvitfotauds9k.gif"],"moderator":{"account":"decebal2dac","time":"2018-03-24T21:21:55.611Z","flagged":true,"reviewed":false,"pending":false},"questions":[],"score":null}
created2018-03-21 18:29:21
last_update2018-03-24 21:21:54
depth0
children6
last_payout2018-03-28 18:29:21
cashout_time1969-12-31 23:59:59
total_payout_value1.444 HBD
curator_payout_value0.451 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,515
author_reputation12,371,240,230,142
root_title"Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,796,698
net_rshares805,359,624,136
author_curate_reward""
vote details (39)
@decebal2dac ·
Your contribution cannot be approved because it is not as informative as other contributions. See the [Utopian Rules](https://utopian.io/rules). Contributions need to be informative and descriptive in order to help readers and developers understand them.

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authordecebal2dac
permlinkre-yanosh01-php-site-for-bid-bot-part-1-calculate-vest-of-all-steem-delegators-and-give-the-possibility-to-new-users-to-delegate-vest-on-20180324t212202714z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-03-24 21:22:03
last_update2018-03-24 21:22:03
depth1
children0
last_payout2018-03-31 21:22:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length373
author_reputation13,975,053,566,819
root_title"Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id46,396,281
net_rshares0
@dedyrendra ·
Details and easy to understanding.... Let me resteem this post for infomation to my frienda
👍  
properties (23)
authordedyrendra
permlinkre-yanosh01-php-site-for-bid-bot-part-1-calculate-vest-of-all-steem-delegators-and-give-the-possibility-to-new-users-to-delegate-vest-on-20180321t185639550z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-03-21 18:56:42
last_update2018-03-21 18:56:42
depth1
children1
last_payout2018-03-28 18:56:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length91
author_reputation5,864,694,273,636
root_title"Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,800,822
net_rshares6,820,398,367
author_curate_reward""
vote details (1)
@yanosh01 ·
thanks for reading... I hope it wiil help  people!!!
properties (22)
authoryanosh01
permlinkre-dedyrendra-re-yanosh01-php-site-for-bid-bot-part-1-calculate-vest-of-all-steem-delegators-and-give-the-possibility-to-new-users-to-delegate-vest-on-20180321t195311275z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-03-21 19:53:12
last_update2018-03-21 19:53:12
depth2
children0
last_payout2018-03-28 19:53:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length52
author_reputation12,371,240,230,142
root_title"Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,809,001
net_rshares0
@minnowsupport ·
<p>Congratulations!  This post has been upvoted from the communal account, @minnowsupport, by Yanosh01 from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows.  Please find us at the <a href="https://discord.gg/HYj4yvw"> Peace, Abundance, and Liberty Network (PALnet) Discord Channel</a>.  It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.</p> <p>If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=102530.639667%20VESTS">50SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=205303.639667%20VESTS">100SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=514303.639667%20VESTS">250SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=1025303.639667%20VESTS">500SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=2053030.639667%20VESTS">1000SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=10253030.639667%20VESTS">5000SP</a>. <br><strong>Be sure to leave at least 50SP undelegated on your account.</strong></p>
properties (22)
authorminnowsupport
permlinkre-php-site-for-bid-bot-part-1-calculate-vest-of-all-steem-delegators-and-give-the-possibility-to-new-users-to-delegate-vest-on-20180321t201338
categoryutopian-io
json_metadata""
created2018-03-21 20:13:39
last_update2018-03-21 20:13:39
depth1
children0
last_payout2018-03-28 20:13:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,704
author_reputation148,902,805,319,183
root_title"Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,811,823
net_rshares0
@seyiodus ·
Thanks for this. it's really a useful tip.
I will get back to you.
properties (22)
authorseyiodus
permlinkre-yanosh01-php-site-for-bid-bot-part-1-calculate-vest-of-all-steem-delegators-and-give-the-possibility-to-new-users-to-delegate-vest-on-20180321t203634418z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-03-21 20:36:45
last_update2018-03-21 20:36:45
depth1
children1
last_payout2018-03-28 20:36:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length66
author_reputation11,664,014,052,840
root_title"Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,815,064
net_rshares0
@yanosh01 ·
Ty, you are welcome!!!
properties (22)
authoryanosh01
permlinkre-seyiodus-re-yanosh01-php-site-for-bid-bot-part-1-calculate-vest-of-all-steem-delegators-and-give-the-possibility-to-new-users-to-delegate-vest-on-20180321t204014538z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-03-21 20:40:15
last_update2018-03-21 20:40:15
depth2
children0
last_payout2018-03-28 20:40:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length22
author_reputation12,371,240,230,142
root_title"Php site for Bid Bot (Part 1) - Calculate Vest of all Steem Delegators and give the possibility to new users to delegate Vest on your Bot - Ubuntu 16.04"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id45,815,555
net_rshares0