Skip to content
Snippets Groups Projects
Commit 618469f9 authored by Holger Nahrstaedt's avatar Holger Nahrstaedt
Browse files

Some bug fixes and improvements

set_next_node_on_empty_reply added to all discussions and RecentByPath and RecentReplies
parent c30aa2b6
No related branches found
No related tags found
No related merge requests found
......@@ -94,7 +94,7 @@ class Comment(BlockchainObject):
content = self.steem.rpc.get_discussion({'author': author, 'permlink': permlink}, api="tags")
else:
content = self.steem.rpc.get_content(author, permlink)
if not content or not content['author']:
if not content or not content['author'] or not content['permlink']:
raise ContentDoesNotExistsException
super(Comment, self).__init__(content, id_item="authorperm", steem_instance=self.steem)
self["authorperm"] = construct_authorperm(self["author"], self["permlink"])
......@@ -412,6 +412,7 @@ class RecentReplies(list):
"""
def __init__(self, author, skip_own=True, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
self.steem.rpc.set_next_node_on_empty_reply(True)
state = self.steem.rpc.get_state("/@%s/recent-replies" % author)
replies = state["accounts"][author].get("recent_replies", [])
comments = []
......@@ -431,7 +432,7 @@ class RecentByPath(list):
"""
def __init__(self, path="promoted", category=None, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
self.steem.rpc.set_next_node_on_empty_reply(True)
state = self.steem.rpc.get_state("/" + path)
replies = state["discussion_idx"][''].get(path, [])
comments = []
......
......@@ -47,6 +47,8 @@ class Discussions_by_trending(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_trending(discussion_query, api="tags")['discussions']
else:
......@@ -67,6 +69,8 @@ class Comment_discussions_by_payout(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_comment_discussions_by_payout(discussion_query, api="tags")['discussions']
else:
......@@ -87,6 +91,8 @@ class Post_discussions_by_payout(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_post_discussions_by_payout(discussion_query, api="tags")['discussions']
else:
......@@ -107,6 +113,8 @@ class Discussions_by_created(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_created(discussion_query, api="tags")['discussions']
else:
......@@ -127,6 +135,8 @@ class Discussions_by_active(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_active(discussion_query, api="tags")['discussions']
else:
......@@ -148,6 +158,8 @@ class Discussions_by_cashout(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_cashout(discussion_query, api="tags")['discussions']
else:
......@@ -168,6 +180,8 @@ class Discussions_by_votes(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_votes(discussion_query, api="tags")['discussions']
else:
......@@ -188,6 +202,8 @@ class Discussions_by_children(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_children(discussion_query, api="tags")['discussions']
else:
......@@ -208,6 +224,8 @@ class Discussions_by_hot(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_hot(discussion_query, api="tags")['discussions']
else:
......@@ -228,6 +246,8 @@ class Discussions_by_feed(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_feed(discussion_query, api="tags")['discussions']
else:
......@@ -252,6 +272,8 @@ class Discussions_by_blog(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_blog(discussion_query, api="tags")['discussions']
else:
......@@ -276,6 +298,8 @@ class Discussions_by_comments(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_comments(discussion_query, api="tags")['discussions']
else:
......@@ -296,6 +320,8 @@ class Discussions_by_promoted(list):
"""
def __init__(self, discussion_query, steem_instance=None):
self.steem = steem_instance or shared_steem_instance()
limit_ok = "limit" in discussion_query and discussion_query["limit"] > 0
self.steem.rpc.set_next_node_on_empty_reply(limit_ok)
if self.steem.rpc.get_use_appbase():
posts = self.steem.rpc.get_discussions_by_promoted(discussion_query, api="tags")['discussions']
else:
......
......@@ -234,8 +234,7 @@ def make_patch(a, b, n=3):
def get_node_list(appbase=False):
"""Returns node list"""
if appbase:
return ["https://api.steemit.com", "https://api.steem.house", "wss://steemd.steemitstage.com",
"wss://steemd.steemitdev.com", "wss://appbasetest.timcliff.com"]
return ["https://api.steemit.com", "https://api.steem.house", "wss://appbasetest.timcliff.com"]
else:
return ["wss://steemd.privex.io", "wss://steemd.pevo.science", "wss://rpc.buildteam.io", "wss://rpc.steemliberator.com", "wss://gtg.steem.house:8090",
"wss://rpc.steemviz.com", "wss://seed.bitcoiner.me", "wss://steemd.steemgigs.org", "wss://steemd.minnowsupportproject.org", "https://rpc.buildteam.io",
......
......@@ -64,13 +64,13 @@ class SteemNodeRPC(GrapheneRPC):
doRetry = True
except exceptions.RPCError as e:
doRetry = self._check_error_message(e, cnt)
if doRetry:
if self.error_cnt_call == 0:
cnt += 1
else:
cnt = self.error_cnt_call + 1
except Exception as e:
raise e
if doRetry:
if self.error_cnt_call == 0:
cnt += 1
else:
cnt = self.error_cnt_call + 1
def _check_error_message(self, e, cnt):
"""Check error message and decide what to do"""
......
......@@ -50,7 +50,10 @@ class Testcases(unittest.TestCase):
exceptions.ContentDoesNotExistsException
):
Comment("@abcdef/abcdef", steem_instance=bts)
c = Comment("@gtg/witness-gtg-log", steem_instance=bts)
try:
c = Comment("@gtg/witness-gtg-log", steem_instance=bts)
except exceptions.ContentDoesNotExistsException:
c = Comment("@gtg/witness-gtg-log", steem_instance=bts)
self.assertTrue(isinstance(c.id, int))
self.assertTrue(c.id > 0)
self.assertEqual(c.author, "gtg")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment