Exploring new Hivemind Community APIssteemCreated with Sketch.

in Python5 years ago

Steemit Beta is running for a while, hosting the new communities UI, powered by Hivemind in the backend. There is a new set of API endpoints available.


It's possible to use these endpoints with Lightsteem in a simple way to explore the API methods. (No updates needed thanks to Lightsteem's dynamic request model)

First step, getting a Client instance


from lightsteem.client import Client

c = Client(nodes=["https://beta-api.steemit.com/"])

Get community details


c('bridge').get_community({"name": "hive-129924", "observer": "emrebeyler"})

Example Output:

{
    'id': 1352979,
    'name': 'hive-129924',
    'title': 'Python',
    'about': 'news, questions, notes, tutorials about the Python programming language',
    'lang': 'en',
    'type_id': 1,
    'is_nsfw': False,
    'subscribers': 31,
    'sum_pending': 28,
    'num_pending': 16,
    'num_authors': 9,
    'created_at': '2020-01-04 09:11:06',
    'context': {
        'role': 'admin',
        'title': '',
        'subscribed': True
    },
    'description': '',
    'flag_text': '',
    'settings': {},
    'team': [
        ['hive-129924', 'owner', ''],
        ['emrebeyler', 'admin', ''],
        ['crokkon', 'mod', 'Expert']
    ]
}

List communities


c('bridge').list_communities({"limit": 1})

List all communities and limit the results to 1. (It's possible to paginate the results with optional last argument.)

Example output:


[{
    'id': 1337319,
    'name': 'hive-100421',
    'title': 'Threespeak',
    'about': '3Speak is a video platform for deplatformed and censored content creators.',
    'lang': 'en',
    'type_id': 1,
    'is_nsfw': False,
    'subscribers': 810,
    'sum_pending': 2770,
    'num_pending': 1912,
    'num_authors': 461,
    'created_at': '2019-11-14 19:51:54',
    'context': {}
}]

List community roles


c('bridge').list_community_roles({"community": "hive-129924"})

Example output:


[
    ['hive-129924', 'owner', ''],
    ['emrebeyler', 'admin', ''],
    ['crokkon', 'mod', 'Expert']
]

List subscribers of a community


 c('bridge').list_subscribers({"community": "hive-129924"})

Example output:


[
    ['cardboard', 'guest', None, '2020-01-05 01:17:51'],
    ['anthonyadavisii', 'guest', None, '2020-01-05 01:11:03'],
    ['mytechtrail', 'guest', None, '2020-01-05 00:52:39'],
    ['louis88', 'guest', None, '2020-01-05 00:50:18'],
    ['dalz', 'guest', '', '2020-01-05 00:45:21'],
    ['emrebeyler', 'admin', '', '2020-01-04 09:11:15'],
    ...
]

List subscriptions of an account


c('bridge').list_all_subscriptions({"account": "emrebeyler"})

Example output:


[
    ['hive-129924', 'Python'],
    ['hive-174578', 'OCD'],
    ['hive-167922', 'SteemLeo'],
    ['hive-136578', 'Steem Think Tank'],
    ['hive-177976', 'DCooperation'],
    ['hive-122359', 'Community Announce'],
    ['hive-185247', 'Open Source']
]

Creating and managing communities

All these transactions are actually Custom JSON transactions. This module will give an insight. Once things go out of the beta, I'll release a helper module in Lightsteem to make things easier.

Note

These API signatures may subject the change. GIT repository is a good place to track the changes if you're interested.

Vote for my witness

If you didn't vote already, consider casting a vote for my witness on Steemconnect or on Steemit

Python community

This is originally posted on Python community in Steemit Beta. Check it out and subscribe if you're interested in Python related content.

Sort:  

Hoping to finally getting around to spinning up my own HiveMind node in the next week or two here.

I have a couple questions, in the meantime:

  • Is there a public HiveMind node available for testing purposes? I remember seeing you post something about your hivemind.emrebeyler.me -- is that still up and public?

  • Does @holger80's beempy library work with HiveMind nodes? Is that what the Discussions module is all about?

hivemind.emrebeyler.meis up and running but it's running the stable version - communities feature is excluded.

No idea about beempy, I don't think it has a Hivemind module.

Ah okay. Thanks for the reply.

At the end of the day -- I'm developing a Steem project using Django. I'm not 100% certain, but I'm pretty sure that running an instance of my own Hivemind node would alleviate some of the issues I've been experiencing (generally related to issues with the "tags api" not being accessible, I think -- which was part of what was deprecated from original full nodes, yeah? Things like getting a list of replies to a post, and stuff like that, seems to throw errors for a while now) with just relying on the node-list incorporated into beempy.


Does it sound like Hivemind would be a worthwhile step, or am I going down the wrong path here?

I think you should be pretty okay with public nodes. What are your requirements and what kind of errors do you get?

Realistically, right now, all I'm trying to do is just get a list of replies to a post. I've build my project, more or less, utilizing beempy. Comments broke a while back, and I haven't really had time to sink my teeth back into it:

from beem.comment import Comment
comment = Comment(@emrebeyler/exploring-new-hivemind-community-apis)
comment.get_replies()

Which then ends up throwing the error below:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/betasites/venv/lib/python3.6/site-packages/beem/comment.py", line 591, in get_replies
    content_replies = self.steem.rpc.get_content_replies({'author': post_author, 'permlink': post_permlink}, api="tags")['discussions']
TypeError: list indices must be integers or slices, not str

Again, I'm not super well versed in the changes that happened to the APIs during the latest HF's. Maybe I'm just completely in the wrong spot trying to find these replies...?


If there's another python library available that would make my life easier -- I'm definitely open to checking it out. I haven't looked into the functionality of lightsteem -- would that one be useful here?

Check out lightsteem, I use it on my scripts/apps all the time. However, it's not advanced as Beem.

That exception you mention needs some debugging. Did you try asking to Beem discord?

Been a while since I've popped in there to touch base with Holger. Maybe worth a visit again.

Still feeling pretty compelled / interested in spinning up a Hivemind node -- so I might start there.

Lightsteem example


c = Client()

replies = c.get_content_replies("emrebeyler", "exploring-new-hivemind-community-apis")

print(replies)

Great stuff!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63651.41
ETH 2679.55
USDT 1.00
SBD 2.80