New project named sc2py to steemconnect2 with python

in #utopian-io6 years ago (edited)

What is sc2py ?

A few days ago I tried to use SteemConnect with python, but I could not find a result.
it have this project for javascript but it is not for python, I opened a issue here, and then discovered how to do it looking at it, then I created this project

New Features

I will add everything that steemconnect-sdk does over time, but for now, this project can do the following.

  • Vote : it will cast a vote on the specified post from the current user:
  • Post : it will share a post from the current user:
  • Resteem : it will reblog post from the current user to another user:
  • Follow : for the current user to follow other users.

How did I implement them?

Vote :

 def vote(self, voter, author, permlink, weight = 10000):
        payload = """{
        "operations":
            [
                ["vote",
                    {
                        "voter":"%s",
                        "author":"%s",
                        "permlink":"%s",
                        "weight":%d
                    }
                ]
            ]
        }"""%(voter,author,permlink,weight)
        return self.run(payload)

Follow

def follow(follower,following):
        payload = """{
            "operations":
                [
                    ["custom_json",
                        {
                            "required_auths":[],
                            "required_posting_auths":["%s"],
                            "id":"follow",
                            "json":"[\\"follow\\",{\\"follower\\":\\"%s\\",\\"following\\":\\"%s\\",\\"what\\":[]}]"
                        }
                    ]
                ]
        }"""%(follower,follower,following)
        return self.run(payload)

Resteem

def resteem(self, account, author, permlink):
        payload = """{
            "operations":
                [
                    ["custom_json",
                        {
                             "required_auths":[],
                             "required_posting_auths":["%s"],
                             "id":"follow",
                             "json":"[\\"reblog\\",{\\"account\\":\\"%s\\",\\"author\\":\\"%s\\",\\"permlink\\":\\"%s\\"}]"
                        }
                    ]
                ]
        }"""%(account,account,author,permlink)
        return self.run(payload)

Post

def post(self,author,title,body,tags):
        permlink = slugify(title.lower())
        payload = """{
            "operations":
                 [
                      ["comment",
                           {
                               "parent_author":"",
                               "parent_permlink":"%s",
                               "author":"%s",
                               "permlink":"%s",
                               "title":"%s",
                               "body":"%s",
                               "json_metadata":"{\\"tags\\":[\\"%s\\"]}"
                            }
                      ]
                  ]
        }"""%(tags[0],author,permlink,title,body,tags[0])
        return self.run(payload)

run and headers

def run(self, payload):
        response = requests.post(self.sc2_broadcast, data = payload, headers = self.get_header())
        return response

    def get_header(self):
        return{
        "content-type": "application/json; charset=utf-8",
        "Accept": "application/json",
        "Authorization": self.access_token,
        "cache-control": "no-cache"
        }

How to use it ?

Download in this address : https://github.com/hakancelik96/sc2py

and continue

Firstly

from sc2py import Sc2
sc = Sc2(access_token = "user access key")

Vote

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

sc.vote(voter, author, permlink, weight)

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. 10000 equale a 100% vote.

post

The post() method will share a post from the current user:

sc.post(parent_permlink,author,permlink,title,body,app,tags)

Parameters:

  • parent_permlink: The Steem username of the current user.
  • app : busy, dlive so this parameter is your app name.
  • tags : post's tags of the current user. ex : ["coogger","tr","steem"] etc.

resteem

sc.resteem(account, author, permlink)

follow

sc.follow(follower,following)

Technology Stack

  • requests

Roadmap

I must add

How to contribute?

  • You can do what I do on the roadmap
  • You can open the issue on github if an error ,bug etc

** if you want to check result, Tests was done with this account @postdestek**

GİTHUB : https://github.com/hakancelik96/sc2py



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @codingdefined, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Thank you for your post. :) I have voted for you: 🎁! To call me just write @contentvoter in a comment.

Hey @hakancelik I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.030
BTC 65128.68
ETH 3442.23
USDT 1.00
SBD 2.52