Steem Voice A0.3 - Steemconnect Integration

in #utopian-io6 years ago (edited)

Steem Voice

Github repository
Author

Hello everyone! Welcome back to the third Steem Voice development update. As the title suggests, in this update, I integrated Steemconnect which allow the user to use advanced commands that require some sort of authorization. First, for the price of 3 steem, I made the app in SteemConnect with the following id: steemvoice.app.
Second thing, I wanted to add the whole list of Steemit users to the app for better recognition so I used get_all_usernames()which generated a 30MB file with over 1 million usernames. I couldn't upload it to Dialogflow so I had to filter those usernames so I wrote this code which filters users who hasn't voted for over a year:

from steem import Steem
from steem.account import Account
import json, time

s = Steem()

def filter(lastvt):
    intdate = '2017-11-30T00:00:00'
    intdate = time.strptime(intdate, "%Y-%m-%dT%H:%M:%S")
    date = time.strptime(lastvt, "%Y-%m-%dT%H:%M:%S")
    return(date>intdate)



users= s.get_all_usernames()
data = []
with open('usernamesfiltered.json', 'a+') as f:
    for i in range(len(users)):
        if filter(Account(users[i])["last_vote_time"]):
            B = {
                "value": users[i],
                "synonyms": [
                    users[i]
                ]
            }
            data.append(B.copy())
    json.dump(data,f)

But It took forever so I measured the process time. It would take 11 days to fully filter the list so I had to find another solution. I tried everything even multiprocessing but it would still take alot of time to complete. If anyone could provide a list of active users that would be great.
With that out of the way let's get to the new features...

New Features

Added a login command

This command allows the user to connect his account meaning it allows him to login using SteemConnect to use the advanced commands:

def r_login():
    login_url = sc.get_login_url( 
        server + "/login",  # This is the callback URL
        "login,custom_json", # The scopes needed (login allows us to verify the user's steem identity while custom_json allows us to Follow, unfollow and mute)
    )
    resp = ask("Please use the button below to login with SteemConnect")
    resp.link_out('the login page', login_url) # To return the button that takes the user to the login page
    return resp

As you can see once the user successfully logged in, the code will redirect him to /login page. So I wrote the code for that page:

def loginpage():
    sc.access_token = request.args.get("access_token")
    return render_template('success.html', variable = sc.me()["name"])

The login page looks like this:


Note: This is my first time writing html I know it looks awful 😂
As you might have noticed, the page tells you to use the check command. Here's the code for it:

def r_check():
    if sc.access_token == None: # No access token
        return ask('Error, Please try to connect your account')
    else:
        return ask('Hello %s ! You can now use commands such as follow, unfollow, mute ...' % sc.me()["name"]) 

Here's the command in action:

Added follow/following check commands

These two commands allow the user to see if he's following a given user or if the user is following him. These commands require no authorization. Here's the code for one of them:

def r_followingcheck(username):
    count = s.get_follow_count(St_username)['following_count'] # To get the total number of following
    thousands = int(count/1000)
    other = count%1000
    lastuser = 0
    flist = []
    for i in range(thousands):  # s.get_following has a limit of 1000 so I have to break the total followers into groups of 1000
        flist.extend(s.get_following(St_username,lastuser,'blog',1000))
        lastuser = flist[-1]['following']
    flist.extend(s.get_following(St_username,lastuser,'blog',other))
    cond = False # Not following
    for i in range(count):
        if flist[i]['following'] == username.strip(): # To remove the extra space
            cond = True # Following

    if cond:
        return ask('You are following %s' % username)
    else:
        return ask('You are not following %s' % username)

I used almost the same code for the other command only replacing a couple of lines.

Added a follow/unfollow/mute command

The user has to connect his account to use these commands or else:


Thanks to emre's SteemConnect client I combined the three commands into a simple one:

def r_follow(inst,username):
    try:
        if inst == 'follow': # To follow a certain user
            follow = Follow(sc.me()["name"], username)
            sc.broadcast([follow.to_operation_structure()])
            return ask('Done, you are now following %s' % username)
        elif inst == 'unfollow': # To unfollow a certain user
            unfollow = Unfollow(sc.me()["name"], username)
            sc.broadcast([unfollow.to_operation_structure()])
            return ask('Done, you are no longer following %s' % username)
        elif inst == 'mute': # To mute a certain user
            ignore = Mute(sc.me()["name"], username)
            sc.broadcast([ignore.to_operation_structure()])
            return ask('Done, %s is now muted' % username)
        else:
            return ask('Error, Please try again!')
    except ValueError:
        return ask('Please connect your account before using this command')

Here's a video showing the follow/unfollow and the previous command:


And here's a video of the mute command:

How to install

Since a moderator asked in the last post, Here's a simplified how to install for those 'who knows what they are doing':
First, You have to know that you won't be able to use advanced commands unless you have a SteemConnect app. Anyway, until I publish Steem Voice offically trough the google assistant app, you can always try it out on your own. You'll need a (preferably) virtual python environment. I suggest using Anaconda. You'll also need ngrok so that Dialogflow can reach your localhost. You will find the all Dialogflow files you need here. You will have to upload the files to Dialogflow account then start the app which you can find in my github. To be honest it's a long process it will need a whole post. if you need any help you can contact me via Discord. I'll be happy to help.

Roadmap

Next on my list is to combine the follow check commands into one and to find a solution for the 'usernames problem'. Then I'll start adding other commands such as power up and send steem...
Also, I'm planning to improve the posts navigation system within the app.

How to contribute?

Everyone is welcome to aid. You can contribute to the development of this project by creating a pull request to my repository. You can also get in touch with me on Discord at Fancybrothers#7429 or on Steem.chat at fancybrothers or simply leave your idea down below.

My Github account: https://github.com/Fancybrothers

Sort:  

Thank you for your contribution. Again a nice update to the awesome project, I am started liking the project. Just Curious, if its possible that can you type the password and username on steemconnect using voice?


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you :) Of course, there is always a way but it would be really frustrating if you've had to spell out a key of almost 50 characters. I think that using the "default" method is way much better and easier.

Thank you for your review, @codingdefined! Keep up the good work!

Hey, @fancybrothers!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.030
BTC 59238.58
ETH 3176.28
USDT 1.00
SBD 2.45