<img src="https://i.hizliresim.com/Gygv9V.jpg"> Hello, This is the third post of "steem-python for dummies" series. If you didn't read the first and second post, take your time and have a look. 1. [steem-python for dummies #1 - Introduction and Basic Operations](https://utopian.io/utopian-io/@emrebeyler/steem-python-for-dummies-1) 2. [steem-python for dummies #2 - Playing with account data](https://utopian.io/utopian-io/@emrebeyler/steem-python-for-dummies-2-playing-with-accounts) In this post, we will study the **get_account_history** method of and create a simple random upvote bot by using it. #### Requirements of the bot Bot, - should listen transfers directed to it. - should check the memo is valid - upvote the memo URL with a random vote (between 1 and 100) **Listening Operations** One can listen transactions by listening new blocks in the each newly produced blocks. However, if you want to see just specific operations for specific accounts, then you have a shortcut. Usage: ``` from steem.account import Account acc = Account('emrebeyler') print(list(acc.get_account_history(-1, 1))) ``` See the raw [output](https://gist.githubusercontent.com/emre/6bffc3c08c99d5060a69f6b16e2051ea/raw/d0c1fbe81ebb4692f6010122f2193a8ffc777b9c/get_account_history_output.txt). It includes last two operations relating to my account in the chain. get_account_history has a bunch of parameters for slicing the data, filtering the operations. It's well documented in the source code, copy/pasting from there. | Parameter | Type | Help | |----------|:-------------:|------:| | index | int | start index for get_account_history| | limit | int | (Optional) skip items until this index| | start | int | (Optional) skip items until this index | | stop | int | (Optional) stop iteration early at this index| | order | (1, -1) | 1 for chronological, -1 for reverse order| | filter_by | (str, list) | filter out all but these operations| | raw_output | (bool) | return history in raw format So, for my case, What I am interested is "transfer" operations. ``` account_history = acc.get_account_history(-1, 100, filter_by=["transfer"]) ``` This will return a list of transfer operations related to my account. **Tip:** This will not return latest 100 transfers. Because filtering is done on the steem-python (client) side, so it will get last 100 operations and filter them by transfers. #### Two steps of success **First step:** Creating an Account instance with bot's posting key. ``` BOT_ACCOUNT = "BOT_ACCOUNT_USERNAME" s = Steem(nodes=["https://rpc.buildteam.io"], keys=["PRIVATE_POSTING_KEYS"]) acc = Account(BOT_ACCOUNT, steemd_instance=s) ``` **Second step:** In an endless loop, check for all transfers and upvote the correct posts with a random vote weight. ``` while True: transfers = acc.get_account_history(-1, 250, filter_by=["transfer"]) for transfer in transfers: if transfer["to"] != BOT_ACCOUNT: continue try: post = Post(transfer.get("memo")) except ValueError as e: if 'Invalid identifier' == e.args[0]: print("Invalid post link. Consider a refund. [%s]" % transfer.get("memo")) continue # get a voting weight between 1 and 100 vote_weight = float(random.randint(+1, +100)) post.commit.vote(post.identifier, vote_weight, account=BOT_ACCOUNT) print("Sleeping for 3 seconds") time.sleep(3) ``` Voila! Bot constantly check for transfers sent to it, and if it sees a valid post, gives a random upvote. Also, reviews the memo is a valid post or not by using steem-python's built-in capabilities. However, this bot is not production ready. If you want to continue developing it, here are my advises: **Missing Features** 1. Refunds. 2. Check for archived posts. (+7 days) 3. Check for duplicate transactions (Bot shouldn't vote same post again and again.) 4. Handle node timeout errors with a try/except blocks. *** That's all for this post. Feel free to ask questions or request topics about steem-python for the incoming posts. <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@emrebeyler/steem-python-for-dummies-3-coding-an-upvote-bot">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>
author | emrebeyler | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
permlink | steem-python-for-dummies-3-coding-an-upvote-bot | ||||||||||||||||||||||||||||||||||||||||||||||||
category | utopian-io | ||||||||||||||||||||||||||||||||||||||||||||||||
json_metadata | "{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"score":84.55162,"default_branch":"master","watchers":59,"open_issues":61,"forks":31,"open_issues_count":61,"archived":false,"mirror_url":null,"forks_count":31,"has_pages":false,"has_wiki":true,"has_downloads":true,"has_projects":true,"has_issues":true,"language":"Python","watchers_count":59,"stargazers_count":59,"size":610,"homepage":null,"svn_url":"https://github.com/steemit/steem-python","clone_url":"https://github.com/steemit/steem-python.git","ssh_url":"git@github.com:steemit/steem-python.git","git_url":"git://github.com/steemit/steem-python.git","pushed_at":"2017-11-21T08:56:52Z","updated_at":"2017-11-24T04:15:20Z","created_at":"2017-03-13T15:37:52Z","deployments_url":"https://api.github.com/repos/steemit/steem-python/deployments","releases_url":"https://api.github.com/repos/steemit/steem-python/releases{/id}","labels_url":"https://api.github.com/repos/steemit/steem-python/labels{/name}","notifications_url":"https://api.github.com/repos/steemit/steem-python/notifications{?since,all,participating}","milestones_url":"https://api.github.com/repos/steemit/steem-python/milestones{/number}","pulls_url":"https://api.github.com/repos/steemit/steem-python/pulls{/number}","issues_url":"https://api.github.com/repos/steemit/steem-python/issues{/number}","downloads_url":"https://api.github.com/repos/steemit/steem-python/downloads","archive_url":"https://api.github.com/repos/steemit/steem-python/{archive_format}{/ref}","merges_url":"https://api.github.com/repos/steemit/steem-python/merges","compare_url":"https://api.github.com/repos/steemit/steem-python/compare/{base}...{head}","contents_url":"https://api.github.com/repos/steemit/steem-python/contents/{+path}","issue_comment_url":"https://api.github.com/repos/steemit/steem-python/issues/comments{/number}","comments_url":"https://api.github.com/repos/steemit/steem-python/comments{/number}","git_commits_url":"https://api.github.com/repos/steemit/steem-python/git/commits{/sha}","commits_url":"https://api.github.com/repos/steemit/steem-python/commits{/sha}","subscription_url":"https://api.github.com/repos/steemit/steem-python/subscription","subscribers_url":"https://api.github.com/repos/steemit/steem-python/subscribers","contributors_url":"https://api.github.com/repos/steemit/steem-python/contributors","stargazers_url":"https://api.github.com/repos/steemit/steem-python/stargazers","languages_url":"https://api.github.com/repos/steemit/steem-python/languages","statuses_url":"https://api.github.com/repos/steemit/steem-python/statuses/{sha}","trees_url":"https://api.github.com/repos/steemit/steem-python/git/trees{/sha}","git_refs_url":"https://api.github.com/repos/steemit/steem-python/git/refs{/sha}","git_tags_url":"https://api.github.com/repos/steemit/steem-python/git/tags{/sha}","blobs_url":"https://api.github.com/repos/steemit/steem-python/git/blobs{/sha}","tags_url":"https://api.github.com/repos/steemit/steem-python/tags","branches_url":"https://api.github.com/repos/steemit/steem-python/branches{/branch}","assignees_url":"https://api.github.com/repos/steemit/steem-python/assignees{/user}","events_url":"https://api.github.com/repos/steemit/steem-python/events","issue_events_url":"https://api.github.com/repos/steemit/steem-python/issues/events{/number}","hooks_url":"https://api.github.com/repos/steemit/steem-python/hooks","teams_url":"https://api.github.com/repos/steemit/steem-python/teams","collaborators_url":"https://api.github.com/repos/steemit/steem-python/collaborators{/collaborator}","keys_url":"https://api.github.com/repos/steemit/steem-python/keys{/key_id}","forks_url":"https://api.github.com/repos/steemit/steem-python/forks","url":"https://api.github.com/repos/steemit/steem-python","fork":false,"description":"Official Python Library for STEEM","html_url":"https://github.com/steemit/steem-python","private":false,"owner":{"site_admin":false,"type":"Organization","received_events_url":"https://api.github.com/users/steemit/received_events","events_url":"https://api.github.com/users/steemit/events{/privacy}","repos_url":"https://api.github.com/users/steemit/repos","organizations_url":"https://api.github.com/users/steemit/orgs","subscriptions_url":"https://api.github.com/users/steemit/subscriptions","starred_url":"https://api.github.com/users/steemit/starred{/owner}{/repo}","gists_url":"https://api.github.com/users/steemit/gists{/gist_id}","following_url":"https://api.github.com/users/steemit/following{/other_user}","followers_url":"https://api.github.com/users/steemit/followers","html_url":"https://github.com/steemit","url":"https://api.github.com/users/steemit","gravatar_id":"","avatar_url":"https://avatars3.githubusercontent.com/u/17434692?v=4","id":17434692,"login":"steemit"},"full_name":"steemit/steem-python","name":"steem-python","id":84843862},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","steempython","python","programming","bots"],"users":["emrebeyler"],"links":["https://utopian.io/utopian-io/@emrebeyler/steem-python-for-dummies-1","https://utopian.io/utopian-io/@emrebeyler/steem-python-for-dummies-2-playing-with-accounts","https://gist.githubusercontent.com/emre/6bffc3c08c99d5060a69f6b16e2051ea/raw/d0c1fbe81ebb4692f6010122f2193a8ffc777b9c/get_account_history_output.txt"]}" | ||||||||||||||||||||||||||||||||||||||||||||||||
created | 2017-11-24 13:57:00 | ||||||||||||||||||||||||||||||||||||||||||||||||
last_update | 2017-11-24 13:58:51 | ||||||||||||||||||||||||||||||||||||||||||||||||
depth | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
children | 8 | ||||||||||||||||||||||||||||||||||||||||||||||||
last_payout | 2017-12-01 13:57:00 | ||||||||||||||||||||||||||||||||||||||||||||||||
cashout_time | 1969-12-31 23:59:59 | ||||||||||||||||||||||||||||||||||||||||||||||||
total_payout_value | 15.518 HBD | ||||||||||||||||||||||||||||||||||||||||||||||||
curator_payout_value | 5.831 HBD | ||||||||||||||||||||||||||||||||||||||||||||||||
pending_payout_value | 0.000 HBD | ||||||||||||||||||||||||||||||||||||||||||||||||
promoted | 0.000 HBD | ||||||||||||||||||||||||||||||||||||||||||||||||
body_length | 4,355 | ||||||||||||||||||||||||||||||||||||||||||||||||
author_reputation | 448,535,049,068,622 | ||||||||||||||||||||||||||||||||||||||||||||||||
root_title | "steem-python for dummies #3 - Coding an upvote bot" | ||||||||||||||||||||||||||||||||||||||||||||||||
beneficiaries |
| ||||||||||||||||||||||||||||||||||||||||||||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||||||||||||||||||||||||||||||||||||||||||||
percent_hbd | 5,000 | ||||||||||||||||||||||||||||||||||||||||||||||||
post_id | 21,394,691 | ||||||||||||||||||||||||||||||||||||||||||||||||
net_rshares | 10,696,775,201,099 | ||||||||||||||||||||||||||||||||||||||||||||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
isteemit | 0 | 9,047,081,464 | 3% | ||
kat-scratch | 0 | 2,437,956,920 | 100% | ||
on247 | 0 | 710,131,867 | 100% | ||
zhanmusi | 0 | 0 | 1% | ||
sisterray | 0 | 719,094,435 | 100% | ||
banjo | 0 | 458,675,273 | 1% | ||
thecrazygm | 0 | 465,863,482 | 100% | ||
steemit-turkey | 0 | 14,135,803,376 | 30% | ||
mkt | 0 | 42,057,142,776 | 100% | ||
monomyth | 0 | 29,227,425,600 | 62% | ||
droucil | 0 | 145,425,684,129 | 100% | ||
steemreports | 0 | 27,809,780,259 | 100% | ||
codingdefined | 0 | 23,293,644,785 | 100% | ||
bigdeej | 0 | 2,159,499,389 | 1% | ||
aafeng | 0 | 8,133,766,508 | 20% | ||
leir | 0 | 1,022,827,517 | 20% | ||
grandpawhale | 0 | 41,479,957,300 | 1% | ||
crokkon | 0 | 19,329,933,687 | 100% | ||
funkie68 | 0 | 1,216,266,433 | 1% | ||
bayeco06 | 0 | 1,302,160,623 | 100% | ||
feedyourminnows | 0 | 28,697,806,814 | 40% | ||
sunray | 0 | 3,072,027,048 | 100% | ||
minnowhub | 0 | 866,410,370 | 21% | ||
kiaazad | 0 | 16,821,030,446 | 100% | ||
sorucevap | 0 | 11,024,950,524 | 25% | ||
anadolu | 0 | 41,144,419,480 | 10% | ||
utopian-io | 0 | 9,895,834,854,729 | 7% | ||
emrebeyler | 0 | 27,781,117,874 | 100% | ||
habercitr | 0 | 4,326,057,330 | 100% | ||
iamafra | 0 | 2,080,350,884 | 11% | ||
zoltarian | 0 | 2,369,554,406 | 100% | ||
bahadirbayin | 0 | 833,189,015 | 100% | ||
forkonti | 0 | 10,487,720,266 | 100% | ||
qustodian | 0 | 116,892,029,901 | 53.64% | ||
ajmaln | 0 | 1,003,871,956 | 100% | ||
gokos | 0 | 1,080,261,919 | 100% | ||
omeratagun | 0 | 156,499,953,904 | 100% | ||
kutayeen | 0 | 1,167,937,915 | 100% | ||
ayoubma | 0 | 945,844,211 | 100% | ||
aydant | 0 | 1,144,269,173 | 100% | ||
mushymushroom | 0 | 1,160,540,781 | 100% | ||
fddnn | 0 | 1,108,306,330 | 100% | ||
bekirsolak | 0 | 0 | 1% | ||
petervroom | 0 | 0 | 100% | ||
closedai | 0 | 0 | 100% |
<div class='pull-right'>https://cdn.steemitimages.com/DQmaHThyECGhEx8tSfHZbiMFRNYjJ35K92cDgiJjkzBUaJo/One%20sip%20of%20BEER%20for%20you.gif<p><sup><a href='https://steem-engine.com/?p=market&t=BEER'>View or trade </a> <code>BEER</code>.</sup></p></div><center><br><br> <p> Hey @emrebeyler, here is a little bit of <code>BEER</code> from @isnochys for you. Enjoy it!</p> </center>
author | beerlover |
---|---|
permlink | re-steem-python-for-dummies-3-coding-an-upvote-bot-20191124t050812z |
category | utopian-io |
json_metadata | "{"app": "beem/0.21.1"}" |
created | 2019-11-24 05:08:15 |
last_update | 2019-11-24 05:08:15 |
depth | 1 |
children | 0 |
last_payout | 2019-12-01 05:08:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 379 |
author_reputation | 25,765,264,402,130 |
root_title | "steem-python for dummies #3 - Coding an upvote bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 92,780,926 |
net_rshares | 0 |
Thank you for this documentation I've been learning and training
author | doctorvee |
---|---|
permlink | re-emrebeyler-steem-python-for-dummies-3-coding-an-upvote-bot-20171207t182551510z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"community":"busy","app":"busy/1.0.0"} |
created | 2017-12-07 18:25:54 |
last_update | 2017-12-07 18:25:54 |
depth | 1 |
children | 0 |
last_payout | 2017-12-14 18:25:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 65 |
author_reputation | 608,629,613,641 |
root_title | "steem-python for dummies #3 - Coding an upvote bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 22,693,130 |
net_rshares | 0 |
2 years old !BEER
author | isnochys |
---|---|
permlink | re-steem-python-for-dummies-3-coding-an-upvote-bot-20191124t050756z |
category | utopian-io |
json_metadata | "{"app": "beem/0.20.23"}" |
created | 2019-11-24 05:08:00 |
last_update | 2019-11-24 05:08:00 |
depth | 1 |
children | 0 |
last_payout | 2019-12-01 05:08:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 17 |
author_reputation | 48,455,405,511,148 |
root_title | "steem-python for dummies #3 - Coding an upvote bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 92,780,925 |
net_rshares | 0 |
Thank you for the contribution. It has been approved. You can contact us on [Discord](https://discord.gg/UCvqCsx). **[[utopian-moderator]](https://utopian.io/moderators)**
author | jefpatat |
---|---|
permlink | re-emrebeyler-steem-python-for-dummies-3-coding-an-upvote-bot-20171124t140030397z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"} |
created | 2017-11-24 14:00:24 |
last_update | 2017-11-24 14:00:24 |
depth | 1 |
children | 1 |
last_payout | 2017-12-01 14:00:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 172 |
author_reputation | 26,609,526,234,408 |
root_title | "steem-python for dummies #3 - Coding an upvote bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 21,395,006 |
net_rshares | 0 |
lightning fast! thanks.
author | emrebeyler |
---|---|
permlink | re-jefpatat-re-emrebeyler-steem-python-for-dummies-3-coding-an-upvote-bot-20171124t140111022z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2017-11-24 14:01:12 |
last_update | 2017-11-24 14:01:12 |
depth | 2 |
children | 0 |
last_payout | 2017-12-01 14:01:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 23 |
author_reputation | 448,535,049,068,622 |
root_title | "steem-python for dummies #3 - Coding an upvote bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 21,395,074 |
net_rshares | 0 |
Brilliant @emrebeyler, thank you
author | petervroom |
---|---|
permlink | re-emrebeyler-steem-python-for-dummies-3-coding-an-upvote-bot-20180629t074033076z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1","users":["emrebeyler"]} |
created | 2018-06-29 07:40:36 |
last_update | 2018-06-29 07:41:45 |
depth | 1 |
children | 0 |
last_payout | 2018-07-06 07:40:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 32 |
author_reputation | 12,060,305,749,902 |
root_title | "steem-python for dummies #3 - Coding an upvote bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 62,710,621 |
net_rshares | 0 |
### Hey @emrebeyler I am @utopian-io. I have just upvoted you at 7% Power! #### Achievements - You have less than 500 followers. Just gave you a gift to help you succeed! - Seems like you contribute quite often. AMAZING! #### Suggestions - Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck! - Contribute more often to get higher and higher rewards. I wish to see you often! - I introduced a competition factor. My vote is based also on how competitive the category used is. #### Human Curation - Do you believe you deserved more? Let a human curator know. <a href="https://discord.gg/PrzCKpq">Get in touch on Discord</a> #### Community-Driven Witness! I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER! - <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a> - <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a> - Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a> [](https://steemit.com/~witnesses) **Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
author | utopian-io |
---|---|
permlink | re-emrebeyler-steem-python-for-dummies-3-coding-an-upvote-bot-20171125t124206418z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"} |
created | 2017-11-25 12:42:06 |
last_update | 2017-11-25 12:42:06 |
depth | 1 |
children | 1 |
last_payout | 2017-12-02 12:42:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,573 |
author_reputation | 152,955,367,999,756 |
root_title | "steem-python for dummies #3 - Coding an upvote bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 21,479,815 |
net_rshares | 0 |
maybe next time.
author | zhanmusi |
---|---|
permlink | re-utopian-io-re-emrebeyler-steem-python-for-dummies-3-coding-an-upvote-bot-20180422t051937518z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-04-22 05:19:36 |
last_update | 2018-04-22 05:19:36 |
depth | 2 |
children | 0 |
last_payout | 2018-04-29 05:19:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.342 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 16 |
author_reputation | 5,566,405,034,040 |
root_title | "steem-python for dummies #3 - Coding an upvote bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 51,424,645 |
net_rshares | 52,552,493,993 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
zhanmusi | 0 | 52,552,493,993 | 100% |