(Controversial) Lightsteem code golf #2 - Send a promotional memo to followers of your witness by emrebeyler

View this thread on steempeak.com
· @emrebeyler · (edited)
$2.75
(Controversial) Lightsteem code golf #2 - Send a promotional memo to followers of your witness
<center><img src="https://steemitimages.com/0x0/https://ipfs.busy.org/ipfs/QmWRuBPiq9AhdsAzBQArCDGcnFtHUYC4P4Wsd6FdTLBd5T"></center>
<center><sup>Welcome to Lightsteem code golf series #2</sup></center>

#### Workflow/Requirements of the evil script
***

- Get followers
- Exclude inactive followers (Last bandwidth update)
- Exclude followers using a proxy for voting
- Exclude followers already voting for you
- Exclude followers already actively voting for 30 witnesses
- Bundle 100 operations into one transaction to keep the network effect limited.

#### Source
***

```python
import logging
import time
from datetime import datetime

from dateutil.parser import parse
from lightsteem.client import Client
from lightsteem.datastructures import Operation


logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logging.basicConfig()

WITNESS_ACCOUNT = "emrebeyler"
MEMO_TEMPLATE = "Hey {username}, I have been running a STEEM witness in the last" \
            " six months. Since you already follow me and have free slots on " \
            "your witness voting, please consider casting a witness vote for" \
            " me. (@{witness_account}). Here you can directly cast a vote: https://steemconnect.com/sign/account-witness-vote?witness=emrebeyler&approve=1"
USERLIST_FILE = "/users/emre/memo-sent.txt"
ACTIVE_KEY = "<active_key>"


def chunks(l, n):
    for i in range(0, len(l), n):
        yield l[i:i + n]


def add_to_list(username):
    with open(USERLIST_FILE, 'a+') as f:
        f.write("%s\n" % username)


def already_sent(username):
    with open(USERLIST_FILE, 'r') as f:
        for line in f.readlines():
            if username in line:
                return True
    return False


def main():
    c = Client(keys=[ACTIVE_KEY,])
    account = c.account(WITNESS_ACCOUNT)

    followers = account.followers()
    print(f"{len(followers)} follower found.")

    suitable_followers = []
    account_details_of_followers = c.get_accounts(followers)
    for follower_data in account_details_of_followers:
        follower = follower_data["name"]

        # check the follower is not dead
        last_bandwidth_update = parse(follower_data["last_bandwidth_update"])

        if (datetime.utcnow() - last_bandwidth_update).total_seconds() > 86400 * 30:
            logger.debug(f"{follower} account looks like dead. Skipping.")
            continue

        # check the follower is full on their votes.
        witness_votes = follower_data["witness_votes"]
        if len(witness_votes) == 30:
            logger.debug(f"{follower} is full. Skipping.")
            continue

        # check the follower has a proxy?
        if follower_data["proxy"]:
            logger.debug(f"{follower} has a proxy. Skipping.")
            continue

        # check the follower is already voting for me
        if WITNESS_ACCOUNT in witness_votes:
            logger.debug(
                f"{follower} is already voting for {WITNESS_ACCOUNT}. Skipping.")
            continue

        suitable_followers.append(follower)


    # handle memos
    print(f"{len(suitable_followers)} found.")

    for follower_username_list in chunks(suitable_followers, 100):
        ops = []
        for follower_username in follower_username_list:
            memo = MEMO_TEMPLATE.format(
                username=follower_username,
                witness_account=WITNESS_ACCOUNT
            )

            if already_sent(follower_username):
                logger.info(f"{follower_username} already got a memo. Skipping")
                continue

            ops.append(
                Operation('transfer', {
                    'from': WITNESS_ACCOUNT,
                    'to': follower_username,
                    'amount': '0.001 SBD',
                    'memo': memo
                })
            )

            add_to_list(follower_username)
        if len(ops):
            c.broadcast(ops)
            time.sleep(3)

if __name__ == '__main__':
    main()

```
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 197 others
properties (23)
post_id62,787,795
authoremrebeyler
permlinkcontroversial-lightsteem-code-golf-2-send-a-memo-to-followers-they-don-t-cast-a-witness-vote-to-you
categorylightsteem
json_metadata{"users":[],"app":"busy\/2.5.6","image":["https:\/\/ipfs.busy.org\/ipfs\/QmWRuBPiq9AhdsAzBQArCDGcnFtHUYC4P4Wsd6FdTLBd5T"],"community":"busy","tags":["lightsteem","codegolf","python","programming","busy"],"format":"markdown","links":[]}
created2018-09-19 10:53:51
last_update2018-09-19 11:16:27
depth0
children9
net_rshares2,391,931,748,657
last_payout2018-09-26 10:53:51
cashout_time1969-12-31 23:59:59
total_payout_value2.404 SBD
curator_payout_value0.342 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length3,987
author_reputation319,480,565,467,431
root_title"(Controversial) Lightsteem code golf #2 - Send a promotional memo to followers of your witness"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (261)
@benfreed ·
I am very new to this and I have tried everything that I'm capable of but I cannot find this place you want me to vote at 
So if you are capable of sending some kind of link that I can click on I will be more than glad to support

