create account

Notification bot for Steem in 30 lines of code by xeroc

View this thread on: hive.blogpeakd.comecency.com
· @xeroc ·
$320.85
Notification bot for Steem in 30 lines of code
Dear Steemians,

since the upvote bot was not received well, I'd like to present another
way of using the piston library for bots:

**A @-notification bot** in 30 lines of code

```
from piston.steem import Steem
import os
import json
import sendgrid
steem = Steem()
sg = sendgrid.SendGridClient(
    os.environ['SENDGRID_USERNAME'],
    os.environ['SENDGRID_PASSWORD']
)
message = sendgrid.Mail()
addresses = {"xeroc": "mail@xeroc.org"}
# addresses = os.environ["ADDRESSES"]
for c in steem.stream_comments(start=1898900):
    for user in addresses.keys():
        if "@%s" % user in c["body"]:
            message.add_to(addresses[user])
            message.set_subject('Notification on Steem')
            message.set_text(
                "You have been messaged by %s " % (c["author"]) +
                "in the post @%s/%s" % (c["author"], c["permlink"]) +
                "\n\n" + 
                "You can read the post on Steemit.com:\n" +
                "http://steemit.com/%s/%s#@%s/%s"
                    % (c["category"],
                       c["openingPostIdentifier"],
                       c["author"], c["permlink"])
            )
            message.set_from('notify@steem')
            status, msg = sg.send(message)
            print("\nMessage sent!\n")
```

### Note
This currently requries that you install the python-steem library as well as piston from the development branch.

Have fun!
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorxeroc
permlinknotification-bot-for-steem-in-30-lines-of-code
categorysteem
json_metadata""
created2016-05-30 11:46:15
last_update2016-05-30 11:46:15
depth0
children15
last_payout2016-08-20 17:26:51
cashout_time1969-12-31 23:59:59
total_payout_value160.447 HBD
curator_payout_value160.401 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,416
author_reputation118,819,064,085,695
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,575
net_rshares61,442,989,614,459
author_curate_reward""
vote details (63)
@dana-edwards · (edited)
Python-steem library? I can work with that!  Although I don't know yet the possibilities of the library. I want to know if data can be passed between Steem and another platform such as an Ethereum smart contract?
properties (22)
authordana-edwards
permlinkre-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t115555872z
categorysteem
json_metadata{}
created2016-05-30 11:55:54
last_update2016-05-30 11:56:33
depth1
children6
last_payout2016-08-20 17:26:51
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_length212
author_reputation353,623,611,191,427
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,585
net_rshares0
@censor-this ·
$34.94
Of course you can make a link layer. You would need the etherium library as well to do that. But making something that will take all @ mentions and put them through an etherium contract would definitely be doable. That's the beauty of blockchain, everything is open.
👍  ,
properties (23)
authorcensor-this
permlinkre-dana-edwards-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t123928961z
categorysteem
json_metadata{}
created2016-05-30 12:39:30
last_update2016-05-30 12:39:30
depth2
children1
last_payout2016-08-20 17:26:51
cashout_time1969-12-31 23:59:59
total_payout_value17.468 HBD
curator_payout_value17.468 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length266
author_reputation1,720,978,822,824
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,625
net_rshares19,008,895,905,443
author_curate_reward""
vote details (2)
@dana-edwards ·
$0.02
In that case I have some interesting ideas. I have some ideas to redefine social media by blending intelligent agents with some mechanism to communicate from one blockchain to the next. I like Steem because if the right API is provided we could really do interesting things with intelligent agents (bots).
👍  
properties (23)
authordana-edwards
permlinkre-censor-this-re-dana-edwards-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t180845662z
categorysteem
json_metadata{}
created2016-05-30 18:08:45
last_update2016-05-30 18:08:45
depth3
children0
last_payout2016-08-20 17:26:51
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length305
author_reputation353,623,611,191,427
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,863
net_rshares13,593,232,577
author_curate_reward""
vote details (1)
@censor-this · (edited)
$0.02
http://ethereum.stackexchange.com/questions/2/how-can-an-ethereum-contract-get-data-from-a-website

This is what you're looking for to make etherium contracts pull data. There are a few options in this post. I'm no expert so I won't try to summarize. If you're not worried about "centralization" than it would be easier and cheaper to run a program that links locally or on a server.
👍  , ,
properties (23)
authorcensor-this
permlinkre-dana-edwards-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t131449789z
categorysteem
json_metadata{}
created2016-05-30 13:14:51
last_update2016-05-30 13:17:00
depth2
children1
last_payout2016-08-20 17:26:51
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length383
author_reputation1,720,978,822,824
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,649
net_rshares14,135,710,567
author_curate_reward""
vote details (3)
@dana-edwards ·
Yes this answers part of it. It can get data into an Ethereum smart contract if the data feed is public. It's not ideal because it's probably not good enough to build some form of communication mechanism beyond a data feed but it's a start. I could work with that.
properties (22)
authordana-edwards
permlinkre-censor-this-re-dana-edwards-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t181342409z
categorysteem
json_metadata{}
created2016-05-30 18:13:42
last_update2016-05-30 18:13:42
depth3
children0
last_payout2016-08-20 17:26:51
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_length264
author_reputation353,623,611,191,427
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,865
net_rshares0
@xeroc ·
$0.34
You can get data out of Steem and put it into Ethereum. The procedure would be centralize though.

