New features sc2py - steemconnect2 with python

in #utopian-io7 years ago (edited)

What is sc2py ?

Sc2py is the first python library written for SteemConnect2, To learn more, check my first contribution

New Features

What feature(s) did you add?

I increased understanding, use and readability of codes of project, in addition I added some features,
let's get to know these features and I changed in old features like vote,follow,unfollow,post.

  • Mute

You can get a user to be muted in.

  • Reblog

You can reblog a post.

  • Comment_options

With this option you can add data like this to any post.
"root_author":"bkatipoglu1","root_permlink":"endustri-40","max_accepted_payout":"100000.000 SBD","percent_steem_dollars":10000,"allow_replies":true,"allow_votes":true,"allow_curation_rewards":true,"beneficiaries":[{"account":"coogger","weight":1000}]

  • DeleteComment

We can delete any post.

  • ClaimRewardBalance

We can transfer our reward balance to wallet.

How did you implement it/them?

import json

class Vote:
    def __init__(self, voter, author, permlink, weight = 100):
        self.voter = voter
        self.author = author
        self.permlink = permlink
        self.weight = weight

    @property
    def json(self):
        return [
            "vote",
                {
                    "voter":"{}".format(self.voter),
                    "author":"{}".format(self.author),
                    "permlink":"{}".format(self.permlink),
                    "weight":self.weight * 100
                }],
class Unfollow:
    def __init__(self,follower,following,what = []):
        self.follower = follower
        self.following = following
        self.what = what

    @property
    def json(self):
        follow_json = [
            "follow",
                {
                    "follower":"{}".format(self.follower),
                    "following":"{}".format(self.following),
                    "what":["{}".format(self.what)]
                }]
        return [
            "custom_json",
                {
                    "required_auths":[],
                    "required_posting_auths":["{}".format(self.follower)],
                    "id":"follow",
                    "json":json.dumps(follow_json)
                }],

