hive-nectar 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hive-nectar might be problematic. Click here for more details.

Files changed (86) hide show
  1. hive_nectar-0.0.2.dist-info/METADATA +182 -0
  2. hive_nectar-0.0.2.dist-info/RECORD +86 -0
  3. hive_nectar-0.0.2.dist-info/WHEEL +4 -0
  4. hive_nectar-0.0.2.dist-info/entry_points.txt +2 -0
  5. hive_nectar-0.0.2.dist-info/licenses/LICENSE.txt +23 -0
  6. nectar/__init__.py +32 -0
  7. nectar/account.py +4371 -0
  8. nectar/amount.py +475 -0
  9. nectar/asciichart.py +270 -0
  10. nectar/asset.py +82 -0
  11. nectar/block.py +446 -0
  12. nectar/blockchain.py +1178 -0
  13. nectar/blockchaininstance.py +2284 -0
  14. nectar/blockchainobject.py +221 -0
  15. nectar/blurt.py +563 -0
  16. nectar/cli.py +6285 -0
  17. nectar/comment.py +1217 -0
  18. nectar/community.py +513 -0
  19. nectar/constants.py +111 -0
  20. nectar/conveyor.py +309 -0
  21. nectar/discussions.py +1709 -0
  22. nectar/exceptions.py +149 -0
  23. nectar/hive.py +546 -0
  24. nectar/hivesigner.py +420 -0
  25. nectar/imageuploader.py +72 -0
  26. nectar/instance.py +129 -0
  27. nectar/market.py +1013 -0
  28. nectar/memo.py +449 -0
  29. nectar/message.py +357 -0
  30. nectar/nodelist.py +444 -0
  31. nectar/price.py +557 -0
  32. nectar/profile.py +65 -0
  33. nectar/rc.py +308 -0
  34. nectar/snapshot.py +726 -0
  35. nectar/steem.py +582 -0
  36. nectar/storage.py +53 -0
  37. nectar/transactionbuilder.py +622 -0
  38. nectar/utils.py +545 -0
  39. nectar/version.py +2 -0
  40. nectar/vote.py +557 -0
  41. nectar/wallet.py +472 -0
  42. nectar/witness.py +617 -0
  43. nectarapi/__init__.py +11 -0
  44. nectarapi/exceptions.py +123 -0
  45. nectarapi/graphenerpc.py +589 -0
  46. nectarapi/node.py +178 -0
  47. nectarapi/noderpc.py +229 -0
  48. nectarapi/rpcutils.py +97 -0
  49. nectarapi/version.py +2 -0
  50. nectarbase/__init__.py +14 -0
  51. nectarbase/ledgertransactions.py +75 -0
  52. nectarbase/memo.py +243 -0
  53. nectarbase/objects.py +429 -0
  54. nectarbase/objecttypes.py +22 -0
  55. nectarbase/operationids.py +102 -0
  56. nectarbase/operations.py +1297 -0
  57. nectarbase/signedtransactions.py +48 -0
  58. nectarbase/transactions.py +11 -0
  59. nectarbase/version.py +2 -0
  60. nectargrapheneapi/__init__.py +6 -0
  61. nectargraphenebase/__init__.py +27 -0
  62. nectargraphenebase/account.py +846 -0
  63. nectargraphenebase/aes.py +52 -0
  64. nectargraphenebase/base58.py +192 -0
  65. nectargraphenebase/bip32.py +494 -0
  66. nectargraphenebase/bip38.py +134 -0
  67. nectargraphenebase/chains.py +149 -0
  68. nectargraphenebase/dictionary.py +3 -0
  69. nectargraphenebase/ecdsasig.py +326 -0
  70. nectargraphenebase/objects.py +123 -0
  71. nectargraphenebase/objecttypes.py +6 -0
  72. nectargraphenebase/operationids.py +3 -0
  73. nectargraphenebase/operations.py +23 -0
  74. nectargraphenebase/prefix.py +11 -0
  75. nectargraphenebase/py23.py +38 -0
  76. nectargraphenebase/signedtransactions.py +201 -0
  77. nectargraphenebase/types.py +419 -0
  78. nectargraphenebase/unsignedtransactions.py +283 -0
  79. nectargraphenebase/version.py +2 -0
  80. nectarstorage/__init__.py +38 -0
  81. nectarstorage/base.py +306 -0
  82. nectarstorage/exceptions.py +16 -0
  83. nectarstorage/interfaces.py +237 -0
  84. nectarstorage/masterpassword.py +239 -0
  85. nectarstorage/ram.py +30 -0
  86. nectarstorage/sqlite.py +334 -0
