create account

Steemautomated: 0.0.3 - Voting Is Live! Added Server Side Voting Application by steempytutorials

View this thread on: hive.blogpeakd.comecency.com
· @steempytutorials ·
$94.14
Steemautomated: 0.0.3 - Voting Is Live! Added Server Side Voting Application
![Screenshot 2018-07-24 18.50.48.png](https://cdn.steemitimages.com/DQmaveG4yAGBA3dG1bKmQDW9hq73vUEMcp8vcem4WpVLFHr/Screenshot%202018-07-24%2018.50.48.png)


### Repository
https://github.com/Juless89/steemautomated

### Commit request
https://github.com/Juless89/steemautomated/commit/8f6e256a7b9688252941767772cb6746ccd0e4e1

### Website 
https://steemautomated.eu/


### New Features
#### Voting is now live
I created a server side version of the standalone voter that uses a MySQL database and Steemconnect authentication. The flow for a vote is as follows:

Every block a list of authors to be upvoted is fetched from the server. 

```
# Fetch author to be upvoted list
self.upvote_list = []
for author in self.db.get_authors():
    self.upvote_list.append(author[0])
```

The blocks transactions are scanned for comment which are then processed

```
for transaction in block['transactions']:
    if transaction['operations'][0][0] == 'comment':
        comment = transaction['operations'][0][1]
        self.process_comment(comment)
```

The comment is verified to be a new post and the author is verified to be in the upvote list. If so post is send to the queue.

```
def process_comment(self, comment):
    parent_author = comment['parent_author']
    author = comment['author']

    if parent_author == '' and author in self.upvote_list:
        permlink = comment['permlink']
        if self.verify_post(author, permlink):
            print(f'\n\n{self.timestamp} Block: {self.block}')
            print(f"New post\nAuthor: {author}")
            self.add_to_queue(author, permlink)
```

For each author all voting rules are retrieved and checked for their specific rules. If the daily limit has not been reached than the post can be added to the queue. When the delay is 0 a direct vote is casted. Posts are added to both the queue and the log. The log is used to determine the daily posts an author has already made. As it is possible to make a new post while there is already a post in the queue. In this instance just checking the log would retrieve an incorrent number.

```
def add_to_queue(self, author, permlink):
    for vote in self.db.get_votes(author):
        voter, weight, limit, delay = vote
        vote_log = self.db.get_vote_log(voter, author, self.timestamp)
        print(f"\nVoter: {voter}\nWeight: {weight}\nLimit: " +
              f"{limit}\nDelay: {delay}")

        if delay != 0:
            self.db.add_to_queue(
                author, voter, weight, limit, delay,
                permlink, self.timestamp,
            )
        elif len(vote_log) < limit:
            self.db.add_to_log(
                author, voter, permlink,
                weight, self.times,
                )
            self.vote(voter, author, permlink, weight)
```

To perform a vote first the access token is checked to still be valid, if not is is updated. The vote is then broadcasted. In case of any errors the post gets added to the error_log for manual review. As of now it does not check yet for revoked authorisation on the Steemconnect side. A user has revoked access, his rules will result in an error message. Success or fail, the vote is removed from the queue and has its log updated.

```
def vote(self, voter, author, permlink, weight):
    result = self.db.get_user_auth(voter)
    access_token, refresh_token, expire_on = result[0]
    dt = datetime.now()
    c = Client(
            client_id="",
            client_secret="",
            access_token=access_token,
        )

    try:
        # Verify access_token
        if dt > expire_on:
            access_token = self.refresh_token(refresh_token)
            result = c.refresh_access_token(
                        refresh_token,
                        "login,vote"  # scopes
            )
            access_token = result['access_token']
            refresh_token = result['refresh_token']
            expires_in = result['expires_in']
            self.db.update_authentication_tokens(
                voter,
                access_token,
                refresh_token,
                expires_in,
                self.timestamp,
            )
            print('Updated access token\n')

        # Perform vote
        vote = Vote(voter, author, permlink, weight)
        result = c.broadcast([vote.to_operation_structure()])

        # Log vote
        if 'error' in result:
            message = result['error_description']
            self.db.add_to_error_log(
                voter, author, permlink, weight,
                message, self.timestamp,
             )
        else:
            message = 'Succes'
            self.db.update_log(voter, permlink, message)
            print(f"Voter: {voter}\nAuthor: {author}\n" +
                  f"Permlink: {permlink}\nWeight: {weight}\n" +
                  "Upvote succes\n")
    except Exception as error:
        self.db.add_to_error_log(
                voter, author, permlink,
                weight, error, self.timestamp,
        )
```

#### Latest votes
In addition the front page now offers a live overview of the latest votes.
![Screenshot 2018-07-28 22.15.08.png](https://cdn.steemitimages.com/DQmPJhKwrL71fDUVZtb4imTuSxHz4MsV2yq48PbG9fwhnN2/Screenshot%202018-07-28%2022.15.08.png)

### GitHub Account
https://github.com/Juless89
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsteempytutorials
permlinksteemautomated-0-0-3-voting-is-live-added-server-side-voting-application
categoryutopian-io
json_metadata{"tags":["utopian-io","development","steem","steemdev"],"image":["https://cdn.steemitimages.com/DQmaveG4yAGBA3dG1bKmQDW9hq73vUEMcp8vcem4WpVLFHr/Screenshot%202018-07-24%2018.50.48.png","https://cdn.steemitimages.com/DQmPJhKwrL71fDUVZtb4imTuSxHz4MsV2yq48PbG9fwhnN2/Screenshot%202018-07-28%2022.15.08.png"],"links":["https://github.com/Juless89/steemautomated","https://github.com/Juless89/steemautomated/commit/8f6e256a7b9688252941767772cb6746ccd0e4e1","https://steemautomated.eu/","https://github.com/Juless89"],"app":"steemit/0.1","format":"markdown"}
created2018-07-28 20:20:42
last_update2018-07-28 20:20:42
depth0
children5
last_payout2018-08-04 20:20:42
cashout_time1969-12-31 23:59:59
total_payout_value71.726 HBD
curator_payout_value22.418 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,293
author_reputation31,094,047,689,691
root_title"Steemautomated: 0.0.3 - Voting Is Live! Added Server Side Voting Application"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,315,703
net_rshares53,238,458,902,054
author_curate_reward""
vote details (33)
@forhadh ·
thanks for your information
properties (22)
authorforhadh
permlinkre-steempytutorials-steemautomated-0-0-3-voting-is-live-added-server-side-voting-application-20180730t083657614z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-07-30 08:37:24
last_update2018-07-30 08:37:24
depth1
children0
last_payout2018-08-06 08:37:24
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_length27
author_reputation193,665,764,419
root_title"Steemautomated: 0.0.3 - Voting Is Live! Added Server Side Voting Application"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,486,937
net_rshares0
@justyy ·
$2.98
Thank you for your contribution. The code is a good example to teach how to use Steem Python. 

1. You may want to define mysql access details somewhere outside the constructor of Database class, which is easier to configure and maintain.
2. There are some broad execeptions, which is in general a bad practice.
3. What are the risks of the database compromised and access tokens leaked?
4. `verify_post` may be better named to indicate its purpose e.g. `is_new_post`
5. You may want to check if a post has been upvoted already before voting it. 

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/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](https://review.utopian.io/result/3/2222231).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , ,
properties (23)
authorjustyy
permlinkre-steempytutorials-steemautomated-0-0-3-voting-is-live-added-server-side-voting-application-20180729t004403030z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/3/2222231","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-07-29 00:44:03
last_update2018-07-29 00:44:03
depth1
children2
last_payout2018-08-05 00:44:03
cashout_time1969-12-31 23:59:59
total_payout_value2.309 HBD
curator_payout_value0.671 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,037
author_reputation280,616,224,641,976
root_title"Steemautomated: 0.0.3 - Voting Is Live! Added Server Side Voting Application"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,333,107
net_rshares1,695,774,849,551
author_curate_reward""
vote details (11)
@juliank ·
Hi @justyy, thanks for your feedback.

I will look to apply it for the next update. About the database security, currently root access is turned of and each database has a separate account. After your tip I changed the default url for phpmyadmin. I will also add SSL and password protect.
properties (22)
authorjuliank
permlinkre-justyy-re-steempytutorials-steemautomated-0-0-3-voting-is-live-added-server-side-voting-application-20180729t020248786z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["justyy"],"app":"steemit/0.1"}
created2018-07-29 02:02:48
last_update2018-07-29 02:02:48
depth2
children0
last_payout2018-08-05 02:02:48
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_length288
author_reputation117,823,071,447,502
root_title"Steemautomated: 0.0.3 - Voting Is Live! Added Server Side Voting Application"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,338,581
net_rshares0
@utopian-io ·
Hey @justyy
Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

**Contributing on Utopian**
Learn how to contribute on <a href="https://join.utopian.io">our website</a>.

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

<a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlink20180729t222030553z
categoryutopian-io
json_metadata{"tags":["utopian.tip"],"app":"utopian-io"}
created2018-07-29 22:20:30
last_update2018-07-29 22:20:30
depth2
children0
last_payout2018-08-05 22:20: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_length406
author_reputation152,955,367,999,756
root_title"Steemautomated: 0.0.3 - Voting Is Live! Added Server Side Voting Application"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,438,570
net_rshares0
@utopian-io ·
Hey @steempytutorials
**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

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

<a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-steemautomated-0-0-3-voting-is-live-added-server-side-voting-application-20180731t225009z
categoryutopian-io
json_metadata"{"app": "beem/0.19.42"}"
created2018-07-31 22:50:09
last_update2018-07-31 22:50:09
depth1
children0
last_payout2018-08-07 22:50:09
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_length308
author_reputation152,955,367,999,756
root_title"Steemautomated: 0.0.3 - Voting Is Live! Added Server Side Voting Application"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id66,689,137
net_rshares0