class Follow(Unfollow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.what = "blog"
class Mute(Unfollow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.what = "ignore"
class Reblog:

    def __init__(self, account, author, permlink):
        self.account = account
        self.author = author
        self.permlink = permlink

    @property
    def json(self):
        reblog_json = [
            "reblog",
                {
                    "account":"{}".format(self.account),
                    "author":"{}".format(self.author),
                    "permlink":"{}".format(self.permlink)
                }]
        return [
            "custom_json",
            {
                "required_auths":[],
                "required_posting_auths":["{}".format(self.account)],
                "id":"follow",
                "json":json.dumps(reblog_json)
            }],
class Comment:

    def __init__(self,parent_permlink,author,permlink,title,body,json_metadata):
        self.parent_permlink = parent_permlink
        self.author = author
        self.permlink = permlink
        self.title = title
        self.body = body
        self.json_metadata = json_metadata

    @property
    def json(self):
        return [
            "comment",
                {
                    "parent_author":"",
                    "parent_permlink":"{}".format(self.parent_permlink),
                    "author":"{}".format(self.author),
                    "permlink":"{}".format(self.permlink),
                    "title":"{}".format(self.title),
                    "body":"{}".format(self.body),
                    "json_metadata":json.dumps(self.json_metadata)
                }],
class Comment_options:

    def __init__(self,author,
        permlink,
        beneficiaries,
        max_accepted_payout = 100000.000,
        percent_steem_dollars = 10000,
        allow_votes = True,
        allow_curation_rewards = True
        ):
        self.author = author
        self.permlink = permlink
        self.beneficiaries = beneficiaries
        self.max_accepted_payout = max_accepted_payout
        self.percent_steem_dollars = percent_steem_dollars
        self.allow_votes = allow_votes
        self.allow_curation_rewards = allow_curation_rewards

    @property
    def json(self):
        return [
            "comment_options",
                {
                    "author":"{}".format(self.author),
                    "permlink":"{}".format(self.permlink),
                    "max_accepted_payout":"{} SBD".format(self.max_accepted_payout),
                    "percent_steem_dollars":self.percent_steem_dollars,
                    "allow_votes":self.allow_votes,
                    "allow_curation_rewards":self.allow_curation_rewards,
                    "extensions":[
                        [
                            0,
                                {
                                    "beneficiaries":[self.beneficiaries]
                                }
                        ]
                    ]
                }],
class DeleteComment:

    def __init__(self, author, permlink):
        self.author = author
        self.permlink = permlink

    @property
    def json(self):
        return [
            "delete_comment", {
                "author": self.author,
                "permlink": self.permlink
            }
        ],
class ClaimRewardBalance:

    def __init__(self, account, reward_steem, reward_sbd, reward_vests):
        self.account = account
        self.reward_steem = reward_steem
        self.reward_vests = reward_vests
        self.reward_sbd = reward_sbd

    @property
    def json(self):
        return [
            "claim_reward_balance", {
                "account": self.account,
                "reward_steem": self.reward_steem,
                "reward_sbd": self.reward_sbd,
                "reward_vests": self.reward_vests,
            }
        ],
class Operations:

    def __init__(self,json):
        self.payload = {"operations":json}

    @property
    def json(self):
        return json.dumps(self.payload).encode(encoding='utf-8')

How to use it or these new features ?

Installation

pip install sc2py

update

pip install sc2py -U

First let's include the library in our project

from sc2py.sc2py import Sc2
from sc2py.operations import Vote
from sc2py.operations import Unfollow
from sc2py.operations import Follow
from sc2py.operations import Mute
from sc2py.operations import Reblog
from sc2py.operations import Comment
from sc2py.operations import Comment_options
from sc2py.operations import DeleteComment
from sc2py.operations import ClaimRewardBalance
from sc2py.operations import Operations

The Vote() method will cast a vote on the specified post or comment from the current user:

vote = Vote(voter:str, author:str, permlink:str, weight:int)
json_data = Operations(json = vote.json).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code == 200:
    print("Your post upvoted")

Parameters:

  • voter: The Steem username of the current user.
  • author: The Steem username of the author of the post or comment.
  • permlink: The link to the post or comment on which to vote. This is the portion of the URL after the last "/". For example the "permlink" for this post: https://steemit.com/steem/@ned/announcing-smart-media-tokens-smts would be "announcing-smart-media-tokens-smts".
  • weight: The weight of the vote. 100 equale a 100% vote.

Follow

follow = Follow(follower:str,following:str)
json_data = Operations(json = follow.json).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code != 200:
    print(response.text)

Unfollow

unfollow = Unfollow(follower:str,following:str)
json_data = Operations(json = unfollow.json).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code != 200:
    print(response.text)

Mute

mute = Mute(follower:str,following:str)
json_data = Operations(json = mute.json).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code != 200:
    print(response.text)

Reblog

reblog = Reblog(account:str, author:str, permlink:str)
json_data = Operations(json = reblog.json).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code != 200:
    print(response.text)

Comment

comment = Comment(parent_permlink:str,author:str,permlink:str,title:str,body:str,json_metadata:dict)
json_data = Operations(json = comment.json).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code != 200:
    print(response.text)

Comment with Comment_options

comment = Comment(parent_permlink:str,author:str,permlink:str,title:str,body:str,json_metadata:dict)
comment_options = Comment_options(
            author:str,
            permlink:str,
            beneficiaries:dict to tuble or list
            )
jsons = comment.json+comment_options.json
json_data = Operations(json = jsons).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code != 200:
    print(response.text)
Example;
json_metadata = {
    "format":"markdown",
    "tags":["coogger","python","django"],
    "app":"coogger/1.3.0",
    "community":"coogger",
    "content":{
         "status":approved,
         "dor":"2.3,
          "content_list":"coogger"
          },
    "mod":{
            "user":"pars11",
            "cooggerup":True
            },
    }
comment = Comment(
    parent_permlink = "coogger",
    author = "hakancelik",
    permlink = "permlink",
    title = "title",
    body = "body",
    json_metadata = json_metadata,
)
comment_options = Comment_options(
    author = "pars11",
    permlink = "permlink",
    beneficiaries = {"account":"coogger","weight":100},{"account":"hakancelik","weight":100} # 100 meas 10%
    )
jsons = comment.json+comment_options.json
op = Operations(json = jsons).json
Sc2(token = "token",data = op).run

DeleteComment

delete_comment = DeleteComment(author:str, permlink:str)
json_data = Operations(json = delete_comment.json).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code != 200:
    print(response.text)

ClaimRewardBalance

claim_reward_balance = ClaimRewardBalance(account:str, reward_steem:str, reward_sbd:str, reward_vests:str)
json_data = Operations(json = claim_reward_balance.json).json
response = Sc2(token = "your_access_token",data = json_data).run
if response.status_code != 200:
    print(response.text)

Roadmap

The fact that the project is over with the addition of these features, because all the features added, but if I learn other features I will add them.

How to contribute?

You can notify me of missing features.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

It has been beautiful features for python steemconnect. Thank you for contributing.

Thanks your feedback dude 😊👍 I pleased.

Coogger a güzel özellikler eklemişsiniz gelişmesi harika emeğinize sağlık.

Hi, your contribution cannot be accepted because this Python package contains all the features/operations you added in this contribution and more.

While we appreciate anyone contributing to open source projects, we can only reward contributors who add value to the open source community by either improving on already existing projects (which @emrebeyler did with his package) or creating something unique and useful.


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

[utopian-moderator]

@amosbastian Sc2py is the first python library written for SteemConnect2, anyway, what am I trying to tell.

You need to write this message to emrebeyler.

This is unfair.

I believe that he already explained clearly enough what the differences between his initial release and your previous version were here. The difference between that situation and this one is that the initial release of his package offered a lot more than yours, and still does, even including this contribution. Just because you were the first to offer a basic version of a SteemConnect Python package it does not mean that yours is the only one people can contribute to - that would be unfair. What does your package do that his doesn't?