nectar/discussions.py ADDED
@@ -0,0 +1,1709 @@
1
+ # -*- coding: utf-8 -*-
2
+ import logging
3
+
4
+ from .comment import Comment
5
+ from .instance import shared_blockchain_instance
6
+
7
+ log = logging.getLogger(__name__)
8
+
9
+
10
+ class Query(dict):
11
+ """Query to be used for all discussion queries
12
+
13
+ :param int limit: limits the number of posts
14
+ :param str tag: tag query
15
+ :param int truncate_body:
16
+ :param array filter_tags:
17
+ :param array select_authors:
18
+ :param array select_tags:
19
+ :param str start_author:
20
+ :param str start_permlink:
21
+ :param str start_tag:
22
+ :param str parent_author:
23
+ :param str parent_permlink:
24
+ :param str start_parent_author:
25
+ :param str before_date:
26
+ :param str author: Author (see Discussions_by_author_before_date)
27
+
28
+ .. testcode::
29
+
30
+ from nectar.discussions import Query
31
+ query = Query(limit=10, tag="steemit")
32
+
33
+ """
34
+
35
+ def __init__(
36
+ self,
37
+ limit=0,
38
+ tag="",
39
+ truncate_body=0,
40
+ filter_tags=[],
41
+ select_authors=[],
42
+ select_tags=[],
43
+ start_author=None,
44
+ start_permlink=None,
45
+ start_tag=None,
46
+ parent_author=None,
47
+ parent_permlink=None,
48
+ start_parent_author=None,
49
+ before_date=None,
50
+ author=None,
51
+ ):
52
+ self["limit"] = limit
53
+ self["truncate_body"] = truncate_body
54
+ self["tag"] = tag
55
+ self["filter_tags"] = filter_tags
56
+ self["select_authors"] = select_authors
57
+ self["select_tags"] = select_tags
58
+ self["start_author"] = start_author
59
+ self["start_permlink"] = start_permlink
60
+ self["start_tag"] = start_tag
61
+ self["parent_author"] = parent_author
62
+ self["parent_permlink"] = parent_permlink
63
+ self["start_parent_author"] = start_parent_author
64
+ self["before_date"] = before_date
65
+ self["author"] = author
66
+
67
+
68
+ class Discussions(object):
69
+ """Get Discussions
70
+
71
+ :param Steem blockchain_instance: Steem instance
72
+
73
+ """
74
+
75
+ def __init__(self, lazy=False, use_appbase=False, blockchain_instance=None, **kwargs):
76
+ if blockchain_instance is None:
77
+ if kwargs.get("steem_instance"):
78
+ blockchain_instance = kwargs["steem_instance"]
79
+ elif kwargs.get("hive_instance"):
80
+ blockchain_instance = kwargs["hive_instance"]
81
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
82
+ self.lazy = lazy
83
+ self.use_appbase = use_appbase
84
+
85
+ def get_discussions(self, discussion_type, discussion_query, limit=1000, raw_data=False):
86
+ """Get Discussions
87
+
88
+ :param str discussion_type: Defines the used discussion query
89
+ :param Query discussion_query: Defines the parameter for
90
+ searching posts
91
+ :param bool raw_data: returns list of comments when False, default is False
92
+
93
+ .. testcode::
94
+
95
+ from nectar.discussions import Query, Discussions
96
+ query = Query(limit=51, tag="steemit")
97
+ discussions = Discussions()
98
+ count = 0
99
+ for d in discussions.get_discussions("tags", query, limit=200):
100
+ print(("%d. " % (count + 1)) + str(d))
101
+ count += 1
102
+
103
+ """
104
+ if limit >= 100 and discussion_query["limit"] == 0:
105
+ discussion_query["limit"] = 100
106
+ elif limit < 100 and discussion_query["limit"] == 0:
107
+ discussion_query["limit"] = limit
108
+ query_count = 0
109
+ found_more_than_start_entry = True
110
+ if "start_author" in discussion_query:
111
+ start_author = discussion_query["start_author"]
112
+ else:
113
+ start_author = None
114
+ if "start_permlink" in discussion_query:
115
+ start_permlink = discussion_query["start_permlink"]
116
+ else:
117
+ start_permlink = None
118
+ if "start_tag" in discussion_query:
119
+ start_tag = discussion_query["start_tag"]
120
+ else:
121
+ start_tag = None
122
+ if "start_parent_author" in discussion_query:
123
+ start_parent_author = discussion_query["start_parent_author"]
124
+ else:
125
+ start_parent_author = None
126
+ if not discussion_query["before_date"]:
127
+ discussion_query["before_date"] = "1970-01-01T00:00:00"
128
+ while query_count < limit and found_more_than_start_entry:
129
+ rpc_query_count = 0
130
+ dd = None
131
+ discussion_query["start_author"] = start_author
132
+ discussion_query["start_permlink"] = start_permlink
133
+ discussion_query["start_tag"] = start_tag
134
+ discussion_query["start_parent_author"] = start_parent_author
135
+ if discussion_type == "trending":
136
+ dd = Discussions_by_trending(
137
+ discussion_query, blockchain_instance=self.blockchain, lazy=self.lazy
138
+ )
139
+ elif discussion_type == "author_before_date":
140
+ dd = Discussions_by_author_before_date(
141
+ author=discussion_query["author"],
142
+ start_permlink=discussion_query["start_permlink"],
143
+ before_date=discussion_query["before_date"],
144
+ limit=discussion_query["limit"],
145
+ blockchain_instance=self.blockchain,
146
+ lazy=self.lazy,
147
+ )
148
+ elif discussion_type == "payout":
149
+ dd = Comment_discussions_by_payout(
150
+ discussion_query,
151
+ blockchain_instance=self.blockchain,
152
+ lazy=self.lazy,
153
+ use_appbase=self.use_appbase,
154
+ raw_data=raw_data,
155
+ )
156
+ elif discussion_type == "post_payout":
157
+ dd = Post_discussions_by_payout(
158
+ discussion_query,
159
+ blockchain_instance=self.blockchain,
160
+ lazy=self.lazy,
161
+ use_appbase=self.use_appbase,
162
+ raw_data=raw_data,
163
+ )
164
+ elif discussion_type == "created":
165
+ dd = Discussions_by_created(
166
+ discussion_query,
167
+ blockchain_instance=self.blockchain,
168
+ lazy=self.lazy,
169
+ use_appbase=self.use_appbase,
170
+ raw_data=raw_data,
171
+ )
172
+ elif discussion_type == "active":
173
+ dd = Discussions_by_active(
174
+ discussion_query,
175
+ blockchain_instance=self.blockchain,
176
+ lazy=self.lazy,
177
+ use_appbase=self.use_appbase,
178
+ raw_data=raw_data,
179
+ )
180
+ elif discussion_type == "cashout":
181
+ dd = Discussions_by_cashout(
182
+ discussion_query,
183
+ blockchain_instance=self.blockchain,
184
+ lazy=self.lazy,
185
+ use_appbase=self.use_appbase,
186
+ raw_data=raw_data,
187
+ )
188
+ elif discussion_type == "votes":
189
+ dd = Discussions_by_votes(
190
+ discussion_query,
191
+ blockchain_instance=self.blockchain,
192
+ lazy=self.lazy,
193
+ use_appbase=self.use_appbase,
194
+ raw_data=raw_data,
195
+ )
196
+ elif discussion_type == "children":
197
+ dd = Discussions_by_children(
198
+ discussion_query,
199
+ blockchain_instance=self.blockchain,
200
+ lazy=self.lazy,
201
+ use_appbase=self.use_appbase,
202
+ raw_data=raw_data,
203
+ )
204
+ elif discussion_type == "hot":
205
+ dd = Discussions_by_hot(
206
+ discussion_query,
207
+ blockchain_instance=self.blockchain,
208
+ lazy=self.lazy,
209
+ use_appbase=self.use_appbase,
210
+ raw_data=raw_data,
211
+ )
212
+ elif discussion_type == "feed":
213
+ dd = Discussions_by_feed(
214
+ discussion_query,
215
+ blockchain_instance=self.blockchain,
216
+ lazy=self.lazy,
217
+ use_appbase=self.use_appbase,
218
+ raw_data=raw_data,
219
+ )
220
+ elif discussion_type == "blog":
221
+ dd = Discussions_by_blog(
222
+ discussion_query,
223
+ blockchain_instance=self.blockchain,
224
+ lazy=self.lazy,
225
+ use_appbase=self.use_appbase,
226
+ raw_data=raw_data,
227
+ )
228
+ elif discussion_type == "comments":
229
+ dd = Discussions_by_comments(
230
+ discussion_query,
231
+ blockchain_instance=self.blockchain,
232
+ lazy=self.lazy,
233
+ use_appbase=self.use_appbase,
234
+ raw_data=raw_data,
235
+ )
236
+ elif discussion_type == "promoted":
237
+ dd = Discussions_by_promoted(
238
+ discussion_query,
239
+ blockchain_instance=self.blockchain,
240
+ lazy=self.lazy,
241
+ use_appbase=self.use_appbase,
242
+ raw_data=raw_data,
243
+ )
244
+ elif discussion_type == "replies":
245
+ dd = Discussions_by_replies(
246
+ discussion_query,
247
+ blockchain_instance=self.blockchain,
248
+ lazy=self.lazy,
249
+ use_appbase=self.use_appbase,
250
+ raw_data=raw_data,
251
+ )
252
+ elif discussion_type == "tags":
253
+ dd = Trending_tags(
254
+ discussion_query,
255
+ blockchain_instance=self.blockchain,
256
+ lazy=self.lazy,
257
+ use_appbase=self.use_appbase,
258
+ )
259
+ else:
260
+ raise ValueError("Wrong discussion_type")
261
+ if not dd:
262
+ return
263
+
264
+ for d in dd:
265
+ double_result = False
266
+ if discussion_type == "tags":
267
+ if query_count != 0 and rpc_query_count == 0 and (d["name"] == start_tag):
268
+ double_result = True
269
+ if len(dd) == 1:
270
+ found_more_than_start_entry = False
271
+ start_tag = d["name"]
272
+ elif discussion_type == "replies":
273
+ if (
274
+ query_count != 0
275
+ and rpc_query_count == 0
276
+ and (d["author"] == start_parent_author and d["permlink"] == start_permlink)
277
+ ):
278
+ double_result = True
279
+ if len(dd) == 1:
280
+ found_more_than_start_entry = False
281
+ start_parent_author = d["author"]
282
+ start_permlink = d["permlink"]
283
+ else:
284
+ if (
285
+ query_count != 0
286
+ and rpc_query_count == 0
287
+ and (d["author"] == start_author and d["permlink"] == start_permlink)
288
+ ):
289
+ double_result = True
290
+ if len(dd) == 1:
291
+ found_more_than_start_entry = False
292
+ start_author = d["author"]
293
+ start_permlink = d["permlink"]
294
+ rpc_query_count += 1
295
+ if not double_result:
296
+ query_count += 1
297
+ if query_count <= limit:
298
+ yield d
299
+
300
+
301
+ class Discussions_by_trending(list):
302
+ """Get Discussions by trending
303
+
304
+ :param Query discussion_query: Defines the parameter for
305
+ searching posts
306
+ :param Steem blockchain_instance: Steem instance
307
+ :param bool raw_data: returns list of comments when False, default is False
308
+
309
+ .. testcode::
310
+
311
+ from nectar.discussions import Query, Discussions_by_trending
312
+ q = Query(limit=10, tag="steem")
313
+ for h in Discussions_by_trending(q):
314
+ print(h)
315
+
316
+ """
317
+
318
+ def __init__(
319
+ self,
320
+ discussion_query,
321
+ lazy=False,
322
+ use_appbase=False,
323
+ raw_data=False,
324
+ blockchain_instance=None,
325
+ **kwargs,
326
+ ):
327
+ if blockchain_instance is None:
328
+ if kwargs.get("steem_instance"):
329
+ blockchain_instance = kwargs["steem_instance"]
330
+ elif kwargs.get("hive_instance"):
331
+ blockchain_instance = kwargs["hive_instance"]
332
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
333
+ reduced_query = {}
334
+ for key in [
335
+ "tag",
336
+ "limit",
337
+ "filter_tags",
338
+ "select_authors",
339
+ "select_tags",
340
+ "truncate_body",
341
+ "start_author",
342
+ "start_permlink",
343
+ ]:
344
+ if key in discussion_query:
345
+ reduced_query[key] = discussion_query[key]
346
+ self.blockchain.rpc.set_next_node_on_empty_reply(
347
+ self.blockchain.rpc.get_use_appbase() and use_appbase
348
+ )
349
+ posts = []
350
+ try:
351
+ # Try to use the bridge API first (preferred method)
352
+ bridge_query = {
353
+ "sort": "trending",
354
+ "tag": reduced_query.get("tag", ""),
355
+ "observer": "",
356
+ }
357
+ if "limit" in reduced_query:
358
+ bridge_query["limit"] = reduced_query["limit"]
359
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
360
+ bridge_query["start_author"] = reduced_query["start_author"]
361
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
362
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
363
+ except Exception:
364
+ # Fall back to old API methods
365
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
366
+ try:
367
+ posts = self.blockchain.rpc.get_discussions_by_trending(
368
+ reduced_query, api="tags"
369
+ )["discussions"]
370
+ except Exception:
371
+ posts = []
372
+ if len(posts) == 0:
373
+ posts = self.blockchain.rpc.get_discussions_by_trending(reduced_query)
374
+ if posts is None:
375
+ posts = []
376
+ if raw_data:
377
+ super(Discussions_by_trending, self).__init__([x for x in posts])
378
+ else:
379
+ super(Discussions_by_trending, self).__init__(
380
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
381
+ )
382
+
383
+
384
+ class Discussions_by_author_before_date(list):
385
+ """Get Discussions by author before date
386
+
387
+ .. note:: To retrieve discussions before date, the time of creation
388
+ of the discussion @author/start_permlink must be older than
389
+ the specified before_date parameter.
390
+
391
+ :param str author: Defines the author *(required)*
392
+ :param str start_permlink: Defines the permlink of a starting discussion
393
+ :param str before_date: Defines the before date for query
394
+ :param int limit: Defines the limit of discussions
395
+ :param bool use_appbase: use condenser call when set to False, default is False
396
+ :param bool raw_data: returns list of comments when False, default is False
397
+ :param Steem blockchain_instance: Steem instance
398
+
399
+ .. testcode::
400
+
401
+ from nectar.discussions import Query, Discussions_by_author_before_date
402
+ for h in Discussions_by_author_before_date(limit=10, author="gtg"):
403
+ print(h)
404
+
405
+ """
406
+
407
+ def __init__(
408
+ self,
409
+ author="",
410
+ start_permlink="",
411
+ before_date="1970-01-01T00:00:00",
412
+ limit=100,
413
+ lazy=False,
414
+ use_appbase=False,
415
+ raw_data=False,
416
+ blockchain_instance=None,
417
+ **kwargs,
418
+ ):
419
+ if blockchain_instance is None:
420
+ if kwargs.get("steem_instance"):
421
+ blockchain_instance = kwargs["steem_instance"]
422
+ elif kwargs.get("hive_instance"):
423
+ blockchain_instance = kwargs["hive_instance"]
424
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
425
+ self.blockchain.rpc.set_next_node_on_empty_reply(
426
+ self.blockchain.rpc.get_use_appbase() and use_appbase
427
+ )
428
+ posts = []
429
+ try:
430
+ # Try to use the bridge API first (preferred method)
431
+ if author:
432
+ bridge_query = {
433
+ "sort": "posts",
434
+ "account": author,
435
+ "limit": limit,
436
+ }
437
+ if start_permlink:
438
+ bridge_query["start_permlink"] = start_permlink
439
+ posts = self.blockchain.rpc.get_account_posts(bridge_query, api="bridge")
440
+ # Filter by before_date if provided
441
+ if before_date and before_date != "1970-01-01T00:00:00":
442
+ filtered_posts = []
443
+ for post in posts:
444
+ if "created" in post and post["created"] < before_date:
445
+ filtered_posts.append(post)
446
+ posts = filtered_posts
447
+ except Exception:
448
+ # Fall back to old API methods
449
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
450
+ discussion_query = {
451
+ "author": author,
452
+ "start_permlink": start_permlink,
453
+ "before_date": before_date,
454
+ "limit": limit,
455
+ }
456
+ posts = self.blockchain.rpc.get_discussions_by_author_before_date(
457
+ discussion_query, api="tags"
458
+ )["discussions"]
459
+ if len(posts) == 0:
460
+ posts = self.blockchain.rpc.get_discussions_by_author_before_date(
461
+ author, start_permlink, before_date, limit
462
+ )
463
+ if posts is None:
464
+ posts = []
465
+ if raw_data:
466
+ super(Discussions_by_author_before_date, self).__init__([x for x in posts])
467
+ else:
468
+ super(Discussions_by_author_before_date, self).__init__(
469
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
470
+ )
471
+
472
+
473
+ class Comment_discussions_by_payout(list):
474
+ """Get comment_discussions_by_payout
475
+
476
+ :param Query discussion_query: Defines the parameter for
477
+ searching posts
478
+ :param bool use_appbase: use condenser call when set to False, default is False
479
+ :param bool raw_data: returns list of comments when False, default is False
480
+ :param Steem blockchain_instance: Steem instance
481
+
482
+ .. testcode::
483
+
484
+ from nectar.discussions import Query, Comment_discussions_by_payout
485
+ q = Query(limit=10)
486
+ for h in Comment_discussions_by_payout(q):
487
+ print(h)
488
+
489
+ """
490
+
491
+ def __init__(
492
+ self,
493
+ discussion_query,
494
+ lazy=False,
495
+ use_appbase=False,
496
+ raw_data=False,
497
+ blockchain_instance=None,
498
+ **kwargs,
499
+ ):
500
+ if blockchain_instance is None:
501
+ if kwargs.get("steem_instance"):
502
+ blockchain_instance = kwargs["steem_instance"]
503
+ elif kwargs.get("hive_instance"):
504
+ blockchain_instance = kwargs["hive_instance"]
505
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
506
+ reduced_query = {}
507
+ for key in [
508
+ "tag",
509
+ "limit",
510
+ "filter_tags",
511
+ "select_authors",
512
+ "select_tags",
513
+ "truncate_body",
514
+ "start_author",
515
+ "start_permlink",
516
+ ]:
517
+ if key in discussion_query:
518
+ reduced_query[key] = discussion_query[key]
519
+ self.blockchain.rpc.set_next_node_on_empty_reply(
520
+ self.blockchain.rpc.get_use_appbase() and use_appbase
521
+ )
522
+ posts = []
523
+ try:
524
+ # Try to use the bridge API first (preferred method)
525
+ bridge_query = {
526
+ "sort": "payout_comments",
527
+ "tag": reduced_query.get("tag", ""),
528
+ "observer": "",
529
+ }
530
+ if "limit" in reduced_query:
531
+ bridge_query["limit"] = reduced_query["limit"]
532
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
533
+ bridge_query["start_author"] = reduced_query["start_author"]
534
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
535
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
536
+ except Exception:
537
+ # Fall back to old API methods
538
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
539
+ try:
540
+ posts = self.blockchain.rpc.get_comment_discussions_by_payout(
541
+ reduced_query, api="tags"
542
+ )["discussions"]
543
+ except Exception:
544
+ posts = []
545
+ if len(posts) == 0:
546
+ posts = self.blockchain.rpc.get_comment_discussions_by_payout(reduced_query)
547
+ if posts is None:
548
+ posts = []
549
+ if raw_data:
550
+ super(Comment_discussions_by_payout, self).__init__([x for x in posts])
551
+ else:
552
+ super(Comment_discussions_by_payout, self).__init__(
553
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
554
+ )
555
+
556
+
557
+ class Post_discussions_by_payout(list):
558
+ """Get post_discussions_by_payout
559
+
560
+ :param Query discussion_query: Defines the parameter for
561
+ searching posts
562
+ :param bool use_appbase: use condenser call when set to False, default is False
563
+ :param bool raw_data: returns list of comments when False, default is False
564
+ :param Steem blockchain_instance: Steem instance
565
+
566
+ .. testcode::
567
+
568
+ from nectar.discussions import Query, Post_discussions_by_payout
569
+ q = Query(limit=10)
570
+ for h in Post_discussions_by_payout(q):
571
+ print(h)
572
+
573
+ """
574
+
575
+ def __init__(
576
+ self,
577
+ discussion_query,
578
+ lazy=False,
579
+ use_appbase=False,
580
+ raw_data=False,
581
+ blockchain_instance=None,
582
+ **kwargs,
583
+ ):
584
+ if blockchain_instance is None:
585
+ if kwargs.get("steem_instance"):
586
+ blockchain_instance = kwargs["steem_instance"]
587
+ elif kwargs.get("hive_instance"):
588
+ blockchain_instance = kwargs["hive_instance"]
589
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
590
+ reduced_query = {}
591
+ for key in [
592
+ "tag",
593
+ "limit",
594
+ "filter_tags",
595
+ "select_authors",
596
+ "select_tags",
597
+ "truncate_body",
598
+ "start_author",
599
+ "start_permlink",
600
+ ]:
601
+ if key in discussion_query:
602
+ reduced_query[key] = discussion_query[key]
603
+ self.blockchain.rpc.set_next_node_on_empty_reply(
604
+ self.blockchain.rpc.get_use_appbase() and use_appbase
605
+ )
606
+ posts = []
607
+ try:
608
+ # Try to use the bridge API first (preferred method)
609
+ bridge_query = {
610
+ "sort": "payout",
611
+ "tag": reduced_query.get("tag", ""),
612
+ "observer": "",
613
+ }
614
+ if "limit" in reduced_query:
615
+ bridge_query["limit"] = reduced_query["limit"]
616
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
617
+ bridge_query["start_author"] = reduced_query["start_author"]
618
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
619
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
620
+ except Exception:
621
+ # Fall back to old API methods
622
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
623
+ try:
624
+ posts = self.blockchain.rpc.get_post_discussions_by_payout(
625
+ reduced_query, api="tags"
626
+ )["discussions"]
627
+ except Exception:
628
+ posts = []
629
+ if len(posts) == 0:
630
+ posts = self.blockchain.rpc.get_post_discussions_by_payout(reduced_query)
631
+ if posts is None:
632
+ posts = []
633
+ if raw_data:
634
+ super(Post_discussions_by_payout, self).__init__([x for x in posts])
635
+ else:
636
+ super(Post_discussions_by_payout, self).__init__(
637
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
638
+ )
639
+
640
+
641
+ class Discussions_by_created(list):
642
+ """Get discussions_by_created
643
+
644
+ :param Query discussion_query: Defines the parameter for
645
+ searching posts
646
+ :param bool use_appbase: use condenser call when set to False, default is False
647
+ :param bool raw_data: returns list of comments when False, default is False
648
+ :param Steem blockchain_instance: Steem instance
649
+
650
+ .. testcode::
651
+
652
+ from nectar.discussions import Query, Discussions_by_created
653
+ q = Query(limit=10)
654
+ for h in Discussions_by_created(q):
655
+ print(h)
656
+
657
+ """
658
+
659
+ def __init__(
660
+ self,
661
+ discussion_query,
662
+ lazy=False,
663
+ use_appbase=False,
664
+ raw_data=False,
665
+ blockchain_instance=None,
666
+ **kwargs,
667
+ ):
668
+ if blockchain_instance is None:
669
+ if kwargs.get("steem_instance"):
670
+ blockchain_instance = kwargs["steem_instance"]
671
+ elif kwargs.get("hive_instance"):
672
+ blockchain_instance = kwargs["hive_instance"]
673
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
674
+ reduced_query = {}
675
+ for key in [
676
+ "tag",
677
+ "limit",
678
+ "filter_tags",
679
+ "select_authors",
680
+ "select_tags",
681
+ "truncate_body",
682
+ "start_author",
683
+ "start_permlink",
684
+ ]:
685
+ if key in discussion_query:
686
+ reduced_query[key] = discussion_query[key]
687
+ self.blockchain.rpc.set_next_node_on_empty_reply(
688
+ self.blockchain.rpc.get_use_appbase() and use_appbase
689
+ )
690
+ posts = []
691
+ try:
692
+ # Try to use the bridge API first (preferred method)
693
+ bridge_query = {
694
+ "sort": "created",
695
+ "tag": reduced_query.get("tag", ""),
696
+ "observer": "",
697
+ }
698
+ if "limit" in reduced_query:
699
+ bridge_query["limit"] = reduced_query["limit"]
700
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
701
+ bridge_query["start_author"] = reduced_query["start_author"]
702
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
703
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
704
+ except Exception:
705
+ # Fall back to old API methods
706
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
707
+ try:
708
+ posts = self.blockchain.rpc.get_discussions_by_created(
709
+ reduced_query, api="tags"
710
+ )["discussions"]
711
+ except Exception:
712
+ posts = []
713
+ if len(posts) == 0:
714
+ posts = self.blockchain.rpc.get_discussions_by_created(reduced_query)
715
+ if posts is None:
716
+ posts = []
717
+ if raw_data:
718
+ super(Discussions_by_created, self).__init__([x for x in posts])
719
+ else:
720
+ super(Discussions_by_created, self).__init__(
721
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
722
+ )
723
+
724
+
725
+ class Discussions_by_active(list):
726
+ """get_discussions_by_active
727
+
728
+ :param Query discussion_query: Defines the parameter
729
+ searching posts
730
+ :param bool use_appbase: use condenser call when set to False, default is False
731
+ :param bool raw_data: returns list of comments when False, default is False
732
+ :param Steem blockchain_instance: Steem() instance to use when accesing a RPC
733
+
734
+ .. testcode::
735
+
736
+ from nectar.discussions import Query, Discussions_by_active
737
+ q = Query(limit=10)
738
+ for h in Discussions_by_active(q):
739
+ print(h)
740
+
741
+ """
742
+
743
+ def __init__(
744
+ self,
745
+ discussion_query,
746
+ lazy=False,
747
+ use_appbase=False,
748
+ raw_data=False,
749
+ blockchain_instance=None,
750
+ **kwargs,
751
+ ):
752
+ if blockchain_instance is None:
753
+ if kwargs.get("steem_instance"):
754
+ blockchain_instance = kwargs["steem_instance"]
755
+ elif kwargs.get("hive_instance"):
756
+ blockchain_instance = kwargs["hive_instance"]
757
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
758
+ reduced_query = {}
759
+ for key in [
760
+ "tag",
761
+ "limit",
762
+ "filter_tags",
763
+ "select_authors",
764
+ "select_tags",
765
+ "truncate_body",
766
+ "start_author",
767
+ "start_permlink",
768
+ ]:
769
+ if key in discussion_query:
770
+ reduced_query[key] = discussion_query[key]
771
+ self.blockchain.rpc.set_next_node_on_empty_reply(
772
+ self.blockchain.rpc.get_use_appbase() and use_appbase
773
+ )
774
+ posts = []
775
+ try:
776
+ # Try to use the bridge API first (preferred method)
777
+ bridge_query = {
778
+ "sort": "active",
779
+ "tag": reduced_query.get("tag", ""),
780
+ "observer": "",
781
+ }
782
+ if "limit" in reduced_query:
783
+ bridge_query["limit"] = reduced_query["limit"]
784
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
785
+ bridge_query["start_author"] = reduced_query["start_author"]
786
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
787
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
788
+ except Exception:
789
+ # Fall back to old API methods
790
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
791
+ try:
792
+ posts = self.blockchain.rpc.get_discussions_by_active(
793
+ reduced_query, api="tags"
794
+ )["discussions"]
795
+ except Exception:
796
+ posts = []
797
+ if len(posts) == 0:
798
+ posts = self.blockchain.rpc.get_discussions_by_active(reduced_query)
799
+ if posts is None:
800
+ posts = []
801
+ if raw_data:
802
+ super(Discussions_by_active, self).__init__([x for x in posts])
803
+ else:
804
+ super(Discussions_by_active, self).__init__(
805
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
806
+ )
807
+
808
+
809
+ class Discussions_by_cashout(list):
810
+ """Get discussions_by_cashout. This query seems to be broken at the moment.
811
+ The output is always empty.
812
+
813
+ :param Query discussion_query: Defines the parameter
814
+ searching posts
815
+ :param bool use_appbase: use condenser call when set to False, default is False
816
+ :param bool raw_data: returns list of comments when False, default is False
817
+ :param Steem blockchain_instance: Steem instance
818
+
819
+ .. testcode::
820
+
821
+ from nectar.discussions import Query, Discussions_by_cashout
822
+ q = Query(limit=10)
823
+ for h in Discussions_by_cashout(q):
824
+ print(h)
825
+
826
+ """
827
+
828
+ def __init__(
829
+ self,
830
+ discussion_query,
831
+ lazy=False,
832
+ use_appbase=False,
833
+ raw_data=False,
834
+ blockchain_instance=None,
835
+ **kwargs,
836
+ ):
837
+ if blockchain_instance is None:
838
+ if kwargs.get("steem_instance"):
839
+ blockchain_instance = kwargs["steem_instance"]
840
+ elif kwargs.get("hive_instance"):
841
+ blockchain_instance = kwargs["hive_instance"]
842
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
843
+ reduced_query = {}
844
+ for key in [
845
+ "tag",
846
+ "limit",
847
+ "filter_tags",
848
+ "select_authors",
849
+ "select_tags",
850
+ "truncate_body",
851
+ "start_author",
852
+ "start_permlink",
853
+ ]:
854
+ if key in discussion_query:
855
+ reduced_query[key] = discussion_query[key]
856
+ self.blockchain.rpc.set_next_node_on_empty_reply(
857
+ self.blockchain.rpc.get_use_appbase() and use_appbase
858
+ )
859
+ posts = []
860
+ try:
861
+ # Try to use the bridge API first (preferred method)
862
+ # Note: 'payout' is the closest sort to 'cashout' in bridge API
863
+ bridge_query = {
864
+ "sort": "payout",
865
+ "tag": reduced_query.get("tag", ""),
866
+ "observer": "",
867
+ }
868
+ if "limit" in reduced_query:
869
+ bridge_query["limit"] = reduced_query["limit"]
870
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
871
+ bridge_query["start_author"] = reduced_query["start_author"]
872
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
873
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
874
+ except Exception:
875
+ # Fall back to old API methods
876
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
877
+ try:
878
+ posts = self.blockchain.rpc.get_discussions_by_cashout(
879
+ reduced_query, api="tags"
880
+ )["discussions"]
881
+ except Exception:
882
+ posts = []
883
+ if len(posts) == 0:
884
+ posts = self.blockchain.rpc.get_discussions_by_cashout(reduced_query)
885
+ if posts is None:
886
+ posts = []
887
+ if raw_data:
888
+ super(Discussions_by_cashout, self).__init__([x for x in posts])
889
+ else:
890
+ super(Discussions_by_cashout, self).__init__(
891
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
892
+ )
893
+
894
+
895
+ class Discussions_by_votes(list):
896
+ """Get discussions_by_votes
897
+
898
+ :param Query discussion_query: Defines the parameter
899
+ searching posts
900
+ :param bool use_appbase: use condenser call when set to False, default is False
901
+ :param bool raw_data: returns list of comments when False, default is False
902
+ :param Steem blockchain_instance: Steem instance
903
+
904
+ .. testcode::
905
+
906
+ from nectar.discussions import Query, Discussions_by_votes
907
+ q = Query(limit=10)
908
+ for h in Discussions_by_votes(q):
909
+ print(h)
910
+
911
+ """
912
+
913
+ def __init__(
914
+ self,
915
+ discussion_query,
916
+ lazy=False,
917
+ use_appbase=False,
918
+ raw_data=False,
919
+ blockchain_instance=None,
920
+ **kwargs,
921
+ ):
922
+ if blockchain_instance is None:
923
+ if kwargs.get("steem_instance"):
924
+ blockchain_instance = kwargs["steem_instance"]
925
+ elif kwargs.get("hive_instance"):
926
+ blockchain_instance = kwargs["hive_instance"]
927
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
928
+ reduced_query = {}
929
+ for key in [
930
+ "tag",
931
+ "limit",
932
+ "filter_tags",
933
+ "select_authors",
934
+ "select_tags",
935
+ "truncate_body",
936
+ "start_author",
937
+ "start_permlink",
938
+ ]:
939
+ if key in discussion_query:
940
+ reduced_query[key] = discussion_query[key]
941
+ self.blockchain.rpc.set_next_node_on_empty_reply(
942
+ self.blockchain.rpc.get_use_appbase() and use_appbase
943
+ )
944
+ posts = []
945
+ try:
946
+ # Try to use the bridge API first (preferred method)
947
+ # Note: There is no direct 'votes' sort in bridge API, so we'll approximate using trending
948
+ bridge_query = {
949
+ "sort": "trending",
950
+ "tag": reduced_query.get("tag", ""),
951
+ "observer": "",
952
+ }
953
+ if "limit" in reduced_query:
954
+ bridge_query["limit"] = reduced_query["limit"]
955
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
956
+ bridge_query["start_author"] = reduced_query["start_author"]
957
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
958
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
959
+ except Exception:
960
+ # Fall back to old API methods
961
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
962
+ try:
963
+ posts = self.blockchain.rpc.get_discussions_by_votes(reduced_query, api="tags")[
964
+ "discussions"
965
+ ]
966
+ except Exception:
967
+ posts = []
968
+ if len(posts) == 0:
969
+ posts = self.blockchain.rpc.get_discussions_by_votes(reduced_query)
970
+ if posts is None:
971
+ posts = []
972
+ if raw_data:
973
+ super(Discussions_by_votes, self).__init__([x for x in posts])
974
+ else:
975
+ super(Discussions_by_votes, self).__init__(
976
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
977
+ )
978
+
979
+
980
+ class Discussions_by_children(list):
981
+ """Get discussions by children
982
+
983
+ :param Query discussion_query: Defines the parameter
984
+ searching posts
985
+ :param bool use_appbase: use condenser call when set to False, default is False
986
+ :param bool raw_data: returns list of comments when False, default is False
987
+ :param Steem blockchain_instance: Steem instance
988
+
989
+ .. testcode::
990
+
991
+ from nectar.discussions import Query, Discussions_by_children
992
+ q = Query(limit=10)
993
+ for h in Discussions_by_children(q):
994
+ print(h)
995
+
996
+ """
997
+
998
+ def __init__(
999
+ self,
1000
+ discussion_query,
1001
+ lazy=False,
1002
+ use_appbase=False,
1003
+ raw_data=False,
1004
+ blockchain_instance=None,
1005
+ **kwargs,
1006
+ ):
1007
+ if blockchain_instance is None:
1008
+ if kwargs.get("steem_instance"):
1009
+ blockchain_instance = kwargs["steem_instance"]
1010
+ elif kwargs.get("hive_instance"):
1011
+ blockchain_instance = kwargs["hive_instance"]
1012
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1013
+ reduced_query = {}
1014
+ for key in [
1015
+ "tag",
1016
+ "limit",
1017
+ "filter_tags",
1018
+ "select_authors",
1019
+ "select_tags",
1020
+ "truncate_body",
1021
+ "start_author",
1022
+ "start_permlink",
1023
+ ]:
1024
+ if key in discussion_query:
1025
+ reduced_query[key] = discussion_query[key]
1026
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1027
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1028
+ )
1029
+ posts = []
1030
+ try:
1031
+ # Try to use the bridge API first (preferred method)
1032
+ # Note: There is no direct 'children' sort in bridge API, we'll use 'trending' as a fallback
1033
+ bridge_query = {
1034
+ "sort": "trending",
1035
+ "tag": reduced_query.get("tag", ""),
1036
+ "observer": "",
1037
+ }
1038
+ if "limit" in reduced_query:
1039
+ bridge_query["limit"] = reduced_query["limit"]
1040
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1041
+ bridge_query["start_author"] = reduced_query["start_author"]
1042
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
1043
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
1044
+ # We could try to sort posts by their children count here if needed
1045
+ except Exception:
1046
+ # Fall back to old API methods
1047
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1048
+ try:
1049
+ posts = self.blockchain.rpc.get_discussions_by_children(
1050
+ reduced_query, api="tags"
1051
+ )["discussions"]
1052
+ except Exception:
1053
+ posts = []
1054
+ if len(posts) == 0:
1055
+ posts = self.blockchain.rpc.get_discussions_by_children(reduced_query)
1056
+ if posts is None:
1057
+ posts = []
1058
+ if raw_data:
1059
+ super(Discussions_by_children, self).__init__([x for x in posts])
1060
+ else:
1061
+ super(Discussions_by_children, self).__init__(
1062
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1063
+ )
1064
+
1065
+
1066
+ class Discussions_by_hot(list):
1067
+ """Get discussions by hot
1068
+
1069
+ :param Query discussion_query: Defines the parameter
1070
+ searching posts
1071
+ :param bool use_appbase: use condenser call when set to False, default is False
1072
+ :param bool raw_data: returns list of comments when False, default is False
1073
+ :param Steem blockchain_instance: Steem instance
1074
+
1075
+ .. testcode::
1076
+
1077
+ from nectar.discussions import Query, Discussions_by_hot
1078
+ q = Query(limit=10, tag="steem")
1079
+ for h in Discussions_by_hot(q):
1080
+ print(h)
1081
+
1082
+ """
1083
+
1084
+ def __init__(
1085
+ self,
1086
+ discussion_query,
1087
+ lazy=False,
1088
+ use_appbase=False,
1089
+ raw_data=False,
1090
+ blockchain_instance=None,
1091
+ **kwargs,
1092
+ ):
1093
+ if blockchain_instance is None:
1094
+ if kwargs.get("steem_instance"):
1095
+ blockchain_instance = kwargs["steem_instance"]
1096
+ elif kwargs.get("hive_instance"):
1097
+ blockchain_instance = kwargs["hive_instance"]
1098
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1099
+ reduced_query = {}
1100
+ for key in [
1101
+ "tag",
1102
+ "limit",
1103
+ "filter_tags",
1104
+ "select_authors",
1105
+ "select_tags",
1106
+ "truncate_body",
1107
+ "start_author",
1108
+ "start_permlink",
1109
+ ]:
1110
+ if key in discussion_query:
1111
+ reduced_query[key] = discussion_query[key]
1112
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1113
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1114
+ )
1115
+ posts = []
1116
+ try:
1117
+ # Try to use the bridge API first (preferred method)
1118
+ bridge_query = {
1119
+ "sort": "hot",
1120
+ "tag": reduced_query.get("tag", ""),
1121
+ "observer": "",
1122
+ }
1123
+ if "limit" in reduced_query:
1124
+ bridge_query["limit"] = reduced_query["limit"]
1125
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1126
+ bridge_query["start_author"] = reduced_query["start_author"]
1127
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
1128
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
1129
+ except Exception:
1130
+ # Fall back to old API methods
1131
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1132
+ try:
1133
+ posts = self.blockchain.rpc.get_discussions_by_hot(reduced_query, api="tags")[
1134
+ "discussions"
1135
+ ]
1136
+ except Exception:
1137
+ posts = []
1138
+ if len(posts) == 0:
1139
+ posts = self.blockchain.rpc.get_discussions_by_hot(reduced_query)
1140
+ if posts is None:
1141
+ posts = []
1142
+ if raw_data:
1143
+ super(Discussions_by_hot, self).__init__([x for x in posts])
1144
+ else:
1145
+ super(Discussions_by_hot, self).__init__(
1146
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1147
+ )
1148
+
1149
+
1150
+ class Discussions_by_feed(list):
1151
+ """Get discussions by feed
1152
+
1153
+ :param Query discussion_query: Defines the parameter
1154
+ searching posts, tag musst be set to a username
1155
+ :param bool use_appbase: use condenser call when set to False, default is False
1156
+ :param bool raw_data: returns list of comments when False, default is False
1157
+ :param Steem blockchain_instance: Steem instance
1158
+
1159
+ .. testcode::
1160
+
1161
+ from nectar.discussions import Query, Discussions_by_feed
1162
+ q = Query(limit=10, tag="steemit")
1163
+ for h in Discussions_by_feed(q):
1164
+ print(h)
1165
+
1166
+ """
1167
+
1168
+ def __init__(
1169
+ self,
1170
+ discussion_query,
1171
+ lazy=False,
1172
+ use_appbase=False,
1173
+ raw_data=False,
1174
+ blockchain_instance=None,
1175
+ **kwargs,
1176
+ ):
1177
+ if blockchain_instance is None:
1178
+ if kwargs.get("steem_instance"):
1179
+ blockchain_instance = kwargs["steem_instance"]
1180
+ elif kwargs.get("hive_instance"):
1181
+ blockchain_instance = kwargs["hive_instance"]
1182
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1183
+ reduced_query = {}
1184
+ for key in [
1185
+ "tag",
1186
+ "limit",
1187
+ "filter_tags",
1188
+ "select_authors",
1189
+ "select_tags",
1190
+ "truncate_body",
1191
+ "start_author",
1192
+ "start_permlink",
1193
+ ]:
1194
+ if key in discussion_query:
1195
+ reduced_query[key] = discussion_query[key]
1196
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1197
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1198
+ )
1199
+ posts = []
1200
+ try:
1201
+ # Try to use the bridge API first (preferred method)
1202
+ account = reduced_query.get("tag", "")
1203
+ if account:
1204
+ bridge_query = {
1205
+ "sort": "feed",
1206
+ "account": account,
1207
+ "limit": reduced_query.get("limit", 20),
1208
+ }
1209
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1210
+ bridge_query["start_author"] = reduced_query["start_author"]
1211
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
1212
+ posts = self.blockchain.rpc.get_account_posts(bridge_query, api="bridge")
1213
+ except Exception:
1214
+ # Fall back to old API methods
1215
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1216
+ try:
1217
+ posts = self.blockchain.rpc.get_discussions_by_feed(reduced_query, api="tags")[
1218
+ "discussions"
1219
+ ]
1220
+ except Exception:
1221
+ posts = []
1222
+ if len(posts) == 0:
1223
+ posts = self.blockchain.rpc.get_discussions_by_feed(reduced_query)
1224
+ if posts is None:
1225
+ posts = []
1226
+ if raw_data:
1227
+ super(Discussions_by_feed, self).__init__([x for x in posts])
1228
+ else:
1229
+ super(Discussions_by_feed, self).__init__(
1230
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1231
+ )
1232
+
1233
+
1234
+ class Discussions_by_blog(list):
1235
+ """Get discussions by blog
1236
+
1237
+ :param Query discussion_query: Defines the parameter
1238
+ searching posts, tag musst be set to a username
1239
+ :param bool use_appbase: use condenser call when set to False, default is False
1240
+ :param bool raw_data: returns list of comments when False, default is False
1241
+ :param Steem blockchain_instance: Steem instance
1242
+
1243
+ .. testcode::
1244
+
1245
+ from nectar.discussions import Query, Discussions_by_blog
1246
+ q = Query(limit=10)
1247
+ for h in Discussions_by_blog(q):
1248
+ print(h)
1249
+
1250
+ """
1251
+
1252
+ def __init__(
1253
+ self,
1254
+ discussion_query,
1255
+ lazy=False,
1256
+ use_appbase=False,
1257
+ raw_data=False,
1258
+ blockchain_instance=None,
1259
+ **kwargs,
1260
+ ):
1261
+ if blockchain_instance is None:
1262
+ if kwargs.get("steem_instance"):
1263
+ blockchain_instance = kwargs["steem_instance"]
1264
+ elif kwargs.get("hive_instance"):
1265
+ blockchain_instance = kwargs["hive_instance"]
1266
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1267
+ reduced_query = {}
1268
+ for key in [
1269
+ "tag",
1270
+ "limit",
1271
+ "filter_tags",
1272
+ "select_authors",
1273
+ "select_tags",
1274
+ "truncate_body",
1275
+ "start_author",
1276
+ "start_permlink",
1277
+ ]:
1278
+ if key in discussion_query:
1279
+ reduced_query[key] = discussion_query[key]
1280
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1281
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1282
+ )
1283
+ posts = []
1284
+ try:
1285
+ # Try to use the bridge API first (preferred method)
1286
+ account = reduced_query.get("tag", "")
1287
+ if account:
1288
+ bridge_query = {
1289
+ "sort": "blog",
1290
+ "account": account,
1291
+ "limit": reduced_query.get("limit", 20),
1292
+ }
1293
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1294
+ bridge_query["start_author"] = reduced_query["start_author"]
1295
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
1296
+ posts = self.blockchain.rpc.get_account_posts(bridge_query, api="bridge")
1297
+ except Exception:
1298
+ # Fall back to old API methods
1299
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1300
+ try:
1301
+ posts = self.blockchain.rpc.get_discussions_by_blog(reduced_query, api="tags")
1302
+ if isinstance(posts, dict) and "discussions" in posts:
1303
+ posts = posts["discussions"]
1304
+ except Exception:
1305
+ posts = []
1306
+ if len(posts) == 0:
1307
+ self.blockchain.rpc.set_next_node_on_empty_reply(False)
1308
+ posts = self.blockchain.rpc.get_discussions_by_blog(reduced_query)
1309
+ if posts is None:
1310
+ posts = []
1311
+ if raw_data:
1312
+ super(Discussions_by_blog, self).__init__([x for x in posts])
1313
+ else:
1314
+ super(Discussions_by_blog, self).__init__(
1315
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1316
+ )
1317
+
1318
+
1319
+ class Discussions_by_comments(list):
1320
+ """Get discussions by comments
1321
+
1322
+ :param Query discussion_query: Defines the parameter
1323
+ searching posts, start_author and start_permlink must be set.
1324
+ :param bool use_appbase: use condenser call when set to False, default is False
1325
+ :param bool raw_data: returns list of comments when False, default is False
1326
+ :param Steem blockchain_instance: Steem instance
1327
+
1328
+ .. testcode::
1329
+
1330
+ from nectar.discussions import Query, Discussions_by_comments
1331
+ q = Query(limit=10, start_author="steemit", start_permlink="firstpost")
1332
+ for h in Discussions_by_comments(q):
1333
+ print(h)
1334
+
1335
+ """
1336
+
1337
+ def __init__(
1338
+ self,
1339
+ discussion_query,
1340
+ lazy=False,
1341
+ use_appbase=False,
1342
+ raw_data=False,
1343
+ blockchain_instance=None,
1344
+ **kwargs,
1345
+ ):
1346
+ if blockchain_instance is None:
1347
+ if kwargs.get("steem_instance"):
1348
+ blockchain_instance = kwargs["steem_instance"]
1349
+ elif kwargs.get("hive_instance"):
1350
+ blockchain_instance = kwargs["hive_instance"]
1351
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1352
+ reduced_query = {}
1353
+ for key in ["start_author", "start_permlink", "limit"]:
1354
+ if key in discussion_query:
1355
+ reduced_query[key] = discussion_query[key]
1356
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1357
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1358
+ )
1359
+ posts = []
1360
+ try:
1361
+ # Try to use the bridge API first (preferred method)
1362
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1363
+ # The bridge.get_discussion API retrieves an entire discussion tree
1364
+ author = reduced_query["start_author"]
1365
+ permlink = reduced_query["start_permlink"]
1366
+ bridge_query = {
1367
+ "author": author,
1368
+ "permlink": permlink,
1369
+ }
1370
+ # The bridge API returns a discussion tree, we need to flatten it
1371
+ discussion = self.blockchain.rpc.get_discussion(bridge_query, api="bridge")
1372
+ # Extract comments from the discussion tree
1373
+ if discussion and isinstance(discussion, dict):
1374
+ posts = []
1375
+ # Start with the main post
1376
+ main_post = discussion.get(f"@{author}/{permlink}")
1377
+ if main_post:
1378
+ posts.append(main_post)
1379
+ # Add replies
1380
+ for key, value in discussion.items():
1381
+ if key != f"@{author}/{permlink}" and isinstance(value, dict):
1382
+ posts.append(value)
1383
+ # Limit the number of posts if needed
1384
+ if "limit" in reduced_query and len(posts) > reduced_query["limit"]:
1385
+ posts = posts[: reduced_query["limit"]]
1386
+ except Exception:
1387
+ # Fall back to old API methods
1388
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1389
+ try:
1390
+ posts = self.blockchain.rpc.get_discussions_by_comments(
1391
+ reduced_query, api="tags"
1392
+ )
1393
+ if "discussions" in posts:
1394
+ posts = posts["discussions"] # inconsistent format across node types
1395
+ except Exception:
1396
+ posts = self.blockchain.rpc.get_discussions_by_comments(
1397
+ reduced_query["start_author"],
1398
+ reduced_query["start_permlink"],
1399
+ reduced_query["limit"],
1400
+ )
1401
+ if len(posts) == 0:
1402
+ posts = self.blockchain.rpc.get_discussions_by_comments(reduced_query)
1403
+ if posts is None:
1404
+ posts = []
1405
+ if raw_data:
1406
+ super(Discussions_by_comments, self).__init__([x for x in posts])
1407
+ else:
1408
+ super(Discussions_by_comments, self).__init__(
1409
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1410
+ )
1411
+
1412
+
1413
+ class Discussions_by_promoted(list):
1414
+ """Get discussions by promoted
1415
+
1416
+ :param Query discussion_query: Defines the parameter
1417
+ searching posts
1418
+ :param bool use_appbase: use condenser call when set to False, default is False
1419
+ :param bool raw_data: returns list of comments when False, default is False
1420
+ :param Steem blockchain_instance: Steem instance
1421
+
1422
+ .. testcode::
1423
+
1424
+ from nectar.discussions import Query, Discussions_by_promoted
1425
+ q = Query(limit=10, tag="steem")
1426
+ for h in Discussions_by_promoted(q):
1427
+ print(h)
1428
+
1429
+ """
1430
+
1431
+ def __init__(
1432
+ self,
1433
+ discussion_query,
1434
+ lazy=False,
1435
+ use_appbase=False,
1436
+ raw_data=False,
1437
+ blockchain_instance=None,
1438
+ **kwargs,
1439
+ ):
1440
+ if blockchain_instance is None:
1441
+ if kwargs.get("steem_instance"):
1442
+ blockchain_instance = kwargs["steem_instance"]
1443
+ elif kwargs.get("hive_instance"):
1444
+ blockchain_instance = kwargs["hive_instance"]
1445
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1446
+ reduced_query = {}
1447
+ for key in [
1448
+ "tag",
1449
+ "limit",
1450
+ "filter_tags",
1451
+ "select_authors",
1452
+ "select_tags",
1453
+ "truncate_body",
1454
+ "start_author",
1455
+ "start_permlink",
1456
+ ]:
1457
+ if key in discussion_query:
1458
+ reduced_query[key] = discussion_query[key]
1459
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1460
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1461
+ )
1462
+ posts = []
1463
+ try:
1464
+ # Try to use the bridge API first (preferred method)
1465
+ bridge_query = {
1466
+ "sort": "promoted",
1467
+ "tag": reduced_query.get("tag", ""),
1468
+ "observer": "",
1469
+ }
1470
+ if "limit" in reduced_query:
1471
+ bridge_query["limit"] = reduced_query["limit"]
1472
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1473
+ bridge_query["start_author"] = reduced_query["start_author"]
1474
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
1475
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query, api="bridge")
1476
+ except Exception:
1477
+ # Fall back to old API methods
1478
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1479
+ try:
1480
+ posts = self.blockchain.rpc.get_discussions_by_promoted(
1481
+ reduced_query, api="tags"
1482
+ )["discussions"]
1483
+ except Exception:
1484
+ posts = []
1485
+ if len(posts) == 0:
1486
+ posts = self.blockchain.rpc.get_discussions_by_promoted(reduced_query)
1487
+ if posts is None:
1488
+ posts = []
1489
+ if raw_data:
1490
+ super(Discussions_by_promoted, self).__init__([x for x in posts])
1491
+ else:
1492
+ super(Discussions_by_promoted, self).__init__(
1493
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1494
+ )
1495
+
1496
+
1497
+ class Discussions_by_replies(list):
1498
+ """Get replies for an author's post
1499
+
1500
+ :param Query discussion_query: Defines the parameter
1501
+ searching posts, start_parent_author, start_permlink must be set.
1502
+ :param bool use_appbase: use condenser call when set to False, default is False
1503
+ :param bool raw_data: returns list of comments when False, default is False
1504
+ :param Steem blockchain_instance: Steem instance
1505
+
1506
+ .. testcode::
1507
+
1508
+ from nectar.discussions import Query, Discussions_by_replies
1509
+ q = Query(limit=10, start_parent_author="steemit", start_permlink="firstpost")
1510
+ for h in Discussions_by_replies(q):
1511
+ print(h)
1512
+
1513
+ """
1514
+
1515
+ def __init__(
1516
+ self,
1517
+ discussion_query,
1518
+ lazy=False,
1519
+ use_appbase=False,
1520
+ raw_data=False,
1521
+ blockchain_instance=None,
1522
+ **kwargs,
1523
+ ):
1524
+ if blockchain_instance is None:
1525
+ if kwargs.get("steem_instance"):
1526
+ blockchain_instance = kwargs["steem_instance"]
1527
+ elif kwargs.get("hive_instance"):
1528
+ blockchain_instance = kwargs["hive_instance"]
1529
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1530
+ reduced_query = {}
1531
+ for key in ["start_parent_author", "start_permlink", "limit"]:
1532
+ if key in discussion_query:
1533
+ reduced_query[key] = discussion_query[key]
1534
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1535
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1536
+ )
1537
+ posts = []
1538
+ try:
1539
+ # Try to use the bridge API first (preferred method)
1540
+ if "start_parent_author" in reduced_query and "start_permlink" in reduced_query:
1541
+ # The bridge.get_discussion API retrieves replies to a post as well
1542
+ author = reduced_query["start_parent_author"]
1543
+ permlink = reduced_query["start_permlink"]
1544
+ bridge_query = {
1545
+ "author": author,
1546
+ "permlink": permlink,
1547
+ }
1548
+ # The bridge API returns a discussion tree
1549
+ discussion = self.blockchain.rpc.get_discussion(bridge_query, api="bridge")
1550
+ # Extract replies from the discussion tree
1551
+ if discussion and isinstance(discussion, dict):
1552
+ posts = []
1553
+ # Gather all replies (all items except the main post)
1554
+ main_post_key = f"@{author}/{permlink}"
1555
+ for key, value in discussion.items():
1556
+ if key != main_post_key and isinstance(value, dict):
1557
+ posts.append(value)
1558
+ # Limit the number of posts if needed
1559
+ if "limit" in reduced_query and len(posts) > reduced_query["limit"]:
1560
+ posts = posts[: reduced_query["limit"]]
1561
+ except Exception:
1562
+ # Fall back to old API methods
1563
+ posts = []
1564
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1565
+ try:
1566
+ posts = self.blockchain.rpc.get_replies_by_last_update(
1567
+ reduced_query, api="tags"
1568
+ )
1569
+ if "discussions" in posts:
1570
+ posts = posts["discussions"]
1571
+ except Exception:
1572
+ posts = self.blockchain.rpc.get_replies_by_last_update(
1573
+ reduced_query["start_parent_author"],
1574
+ reduced_query["start_permlink"],
1575
+ reduced_query["limit"],
1576
+ )
1577
+ if len(posts) == 0:
1578
+ if (
1579
+ "start_parent_author" in reduced_query and reduced_query["start_parent_author"]
1580
+ ) and ("start_permlink" in reduced_query and reduced_query["start_permlink"]):
1581
+ if "limit" in reduced_query:
1582
+ posts = self.blockchain.rpc.get_replies_by_last_update(
1583
+ reduced_query["start_parent_author"],
1584
+ reduced_query["start_permlink"],
1585
+ reduced_query["limit"],
1586
+ )
1587
+ else:
1588
+ posts = self.blockchain.rpc.get_replies_by_last_update(
1589
+ reduced_query["start_parent_author"],
1590
+ reduced_query["start_permlink"],
1591
+ 100,
1592
+ )
1593
+ if posts is None:
1594
+ posts = []
1595
+ if raw_data:
1596
+ super(Discussions_by_replies, self).__init__([x for x in posts])
1597
+ else:
1598
+ super(Discussions_by_replies, self).__init__(
1599
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1600
+ )
1601
+
1602
+
1603
+ class Replies_by_last_update(list):
1604
+ """Returns a list of replies by last update
1605
+
1606
+ :param Query discussion_query: Defines the parameter
1607
+ searching posts start_parent_author and start_permlink must be set.
1608
+ :param bool use_appbase: use condenser call when set to False, default is False
1609
+ :param bool raw_data: returns list of comments when False, default is False
1610
+ :param Steem blockchain_instance: Steem instance
1611
+
1612
+ .. testcode::
1613
+
1614
+ from nectar.discussions import Query, Replies_by_last_update
1615
+ q = Query(limit=10, start_parent_author="steemit", start_permlink="firstpost")
1616
+ for h in Replies_by_last_update(q):
1617
+ print(h)
1618
+
1619
+ """
1620
+
1621
+ def __init__(
1622
+ self,
1623
+ discussion_query,
1624
+ lazy=False,
1625
+ use_appbase=False,
1626
+ raw_data=False,
1627
+ blockchain_instance=None,
1628
+ **kwargs,
1629
+ ):
1630
+ if blockchain_instance is None:
1631
+ if kwargs.get("steem_instance"):
1632
+ blockchain_instance = kwargs["steem_instance"]
1633
+ elif kwargs.get("hive_instance"):
1634
+ blockchain_instance = kwargs["hive_instance"]
1635
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1636
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1637
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1638
+ )
1639
+ posts = []
1640
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1641
+ try:
1642
+ posts = self.blockchain.rpc.get_replies_by_last_update(discussion_query, api="tags")
1643
+ if "discussions" in posts:
1644
+ posts = posts["discussions"]
1645
+ except Exception:
1646
+ posts = self.blockchain.rpc.get_replies_by_last_update(
1647
+ discussion_query["start_author"],
1648
+ discussion_query["start_permlink"],
1649
+ discussion_query["limit"],
1650
+ )
1651
+ if len(posts) == 0:
1652
+ posts = self.blockchain.rpc.get_replies_by_last_update(
1653
+ discussion_query["start_author"],
1654
+ discussion_query["start_permlink"],
1655
+ discussion_query["limit"],
1656
+ )
1657
+ if posts is None:
1658
+ posts = []
1659
+ if raw_data:
1660
+ super(Replies_by_last_update, self).__init__([x for x in posts])
1661
+ else:
1662
+ super(Replies_by_last_update, self).__init__(
1663
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1664
+ )
1665
+
1666
+
1667
+ class Trending_tags(list):
1668
+ """Get trending tags
1669
+
1670
+ :param Query discussion_query: Defines the parameter
1671
+ searching posts, start_tag is used if set
1672
+ :param Steem blockchain_instance: Steem instance
1673
+
1674
+ .. testcode::
1675
+
1676
+ from nectar.discussions import Query, Trending_tags
1677
+ q = Query(limit=10)
1678
+ for h in Trending_tags(q):
1679
+ print(h)
1680
+
1681
+ """
1682
+
1683
+ def __init__(
1684
+ self, discussion_query, lazy=False, use_appbase=False, blockchain_instance=None, **kwargs
1685
+ ):
1686
+ if blockchain_instance is None:
1687
+ if kwargs.get("steem_instance"):
1688
+ blockchain_instance = kwargs["steem_instance"]
1689
+ elif kwargs.get("hive_instance"):
1690
+ blockchain_instance = kwargs["hive_instance"]
1691
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1692
+ self.blockchain.rpc.set_next_node_on_empty_reply(
1693
+ self.blockchain.rpc.get_use_appbase() and use_appbase
1694
+ )
1695
+ limit = discussion_query["limit"] if "limit" in discussion_query else 0
1696
+ tags = []
1697
+ try:
1698
+ # Try to use bridge API for getting trending tags
1699
+ # Unfortunately there's no direct bridge API for tags, so we fall back to condenser API
1700
+ if self.blockchain.rpc.get_use_appbase() and use_appbase:
1701
+ tags = self.blockchain.rpc.get_trending_tags(
1702
+ {"start": "", "limit": limit}, api="condenser"
1703
+ )["tags"]
1704
+ else:
1705
+ tags = self.blockchain.rpc.get_trending_tags("", limit)
1706
+ except Exception:
1707
+ # If API fails, return empty list
1708
+ pass
1709
+ super(Trending_tags, self).__init__(tags)