Notification bot for Steem in 30 lines of code

in #steem8 years ago

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": "[email protected]"}
# 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!

Sort:  

Can you please give us a link to the "python-steem library as well as piston "
Thank you!!

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?

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?

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.

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).

You can get data out of Steem and put it into Ethereum. The procedure would be centralize though.

What do you have in mind?

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.

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.

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.

Can you please explain what this does? The number has me confused.

for c in steem.stream_comments(start=1898900):

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.

I'm getting this error:
sg = sendgrid.SendGridClient(
AttributeError: module 'sendgrid' has no attribute 'SendGridClient'

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

Very interesting post. Great contribution to the community here. I will investigate this further and get my programmer buddies in on this.

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.030
BTC 67621.06
ETH 3787.11
USDT 1.00
SBD 3.50