My apologies for my inability

But i have search all over since you ask and I can't find place to vote

Thanks for your kindness

Posted using [Partiko Android](https://steemit.com/@partiko-android)
properties (22)
post_id62,790,892
authorbenfreed
permlinkbenfreed-re-emrebeyler-controversial-lightsteem-code-golf-2-send-a-memo-to-followers-they-don-t-cast-a-witness-vote-to-you-20180919t115010587z
categorylightsteem
json_metadata{"app":"partiko"}
created2018-09-19 11:50:12
last_update2018-09-19 11:50:12
depth1
children4
net_rshares0
last_payout2018-09-26 11:50:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length429
author_reputation68,303,733,730
root_title"(Controversial) Lightsteem code golf #2 - Send a promotional memo to followers of your witness"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@emrebeyler ·
Sure, you can use [this link](https://steemconnect.com/sign/account-witness-vote?witness=emrebeyler&approve=1) or go to https://steemit.com/~witnesses and find my name, and vote from there. :)
properties (22)
post_id62,791,538
authoremrebeyler
permlinkre-benfreed-benfreed-re-emrebeyler-controversial-lightsteem-code-golf-2-send-a-memo-to-followers-they-don-t-cast-a-witness-vote-to-you-20180919t120240699z
categorylightsteem
json_metadata{"tags":["lightsteem"],"app":"steemit\/0.1","links":["https:\/\/steemconnect.com\/sign\/account-witness-vote?witness=emrebeyler&approve=1","https:\/\/steemit.com\/~witnesses"]}
created2018-09-19 12:02:42
last_update2018-09-19 12:02:42
depth2
children3
net_rshares0
last_payout2018-09-26 12:02:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length192
author_reputation319,480,565,467,431
root_title"(Controversial) Lightsteem code golf #2 - Send a promotional memo to followers of your witness"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@benfreed ·
I guess I'm just to old to figure this out

Maybe my son can help me latter. 

I'm on a phone app through particle 

So the way you send it to me I can't click on it and I don't know where to search for it 

The if I go to the pc and get on steem I can't find this message

I am fast learner 

But too dumb to do so now 

Sorry
I will figure out some how

Posted using [Partiko Android](https://steemit.com/@partiko-android)
properties (22)
post_id62,792,052
authorbenfreed
permlinkbenfreed-re-emrebeyler-re-benfreed-benfreed-re-emrebeyler-controversial-lightsteem-code-golf-2-send-a-memo-to-followers-they-don-t-cast-a-witness-vote-to-you-20180919t121114636z
categorylightsteem
json_metadata{"app":"partiko"}
created2018-09-19 12:11:15
last_update2018-09-19 12:11:15
depth3
children2
net_rshares0
last_payout2018-09-26 12:11:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length424
author_reputation68,303,733,730
root_title"(Controversial) Lightsteem code golf #2 - Send a promotional memo to followers of your witness"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@fatihyalcin14 ·
Abi simdi burada yeniyim nasıl şeyler yapmalıyım.para kazan neye göre kazanılıyor.sistemin mantığını biraz açıklarmısın
properties (22)
post_id62,805,045
authorfatihyalcin14
permlinkre-emrebeyler-controversial-lightsteem-code-golf-2-send-a-memo-to-followers-they-don-t-cast-a-witness-vote-to-you-20180919t151402672z
categorylightsteem
json_metadata{"tags":["lightsteem"],"app":"steemit\/0.1"}
created2018-09-19 15:14:00
last_update2018-09-19 15:14:00
depth1
children1
net_rshares0
last_payout2018-09-26 15:14:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length119
author_reputation14,234,208,838
root_title"(Controversial) Lightsteem code golf #2 - Send a promotional memo to followers of your witness"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@emrebeyler ·
çokca türkçe kaynak var konu ile ilgili, google araması ile erişebilirsiniz.
properties (22)
post_id62,817,116
authoremrebeyler
permlinkre-fatihyalcin14-re-emrebeyler-controversial-lightsteem-code-golf-2-send-a-memo-to-followers-they-don-t-cast-a-witness-vote-to-you-20180919t183442332z
categorylightsteem
json_metadata{"tags":["lightsteem"],"app":"steemit\/0.1"}
created2018-09-19 18:34:42
last_update2018-09-19 18:34:42
depth2
children0
net_rshares0
last_payout2018-09-26 18:34:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length76
author_reputation319,480,565,467,431
root_title"(Controversial) Lightsteem code golf #2 - Send a promotional memo to followers of your witness"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000