For a project, I needed to fetch all communities' data to create a map between the weird tag names (hive-XXXXXX
) and the human-readable community titles.
This Python snippet creates exactly this data structure:
from lighthive.client import Client
def get_all_communities(last=None, limit=100, community_list=None):
if not community_list:
community_list = []
c = Client()
communities = c('bridge').list_communities({"limit": limit, "last": last})
community_list += communities
if communities:
return get_all_communities(
last=communities[-1]["name"],
community_list=community_list,
)
return community_list
if __name__ == '__main__':
all_communities = get_all_communities()
print(len(all_communities), "communities found")
tag_name_map = {c["name"]: c["title"] for c in all_communities}
print(tag_name_map)
P.S: Looks like we have 1497 valid communities created so far. 😲
Nice one, though since anyone can create the communities, I feel in future it will be much more than current number.
Agreed, it will be much more. 3 HIVE for a community is deadly cheap.
"list_communities" is Hive node API direct call? I don't see such method in lighthive library.
lighthive doesn't implement methods explicitly, they're prepared and sent on the fly. There is a
list_communities
call inbridge_api
(routed to Hivemind)Ah Hivemind is the key. Clear!