What do you have in mind?
👍  
properties (23)
authorxeroc
permlinkre-dana-edwards-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t124035183z
categorysteem
json_metadata{}
created2016-05-30 12:40:33
last_update2016-05-30 12:40:33
depth2
children1
last_payout2016-08-20 17:26:51
cashout_time1969-12-31 23:59:59
total_payout_value0.168 HBD
curator_payout_value0.168 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length124
author_reputation118,819,064,085,695
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,626
net_rshares867,219,193,419
author_curate_reward""
vote details (1)
@dana-edwards · (edited)
I would like it to be easy to build intelligent agents which can communicate from (A) -> (B) -> (C) etc where each is a different blockchain and or smart contract. Basically I feel like Steem is somehow an island and without the ability to communicate off the island we miss out on a lot of apps and potential powers. Like imagine what could be done with intelligent agents on Steem which can interface with smart contracts on Ethereum, or any other platform?

I understand it will not be easy but I know with side chains you can possibly build a cross chain gateway. A notification bot or voting bot is nice but if that bot could interact with Ethereum smart contracts for example then it's much nicer.
properties (22)
authordana-edwards
permlinkre-xeroc-re-dana-edwards-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t181147432z
categorysteem
json_metadata{}
created2016-05-30 18:11:48
last_update2016-05-30 18:16:06
depth3
children0
last_payout2016-08-20 17:26:51
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_length703
author_reputation353,623,611,191,427
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,864
net_rshares0
@djleo ·
Can you please explain what this does? The number has me confused.
>for c in steem.stream_comments(start=1898900):
properties (22)
authordjleo
permlinkre-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160717t105327379z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-17 10:53:27
last_update2016-07-17 10:53:27
depth1
children1
last_payout2016-08-20 17:26:51
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_length114
author_reputation1,834,764,955,389
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id142,325
net_rshares0
@xeroc ·
$0.15
`steem.stream_comments()` is a generator that returns all comments when they come in.
The `start` parameter just tells the starting **block**. If you leave it, it will start with the most recent block.

This way, you can store the block number and continue your bot where you have left after an unexpected shutdown.
👍  ,
properties (23)
authorxeroc
permlinkre-djleo-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160717t111148980z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-17 11:11:48
last_update2016-07-17 11:11:48
depth2
children0
last_payout2016-08-20 17:26:51
cashout_time1969-12-31 23:59:59
total_payout_value0.114 HBD
curator_payout_value0.036 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length315
author_reputation118,819,064,085,695
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id142,640
net_rshares99,929,793,640
author_curate_reward""
vote details (2)
@djleo ·
I'm getting this error:
    sg = sendgrid.SendGridClient(
AttributeError: module 'sendgrid' has no attribute 'SendGridClient'
properties (22)
authordjleo
permlinkre-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160718t040901482z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-18 04:09:03
last_update2016-07-18 04:09:03
depth1
children0
last_payout2016-08-20 17:26:51
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_length125
author_reputation1,834,764,955,389
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id159,433
net_rshares0
@hossary ·
Can you please give us a link to the "python-steem library as well as piston " 
Thank you!!
properties (22)
authorhossary
permlinkre-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t115219005z
categorysteem
json_metadata{}
created2016-05-30 11:52:21
last_update2016-05-30 11:52:21
depth1
children2
last_payout2016-08-20 17:26:51
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_reputation10,246,580,355,015
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,581
net_rshares0
@xeroc ·
$0.35
https://github.com/xeroc?tab=repositories
👍  ,
properties (23)
authorxeroc
permlinkre-hossary-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160530t122147489z
categorysteem
json_metadata{}
created2016-05-30 12:21:48
last_update2016-05-30 12:21:48
depth2
children1
last_payout2016-08-20 17:26:51
cashout_time1969-12-31 23:59:59
total_payout_value0.176 HBD
curator_payout_value0.175 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length41
author_reputation118,819,064,085,695
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id18,613
net_rshares899,202,099,955
author_curate_reward""
vote details (2)
@cyberspace · (edited)
Why not an android Swiss Army Knife type of bot for Steem that can be configured to do a number of useful things and requires no coding knowledge?
properties (22)
authorcyberspace
permlinkre-xeroc-re-hossary-re-xeroc-notification-bot-for-steem-in-30-lines-of-code-20170727t080821567z
categorysteem
json_metadata{"tags":["steem"],"app":"steemit/0.1"}
created2017-07-27 08:08:30
last_update2017-07-27 08:08:48
depth3
children0
last_payout2017-08-03 08:08:30
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_length146
author_reputation780,337,768,524
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id9,885,533
net_rshares0
@ldauch ·
Very interesting post. Great contribution to the community here. I will investigate this further and get my programmer buddies in on this.
properties (22)
authorldauch
permlinkre-xeroc-notification-bot-for-steem-in-30-lines-of-code-20170716t042035705z
categorysteem
json_metadata{"tags":["steem"],"app":"steemit/0.1"}
created2017-07-16 04:20:39
last_update2017-07-16 04:20:39
depth1
children0
last_payout2017-07-23 04:20: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_length138
author_reputation1,374,860,836,555
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id8,635,480
net_rshares0
@marsresident ·
Here is an Archive of Cryptocurrency App building Code on Github for anyone creating a Steemit app
https://steemit.com/steem/@marsresident/github-cryptocurrency-app-creation-archive
properties (22)
authormarsresident
permlinkre-xeroc-notification-bot-for-steem-in-30-lines-of-code-20160722t015852268z
categorysteem
json_metadata{"tags":["steem"],"links":["https://steemit.com/steem/@marsresident/github-cryptocurrency-app-creation-archive"]}
created2016-07-22 01:59:06
last_update2016-07-22 01:59:06
depth1
children0
last_payout2016-08-20 17:26:51
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_length181
author_reputation10,013,229,877,794
root_title"Notification bot for Steem in 30 lines of code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id263,961
net_rshares0