hive-nectar 0.2.9__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.
Files changed (87) hide show
  1. hive_nectar-0.2.9.dist-info/METADATA +194 -0
  2. hive_nectar-0.2.9.dist-info/RECORD +87 -0
  3. hive_nectar-0.2.9.dist-info/WHEEL +4 -0
  4. hive_nectar-0.2.9.dist-info/entry_points.txt +2 -0
  5. hive_nectar-0.2.9.dist-info/licenses/LICENSE.txt +23 -0
  6. nectar/__init__.py +37 -0
  7. nectar/account.py +5076 -0
  8. nectar/amount.py +553 -0
  9. nectar/asciichart.py +303 -0
  10. nectar/asset.py +122 -0
  11. nectar/block.py +574 -0
  12. nectar/blockchain.py +1242 -0
  13. nectar/blockchaininstance.py +2590 -0
  14. nectar/blockchainobject.py +263 -0
  15. nectar/cli.py +5937 -0
  16. nectar/comment.py +1552 -0
  17. nectar/community.py +854 -0
  18. nectar/constants.py +95 -0
  19. nectar/discussions.py +1437 -0
  20. nectar/exceptions.py +152 -0
  21. nectar/haf.py +381 -0
  22. nectar/hive.py +630 -0
  23. nectar/imageuploader.py +114 -0
  24. nectar/instance.py +113 -0
  25. nectar/market.py +876 -0
  26. nectar/memo.py +542 -0
  27. nectar/message.py +379 -0
  28. nectar/nodelist.py +309 -0
  29. nectar/price.py +603 -0
  30. nectar/profile.py +74 -0
  31. nectar/py.typed +0 -0
  32. nectar/rc.py +333 -0
  33. nectar/snapshot.py +1024 -0
  34. nectar/storage.py +62 -0
  35. nectar/transactionbuilder.py +659 -0
  36. nectar/utils.py +630 -0
  37. nectar/version.py +3 -0
  38. nectar/vote.py +722 -0
  39. nectar/wallet.py +472 -0
  40. nectar/witness.py +728 -0
  41. nectarapi/__init__.py +12 -0
  42. nectarapi/exceptions.py +126 -0
  43. nectarapi/graphenerpc.py +596 -0
  44. nectarapi/node.py +194 -0
  45. nectarapi/noderpc.py +79 -0
  46. nectarapi/openapi.py +107 -0
  47. nectarapi/py.typed +0 -0
  48. nectarapi/rpcutils.py +98 -0
  49. nectarapi/version.py +3 -0
  50. nectarbase/__init__.py +15 -0
  51. nectarbase/ledgertransactions.py +106 -0
  52. nectarbase/memo.py +242 -0
  53. nectarbase/objects.py +521 -0
  54. nectarbase/objecttypes.py +21 -0
  55. nectarbase/operationids.py +102 -0
  56. nectarbase/operations.py +1357 -0
  57. nectarbase/py.typed +0 -0
  58. nectarbase/signedtransactions.py +89 -0
  59. nectarbase/transactions.py +11 -0
  60. nectarbase/version.py +3 -0
  61. nectargraphenebase/__init__.py +27 -0
  62. nectargraphenebase/account.py +1121 -0
  63. nectargraphenebase/aes.py +49 -0
  64. nectargraphenebase/base58.py +197 -0
  65. nectargraphenebase/bip32.py +575 -0
  66. nectargraphenebase/bip38.py +110 -0
  67. nectargraphenebase/chains.py +15 -0
  68. nectargraphenebase/dictionary.py +2 -0
  69. nectargraphenebase/ecdsasig.py +309 -0
  70. nectargraphenebase/objects.py +130 -0
  71. nectargraphenebase/objecttypes.py +8 -0
  72. nectargraphenebase/operationids.py +5 -0
  73. nectargraphenebase/operations.py +25 -0
  74. nectargraphenebase/prefix.py +13 -0
  75. nectargraphenebase/py.typed +0 -0
  76. nectargraphenebase/signedtransactions.py +221 -0
  77. nectargraphenebase/types.py +557 -0
  78. nectargraphenebase/unsignedtransactions.py +288 -0
  79. nectargraphenebase/version.py +3 -0
  80. nectarstorage/__init__.py +57 -0
  81. nectarstorage/base.py +317 -0
  82. nectarstorage/exceptions.py +15 -0
  83. nectarstorage/interfaces.py +244 -0
  84. nectarstorage/masterpassword.py +237 -0
  85. nectarstorage/py.typed +0 -0
  86. nectarstorage/ram.py +27 -0
  87. nectarstorage/sqlite.py +343 -0
nectar/discussions.py ADDED
@@ -0,0 +1,1437 @@
1
+ import logging
2
+ from typing import Any, List, Optional
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="hive")
32
+
33
+ """
34
+
35
+ def __init__(
36
+ self,
37
+ limit: int = 0,
38
+ tag: str = "",
39
+ truncate_body: int = 0,
40
+ filter_tags: Optional[List[str]] = None,
41
+ select_authors: Optional[List[str]] = None,
42
+ select_tags: Optional[List[str]] = None,
43
+ start_author: Optional[str] = None,
44
+ start_permlink: Optional[str] = None,
45
+ start_tag: Optional[str] = None,
46
+ parent_author: Optional[str] = None,
47
+ parent_permlink: Optional[str] = None,
48
+ start_parent_author: Optional[str] = None,
49
+ before_date: Optional[str] = None,
50
+ author: Optional[str] = None,
51
+ observer: Optional[str] = None,
52
+ ) -> None:
53
+ """
54
+ Initialize a Query mapping for discussion fetches.
55
+
56
+ Creates a dict-like Query object containing normalized discussion query parameters used by the Discussions fetchers. List-valued parameters default to empty lists when None. Values are stored as keys on self (e.g. self["limit"], self["tag"], etc.).
57
+
58
+ Parameters:
59
+ limit (int): Maximum number of items requested (0 means no explicit client-side limit).
60
+ tag (str): Topic tag or account (used by feed/blog where appropriate).
61
+ truncate_body (int): Number of characters to truncate post bodies to (0 = no truncate).
62
+ filter_tags (list|None): Tags to exclude; defaults to [].
63
+ select_authors (list|None): Authors to include; defaults to [].
64
+ select_tags (list|None): Tags to include; defaults to [].
65
+ start_author (str|None): Author name used as a pagination starting point.
66
+ start_permlink (str|None): Permlink used as a pagination starting point.
67
+ start_tag (str|None): Tag used as a pagination starting point for tag-based queries.
68
+ parent_author (str|None): Parent post author (used for comment/replies queries).
69
+ parent_permlink (str|None): Parent post permlink (used for comment/replies queries).
70
+ start_parent_author (str|None): Parent author used for pagination in replies queries.
71
+ before_date (str|None): ISO 8601 datetime string to fetch items before this timestamp.
72
+ author (str|None): Author name for author-scoped queries.
73
+ observer (str|None): Observer account name for user-specific data (e.g., vote status).
74
+ """
75
+ self["limit"] = limit
76
+ self["truncate_body"] = truncate_body
77
+ self["tag"] = tag
78
+ self["filter_tags"] = filter_tags or []
79
+ self["select_authors"] = select_authors or []
80
+ self["select_tags"] = select_tags or []
81
+ self["start_author"] = start_author
82
+ self["start_permlink"] = start_permlink
83
+ self["start_tag"] = start_tag
84
+ self["parent_author"] = parent_author
85
+ self["parent_permlink"] = parent_permlink
86
+ self["start_parent_author"] = start_parent_author
87
+ self["before_date"] = before_date
88
+ self["author"] = author
89
+ self["observer"] = observer
90
+
91
+
92
+ class Discussions:
93
+ """Get Discussions
94
+
95
+ :param Hive blockchain_instance: Hive instance
96
+
97
+ """
98
+
99
+ def __init__(
100
+ self, lazy: bool = False, blockchain_instance: Optional[Any] = None, **kwargs: Any
101
+ ) -> None:
102
+ """
103
+ Initialize the Discussions orchestrator.
104
+
105
+ Parameters:
106
+ lazy (bool): If True, wrap fetched items in lazy-loading Comment objects.
107
+
108
+ Notes:
109
+ - The resolved blockchain instance is stored on self.blockchain (falls back to shared_blockchain_instance() when none provided).
110
+ """
111
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
112
+ self.lazy = lazy
113
+
114
+ def get_discussions(self, discussion_type, discussion_query, limit=1000, raw_data=False):
115
+ """
116
+ Yield discussions of a given type according to a Query, handling pagination.
117
+
118
+ This generator fetches discussions in pages from the appropriate per-type helper
119
+ and yields individual discussion entries until `limit` items have been yielded
120
+ or no more results are available.
121
+
122
+ Parameters:
123
+ discussion_type (str): One of:
124
+ "trending", "author_before_date", "payout", "post_payout", "created",
125
+ "active", "cashout", "votes", "children", "hot", "feed", "blog",
126
+ "comments", "promoted", "replies", "tags".
127
+ Determines which backend/query helper is used.
128
+ discussion_query (Query): Query-like mapping with parameters used by the
129
+ underlying helpers (e.g., limit, tag, start_author, start_permlink,
130
+ before_date). If `discussion_query["limit"]` is 0, it will be set to
131
+ 100 when `limit >= 100`, otherwise set to the provided `limit`.
132
+ If `before_date` is falsy, it will be set to "1970-01-01T00:00:00".
133
+ limit (int): Maximum number of discussion items to yield (default 1000).
134
+ raw_data (bool): If True, helpers are requested to return raw dict data;
135
+ if False, helpers may return wrapped Comment objects when supported.
136
+
137
+ Yields:
138
+ Individual discussion items as returned by the selected helper:
139
+ - For post/comment helpers: dicts when `raw_data=True`, or Comment objects
140
+ when `raw_data=False` and wrapping is supported.
141
+ - For "tags": tag dictionaries.
142
+
143
+ Behavior and notes:
144
+ - This function mutates `discussion_query` for pagination (start_* fields)
145
+ and may update `discussion_query["limit"]` and `before_date` as described.
146
+ - Pagination is driven by start markers (author/permlink/tag/parent_author)
147
+ and the function avoids yielding duplicate entries across pages.
148
+ - Raises ValueError if `discussion_type` is not one of the supported values.
149
+ """
150
+ if limit >= 100 and discussion_query["limit"] == 0:
151
+ discussion_query["limit"] = 100
152
+ elif limit < 100 and discussion_query["limit"] == 0:
153
+ discussion_query["limit"] = limit
154
+ query_count = 0
155
+ found_more_than_start_entry = True
156
+ if "start_author" in discussion_query:
157
+ start_author = discussion_query["start_author"]
158
+ else:
159
+ start_author = None
160
+ if "start_permlink" in discussion_query:
161
+ start_permlink = discussion_query["start_permlink"]
162
+ else:
163
+ start_permlink = None
164
+ if "start_tag" in discussion_query:
165
+ start_tag = discussion_query["start_tag"]
166
+ else:
167
+ start_tag = None
168
+ if "start_parent_author" in discussion_query:
169
+ start_parent_author = discussion_query["start_parent_author"]
170
+ else:
171
+ start_parent_author = None
172
+ if not discussion_query["before_date"]:
173
+ discussion_query["before_date"] = "1970-01-01T00:00:00"
174
+ while query_count < limit and found_more_than_start_entry:
175
+ rpc_query_count = 0
176
+ dd = None
177
+ discussion_query["start_author"] = start_author
178
+ discussion_query["start_permlink"] = start_permlink
179
+ discussion_query["start_tag"] = start_tag
180
+ discussion_query["start_parent_author"] = start_parent_author
181
+ if discussion_type == "trending":
182
+ dd = Discussions_by_trending(
183
+ discussion_query, blockchain_instance=self.blockchain, lazy=self.lazy
184
+ )
185
+ elif discussion_type == "author_before_date":
186
+ dd = Discussions_by_author_before_date(
187
+ author=discussion_query["author"],
188
+ start_permlink=discussion_query["start_permlink"],
189
+ before_date=discussion_query["before_date"],
190
+ limit=discussion_query["limit"],
191
+ blockchain_instance=self.blockchain,
192
+ lazy=self.lazy,
193
+ )
194
+ elif discussion_type == "payout":
195
+ dd = Comment_discussions_by_payout(
196
+ discussion_query,
197
+ blockchain_instance=self.blockchain,
198
+ lazy=self.lazy,
199
+ raw_data=raw_data,
200
+ )
201
+ elif discussion_type == "post_payout":
202
+ dd = Post_discussions_by_payout(
203
+ discussion_query,
204
+ blockchain_instance=self.blockchain,
205
+ lazy=self.lazy,
206
+ raw_data=raw_data,
207
+ )
208
+ elif discussion_type == "created":
209
+ dd = Discussions_by_created(
210
+ discussion_query,
211
+ blockchain_instance=self.blockchain,
212
+ lazy=self.lazy,
213
+ raw_data=raw_data,
214
+ )
215
+ elif discussion_type == "active":
216
+ dd = Discussions_by_active(
217
+ discussion_query,
218
+ blockchain_instance=self.blockchain,
219
+ lazy=self.lazy,
220
+ raw_data=raw_data,
221
+ )
222
+ elif discussion_type == "cashout":
223
+ dd = Discussions_by_cashout(
224
+ discussion_query,
225
+ blockchain_instance=self.blockchain,
226
+ lazy=self.lazy,
227
+ raw_data=raw_data,
228
+ )
229
+ elif discussion_type == "votes":
230
+ dd = Discussions_by_votes(
231
+ discussion_query,
232
+ blockchain_instance=self.blockchain,
233
+ lazy=self.lazy,
234
+ raw_data=raw_data,
235
+ )
236
+ elif discussion_type == "children":
237
+ dd = Discussions_by_children(
238
+ discussion_query,
239
+ blockchain_instance=self.blockchain,
240
+ lazy=self.lazy,
241
+ raw_data=raw_data,
242
+ )
243
+ elif discussion_type == "hot":
244
+ dd = Discussions_by_hot(
245
+ discussion_query,
246
+ blockchain_instance=self.blockchain,
247
+ lazy=self.lazy,
248
+ raw_data=raw_data,
249
+ )
250
+ elif discussion_type == "feed":
251
+ dd = Discussions_by_feed(
252
+ discussion_query,
253
+ blockchain_instance=self.blockchain,
254
+ lazy=self.lazy,
255
+ raw_data=raw_data,
256
+ )
257
+ elif discussion_type == "blog":
258
+ dd = Discussions_by_blog(
259
+ discussion_query,
260
+ blockchain_instance=self.blockchain,
261
+ lazy=self.lazy,
262
+ raw_data=raw_data,
263
+ )
264
+ elif discussion_type == "comments":
265
+ dd = Discussions_by_comments(
266
+ discussion_query,
267
+ blockchain_instance=self.blockchain,
268
+ lazy=self.lazy,
269
+ raw_data=raw_data,
270
+ )
271
+ elif discussion_type == "promoted":
272
+ dd = Discussions_by_promoted(
273
+ discussion_query,
274
+ blockchain_instance=self.blockchain,
275
+ lazy=self.lazy,
276
+ raw_data=raw_data,
277
+ )
278
+ elif discussion_type == "replies":
279
+ dd = Discussions_by_replies(
280
+ discussion_query,
281
+ blockchain_instance=self.blockchain,
282
+ lazy=self.lazy,
283
+ raw_data=raw_data,
284
+ )
285
+ elif discussion_type == "tags":
286
+ dd = Trending_tags(
287
+ discussion_query,
288
+ blockchain_instance=self.blockchain,
289
+ lazy=self.lazy,
290
+ )
291
+ else:
292
+ raise ValueError("Wrong discussion_type")
293
+ if not dd:
294
+ return
295
+
296
+ for d in dd:
297
+ double_result = False
298
+ if discussion_type == "tags":
299
+ if query_count != 0 and rpc_query_count == 0 and (d["name"] == start_tag):
300
+ double_result = True
301
+ if len(dd) == 1:
302
+ found_more_than_start_entry = False
303
+ start_tag = d["name"]
304
+ elif discussion_type == "replies":
305
+ if (
306
+ query_count != 0
307
+ and rpc_query_count == 0
308
+ and (d["author"] == start_parent_author and d["permlink"] == start_permlink)
309
+ ):
310
+ double_result = True
311
+ if len(dd) == 1:
312
+ found_more_than_start_entry = False
313
+ start_parent_author = d["author"]
314
+ start_permlink = d["permlink"]
315
+ else:
316
+ if (
317
+ query_count != 0
318
+ and rpc_query_count == 0
319
+ and (d["author"] == start_author and d["permlink"] == start_permlink)
320
+ ):
321
+ double_result = True
322
+ if len(dd) == 1:
323
+ found_more_than_start_entry = False
324
+ start_author = d["author"]
325
+ start_permlink = d["permlink"]
326
+ rpc_query_count += 1
327
+ if not double_result:
328
+ query_count += 1
329
+ if query_count <= limit:
330
+ yield d
331
+
332
+
333
+ class Discussions_by_trending(list):
334
+ """Get Discussions by trending
335
+
336
+ :param Query discussion_query: Defines the parameter for
337
+ searching posts
338
+ :param Hive blockchain_instance: Hive instance
339
+ :param bool raw_data: returns list of comments when False, default is False
340
+
341
+ .. testcode::
342
+
343
+ from nectar.discussions import Query, Discussions_by_trending
344
+ q = Query(limit=10, tag="hive")
345
+ for h in Discussions_by_trending(q):
346
+ print(h)
347
+
348
+ """
349
+
350
+ def __init__(
351
+ self,
352
+ discussion_query,
353
+ lazy=False,
354
+ raw_data=False,
355
+ blockchain_instance=None,
356
+ **kwargs,
357
+ ):
358
+ """
359
+ Initialize a Discussions_by_trending iterator that fetches trending discussions.
360
+ """
361
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
362
+ reduced_query = {}
363
+ for key in [
364
+ "tag",
365
+ "limit",
366
+ "filter_tags",
367
+ "select_authors",
368
+ "select_tags",
369
+ "truncate_body",
370
+ "start_author",
371
+ "start_permlink",
372
+ ]:
373
+ if key in discussion_query:
374
+ reduced_query[key] = discussion_query[key]
375
+
376
+ posts = []
377
+ # Try to use the bridge API first (preferred method)
378
+ bridge_query = {
379
+ "sort": "trending",
380
+ "tag": reduced_query.get("tag", ""),
381
+ "observer": reduced_query.get("observer", ""),
382
+ }
383
+ if "limit" in reduced_query:
384
+ bridge_query["limit"] = reduced_query["limit"]
385
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
386
+ bridge_query["start_author"] = reduced_query["start_author"]
387
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
388
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
389
+
390
+ if posts is None:
391
+ posts = []
392
+ if raw_data:
393
+ super().__init__([x for x in posts])
394
+ else:
395
+ super().__init__(
396
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
397
+ )
398
+
399
+
400
+ class Discussions_by_author_before_date(list):
401
+ """Get Discussions by author before date
402
+
403
+ .. note:: To retrieve discussions before date, the time of creation
404
+ of the discussion @author/start_permlink must be older than
405
+ the specified before_date parameter.
406
+
407
+ :param str author: Defines the author *(required)*
408
+ :param str start_permlink: Defines the permlink of a starting discussion
409
+ :param str before_date: Defines the before date for query
410
+ :param int limit: Defines the limit of discussions
411
+
412
+ :param bool raw_data: returns list of comments when False, default is False
413
+ :param Hive blockchain_instance: Hive instance
414
+
415
+ .. testcode::
416
+
417
+ from nectar.discussions import Query, Discussions_by_author_before_date
418
+ for h in Discussions_by_author_before_date(limit=10, author="gtg"):
419
+ print(h)
420
+
421
+ """
422
+
423
+ def __init__(
424
+ self,
425
+ author="",
426
+ start_permlink="",
427
+ before_date="1970-01-01T00:00:00",
428
+ limit=100,
429
+ lazy=False,
430
+ raw_data=False,
431
+ blockchain_instance=None,
432
+ **kwargs,
433
+ ):
434
+ """
435
+ Initialize a Discussions_by_author_before_date container of posts by a specific author before a given date.
436
+ """
437
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
438
+ posts = []
439
+ # Try to use the bridge API first (preferred method)
440
+ if author:
441
+ bridge_query = {
442
+ "sort": "posts",
443
+ "account": author,
444
+ "limit": limit,
445
+ }
446
+ if start_permlink:
447
+ bridge_query["start_permlink"] = start_permlink
448
+ posts = self.blockchain.rpc.get_account_posts(bridge_query)
449
+ # Filter by before_date if provided
450
+ if before_date and before_date != "1970-01-01T00:00:00":
451
+ filtered_posts = []
452
+ for post in posts:
453
+ if "created" in post and post["created"] < before_date:
454
+ filtered_posts.append(post)
455
+ posts = filtered_posts
456
+
457
+ if posts is None:
458
+ posts = []
459
+ if raw_data:
460
+ super().__init__([x for x in posts])
461
+ else:
462
+ super().__init__(
463
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
464
+ )
465
+
466
+
467
+ class Comment_discussions_by_payout(list):
468
+ """Get comment_discussions_by_payout
469
+
470
+ :param Query discussion_query: Defines the parameter for
471
+ searching posts
472
+
473
+ :param bool raw_data: returns list of comments when False, default is False
474
+ :param Hive blockchain_instance: Hive instance
475
+
476
+ .. testcode::
477
+
478
+ from nectar.discussions import Query, Comment_discussions_by_payout
479
+ q = Query(limit=10)
480
+ for h in Comment_discussions_by_payout(q):
481
+ print(h)
482
+
483
+ """
484
+
485
+ def __init__(
486
+ self,
487
+ discussion_query,
488
+ lazy=False,
489
+ raw_data=False,
490
+ blockchain_instance=None,
491
+ **kwargs,
492
+ ):
493
+ """
494
+ Initialize a Comment_discussions_by_payout iterator that fetches comment discussions sorted by payout.
495
+ """
496
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
497
+ reduced_query = {}
498
+ for key in [
499
+ "tag",
500
+ "limit",
501
+ "filter_tags",
502
+ "select_authors",
503
+ "select_tags",
504
+ "truncate_body",
505
+ "start_author",
506
+ "start_permlink",
507
+ ]:
508
+ if key in discussion_query:
509
+ reduced_query[key] = discussion_query[key]
510
+ posts = []
511
+
512
+ # Try to use the bridge API first (preferred method)
513
+ bridge_query = {
514
+ "sort": "payout_comments",
515
+ "tag": reduced_query.get("tag", ""),
516
+ "observer": reduced_query.get("observer", ""),
517
+ }
518
+ if "limit" in reduced_query:
519
+ bridge_query["limit"] = reduced_query["limit"]
520
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
521
+ bridge_query["start_author"] = reduced_query["start_author"]
522
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
523
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
524
+
525
+ if posts is None:
526
+ posts = []
527
+ if raw_data:
528
+ super().__init__([x for x in posts])
529
+ else:
530
+ super().__init__(
531
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
532
+ )
533
+
534
+
535
+ class Post_discussions_by_payout(list):
536
+ """Get post_discussions_by_payout
537
+
538
+ :param Query discussion_query: Defines the parameter for
539
+ searching posts
540
+
541
+ :param bool raw_data: returns list of comments when False, default is False
542
+ :param Hive blockchain_instance: Hive instance
543
+
544
+ .. testcode::
545
+
546
+ from nectar.discussions import Query, Post_discussions_by_payout
547
+ q = Query(limit=10)
548
+ for h in Post_discussions_by_payout(q):
549
+ print(h)
550
+
551
+ """
552
+
553
+ def __init__(
554
+ self,
555
+ discussion_query,
556
+ lazy=False,
557
+ raw_data=False,
558
+ blockchain_instance=None,
559
+ **kwargs,
560
+ ):
561
+ """
562
+ Initialize Post_discussions_by_payout: fetches post discussions sorted by payout and populates the list (raw dicts or Comment objects).
563
+ """
564
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
565
+ reduced_query = {}
566
+ for key in [
567
+ "tag",
568
+ "limit",
569
+ "filter_tags",
570
+ "select_authors",
571
+ "select_tags",
572
+ "truncate_body",
573
+ "start_author",
574
+ "start_permlink",
575
+ ]:
576
+ if key in discussion_query:
577
+ reduced_query[key] = discussion_query[key]
578
+ posts = []
579
+
580
+ # Try to use the bridge API first (preferred method)
581
+ bridge_query = {
582
+ "sort": "payout",
583
+ "tag": reduced_query.get("tag", ""),
584
+ "observer": "",
585
+ }
586
+ if "limit" in reduced_query:
587
+ bridge_query["limit"] = reduced_query["limit"]
588
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
589
+ bridge_query["start_author"] = reduced_query["start_author"]
590
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
591
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
592
+
593
+ if posts is None:
594
+ posts = []
595
+ if raw_data:
596
+ super().__init__([x for x in posts])
597
+ else:
598
+ super().__init__(
599
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
600
+ )
601
+
602
+
603
+ class Discussions_by_created(list):
604
+ """Get discussions_by_created
605
+
606
+ :param Query discussion_query: Defines the parameter for
607
+ searching posts
608
+
609
+ :param bool raw_data: returns list of comments when False, default is False
610
+ :param Hive blockchain_instance: Hive instance
611
+
612
+ .. testcode::
613
+
614
+ from nectar.discussions import Query, Discussions_by_created
615
+ q = Query(limit=10)
616
+ for h in Discussions_by_created(q):
617
+ print(h)
618
+
619
+ """
620
+
621
+ def __init__(
622
+ self,
623
+ discussion_query,
624
+ lazy=False,
625
+ raw_data=False,
626
+ blockchain_instance=None,
627
+ **kwargs,
628
+ ):
629
+ """
630
+ Initialize a Discussions_by_created fetcher and populate it with posts matching the query.
631
+ """
632
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
633
+ reduced_query = {}
634
+ for key in [
635
+ "tag",
636
+ "limit",
637
+ "filter_tags",
638
+ "select_authors",
639
+ "select_tags",
640
+ "truncate_body",
641
+ "start_author",
642
+ "start_permlink",
643
+ ]:
644
+ if key in discussion_query:
645
+ reduced_query[key] = discussion_query[key]
646
+ posts = []
647
+ # Try to use the bridge API first (preferred method)
648
+ bridge_query = {
649
+ "sort": "created",
650
+ "tag": reduced_query.get("tag", ""),
651
+ "observer": "",
652
+ }
653
+ if "limit" in reduced_query:
654
+ bridge_query["limit"] = reduced_query["limit"]
655
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
656
+ bridge_query["start_author"] = reduced_query["start_author"]
657
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
658
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
659
+
660
+ if posts is None:
661
+ posts = []
662
+ if raw_data:
663
+ super().__init__([x for x in posts])
664
+ else:
665
+ super().__init__(
666
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
667
+ )
668
+
669
+
670
+ class Discussions_by_active(list):
671
+ """get_discussions_by_active
672
+
673
+ :param Query discussion_query: Defines the parameter
674
+ searching posts
675
+
676
+ :param bool raw_data: returns list of comments when False, default is False
677
+ :param Hive blockchain_instance: Hive() instance to use when accesing a RPC
678
+
679
+ .. testcode::
680
+
681
+ from nectar.discussions import Query, Discussions_by_active
682
+ q = Query(limit=10)
683
+ for h in Discussions_by_active(q):
684
+ print(h)
685
+
686
+ """
687
+
688
+ def __init__(
689
+ self,
690
+ discussion_query,
691
+ lazy=False,
692
+ raw_data=False,
693
+ blockchain_instance=None,
694
+ **kwargs,
695
+ ):
696
+ """
697
+ Initialize Discussions_by_active: fetch discussions sorted by "active" and populate the sequence.
698
+ """
699
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
700
+ reduced_query = {}
701
+ for key in [
702
+ "tag",
703
+ "limit",
704
+ "filter_tags",
705
+ "select_authors",
706
+ "select_tags",
707
+ "truncate_body",
708
+ "start_author",
709
+ "start_permlink",
710
+ ]:
711
+ if key in discussion_query:
712
+ reduced_query[key] = discussion_query[key]
713
+ posts = []
714
+ # Try to use the bridge API first (preferred method)
715
+ bridge_query = {
716
+ "sort": "active",
717
+ "tag": reduced_query.get("tag", ""),
718
+ "observer": "",
719
+ }
720
+ if "limit" in reduced_query:
721
+ bridge_query["limit"] = reduced_query["limit"]
722
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
723
+ bridge_query["start_author"] = reduced_query["start_author"]
724
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
725
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
726
+
727
+ if posts is None:
728
+ posts = []
729
+ if raw_data:
730
+ super().__init__([x for x in posts])
731
+ else:
732
+ super().__init__(
733
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
734
+ )
735
+
736
+
737
+ class Discussions_by_cashout(list):
738
+ """Get discussions_by_cashout. This query seems to be broken at the moment.
739
+ The output is always empty.
740
+
741
+ :param Query discussion_query: Defines the parameter
742
+ searching posts
743
+
744
+ :param bool raw_data: returns list of comments when False, default is False
745
+ :param Hive blockchain_instance: Hive instance
746
+
747
+ .. testcode::
748
+
749
+ from nectar.discussions import Query, Discussions_by_cashout
750
+ q = Query(limit=10)
751
+ for h in Discussions_by_cashout(q):
752
+ print(h)
753
+
754
+ """
755
+
756
+ def __init__(
757
+ self,
758
+ discussion_query,
759
+ lazy=False,
760
+ raw_data=False,
761
+ blockchain_instance=None,
762
+ **kwargs,
763
+ ):
764
+ """
765
+ Initialize Discussions_by_cashout fetcher.
766
+ """
767
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
768
+ reduced_query = {}
769
+ for key in [
770
+ "tag",
771
+ "limit",
772
+ "filter_tags",
773
+ "select_authors",
774
+ "select_tags",
775
+ "truncate_body",
776
+ "start_author",
777
+ "start_permlink",
778
+ ]:
779
+ if key in discussion_query:
780
+ reduced_query[key] = discussion_query[key]
781
+ posts = []
782
+ # Try to use the bridge API first (preferred method)
783
+ # Note: 'payout' is the closest sort to 'cashout' in bridge API
784
+ bridge_query = {
785
+ "sort": "payout",
786
+ "tag": reduced_query.get("tag", ""),
787
+ "observer": "",
788
+ }
789
+ if "limit" in reduced_query:
790
+ bridge_query["limit"] = reduced_query["limit"]
791
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
792
+ bridge_query["start_author"] = reduced_query["start_author"]
793
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
794
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
795
+
796
+ if posts is None:
797
+ posts = []
798
+ if raw_data:
799
+ super().__init__([x for x in posts])
800
+ else:
801
+ super().__init__(
802
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
803
+ )
804
+
805
+
806
+ class Discussions_by_votes(list):
807
+ """Get discussions_by_votes
808
+
809
+ :param Query discussion_query: Defines the parameter
810
+ searching posts
811
+
812
+ :param bool raw_data: returns list of comments when False, default is False
813
+ :param Hive blockchain_instance: Hive instance
814
+
815
+ .. testcode::
816
+
817
+ from nectar.discussions import Query, Discussions_by_votes
818
+ q = Query(limit=10)
819
+ for h in Discussions_by_votes(q):
820
+ print(h)
821
+
822
+ """
823
+
824
+ def __init__(
825
+ self,
826
+ discussion_query,
827
+ lazy=False,
828
+ raw_data=False,
829
+ blockchain_instance=None,
830
+ **kwargs,
831
+ ):
832
+ """
833
+ Initialize Discussions_by_votes: fetch discussions approximating "votes" and store results.
834
+ """
835
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
836
+ reduced_query = {}
837
+ for key in [
838
+ "tag",
839
+ "limit",
840
+ "filter_tags",
841
+ "select_authors",
842
+ "select_tags",
843
+ "truncate_body",
844
+ "start_author",
845
+ "start_permlink",
846
+ ]:
847
+ if key in discussion_query:
848
+ reduced_query[key] = discussion_query[key]
849
+ posts = []
850
+ # Try to use the bridge API first (preferred method)
851
+ # Note: There is no direct 'votes' sort in bridge API, so we'll approximate using trending
852
+ bridge_query = {
853
+ "sort": "trending",
854
+ "tag": reduced_query.get("tag", ""),
855
+ "observer": "",
856
+ }
857
+ if "limit" in reduced_query:
858
+ bridge_query["limit"] = reduced_query["limit"]
859
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
860
+ bridge_query["start_author"] = reduced_query["start_author"]
861
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
862
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
863
+
864
+ if posts is None:
865
+ posts = []
866
+ if raw_data:
867
+ super().__init__([x for x in posts])
868
+ else:
869
+ super().__init__(
870
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
871
+ )
872
+
873
+
874
+ class Discussions_by_children(list):
875
+ """Get discussions by children
876
+
877
+ :param Query discussion_query: Defines the parameter
878
+ searching posts
879
+
880
+ :param bool raw_data: returns list of comments when False, default is False
881
+ :param Hive blockchain_instance: Hive instance
882
+
883
+ .. testcode::
884
+
885
+ from nectar.discussions import Query, Discussions_by_children
886
+ q = Query(limit=10)
887
+ for h in Discussions_by_children(q):
888
+ print(h)
889
+
890
+ """
891
+
892
+ def __init__(
893
+ self,
894
+ discussion_query,
895
+ lazy=False,
896
+ raw_data=False,
897
+ blockchain_instance=None,
898
+ **kwargs,
899
+ ):
900
+ """
901
+ Initialize a Discussions_by_children fetcher that yields child (reply) discussions for a tag/post.
902
+ """
903
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
904
+ reduced_query = {}
905
+ for key in [
906
+ "tag",
907
+ "limit",
908
+ "filter_tags",
909
+ "select_authors",
910
+ "select_tags",
911
+ "truncate_body",
912
+ "start_author",
913
+ "start_permlink",
914
+ ]:
915
+ if key in discussion_query:
916
+ reduced_query[key] = discussion_query[key]
917
+
918
+ posts = []
919
+ # Try to use the bridge API first (preferred method)
920
+ # Note: There is no direct 'children' sort in bridge API, we'll use 'trending' as a fallback
921
+ bridge_query = {
922
+ "sort": "trending",
923
+ "tag": reduced_query.get("tag", ""),
924
+ "observer": "",
925
+ }
926
+ if "limit" in reduced_query:
927
+ bridge_query["limit"] = reduced_query["limit"]
928
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
929
+ bridge_query["start_author"] = reduced_query["start_author"]
930
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
931
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
932
+ # We could try to sort posts by their children count here if needed
933
+
934
+ if posts is None:
935
+ posts = []
936
+ if raw_data:
937
+ super().__init__([x for x in posts])
938
+ else:
939
+ super().__init__(
940
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
941
+ )
942
+
943
+
944
+ class Discussions_by_hot(list):
945
+ """Get discussions by hot
946
+
947
+ :param Query discussion_query: Defines the parameter
948
+ searching posts
949
+
950
+ :param bool raw_data: returns list of comments when False, default is False
951
+ :param Hive blockchain_instance: Hive instance
952
+
953
+ .. testcode::
954
+
955
+ from nectar.discussions import Query, Discussions_by_hot
956
+ q = Query(limit=10, tag="hive")
957
+ for h in Discussions_by_hot(q):
958
+ print(h)
959
+
960
+ """
961
+
962
+ def __init__(
963
+ self,
964
+ discussion_query,
965
+ lazy=False,
966
+ raw_data=False,
967
+ blockchain_instance=None,
968
+ **kwargs,
969
+ ):
970
+ """
971
+ Initialize a Discussions_by_hot iterator that fetches "hot" discussions.
972
+ """
973
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
974
+ reduced_query = {}
975
+ for key in [
976
+ "tag",
977
+ "limit",
978
+ "filter_tags",
979
+ "select_authors",
980
+ "select_tags",
981
+ "truncate_body",
982
+ "start_author",
983
+ "start_permlink",
984
+ ]:
985
+ if key in discussion_query:
986
+ reduced_query[key] = discussion_query[key]
987
+ posts = []
988
+ # Try to use the bridge API first (preferred method)
989
+ bridge_query = {
990
+ "sort": "hot",
991
+ "tag": reduced_query.get("tag", ""),
992
+ "observer": "",
993
+ }
994
+ if "limit" in reduced_query:
995
+ bridge_query["limit"] = reduced_query["limit"]
996
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
997
+ bridge_query["start_author"] = reduced_query["start_author"]
998
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
999
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
1000
+
1001
+ if posts is None:
1002
+ posts = []
1003
+ if raw_data:
1004
+ super().__init__([x for x in posts])
1005
+ else:
1006
+ super().__init__(
1007
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1008
+ )
1009
+
1010
+
1011
+ class Discussions_by_feed(list):
1012
+ """Get discussions by feed
1013
+
1014
+ :param Query discussion_query: Defines the parameter
1015
+ searching posts, tag musst be set to a username
1016
+
1017
+ :param bool raw_data: returns list of comments when False, default is False
1018
+ :param Hive blockchain_instance: Hive instance
1019
+
1020
+ .. testcode::
1021
+
1022
+ from nectar.discussions import Query, Discussions_by_feed
1023
+ q = Query(limit=10, tag="hive")
1024
+ for h in Discussions_by_feed(q):
1025
+ print(h)
1026
+
1027
+ """
1028
+
1029
+ def __init__(
1030
+ self,
1031
+ discussion_query,
1032
+ lazy=False,
1033
+ raw_data=False,
1034
+ blockchain_instance=None,
1035
+ **kwargs,
1036
+ ):
1037
+ """
1038
+ Initialize a Discussions_by_feed instance that fetches a user's feed discussions.
1039
+ """
1040
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1041
+ reduced_query = {}
1042
+ for key in [
1043
+ "tag",
1044
+ "limit",
1045
+ "filter_tags",
1046
+ "select_authors",
1047
+ "select_tags",
1048
+ "truncate_body",
1049
+ "start_author",
1050
+ "start_permlink",
1051
+ ]:
1052
+ if key in discussion_query:
1053
+ reduced_query[key] = discussion_query[key]
1054
+ posts = []
1055
+ # Try to use the bridge API first (preferred method)
1056
+ account = reduced_query.get("tag", "")
1057
+ if account:
1058
+ bridge_query = {
1059
+ "sort": "feed",
1060
+ "account": account,
1061
+ "limit": reduced_query.get("limit", 20),
1062
+ }
1063
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1064
+ bridge_query["start_author"] = reduced_query["start_author"]
1065
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
1066
+ posts = self.blockchain.rpc.get_account_posts(bridge_query)
1067
+
1068
+ if posts is None:
1069
+ posts = []
1070
+ if raw_data:
1071
+ super().__init__([x for x in posts])
1072
+ else:
1073
+ super().__init__(
1074
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1075
+ )
1076
+
1077
+
1078
+ class Discussions_by_blog(list):
1079
+ """Get discussions by blog
1080
+
1081
+ :param Query discussion_query: Defines the parameter
1082
+ searching posts, tag musst be set to a username
1083
+
1084
+ :param bool raw_data: returns list of comments when False, default is False
1085
+ :param Hive blockchain_instance: Hive instance
1086
+
1087
+ .. testcode::
1088
+
1089
+ from nectar.discussions import Query, Discussions_by_blog
1090
+ q = Query(limit=10)
1091
+ for h in Discussions_by_blog(q):
1092
+ print(h)
1093
+
1094
+ """
1095
+
1096
+ def __init__(
1097
+ self,
1098
+ discussion_query,
1099
+ lazy=False,
1100
+ raw_data=False,
1101
+ blockchain_instance=None,
1102
+ **kwargs,
1103
+ ):
1104
+ """
1105
+ Initialize a Discussions_by_blog fetcher that retrieves a user's blog posts.
1106
+ """
1107
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1108
+ reduced_query = {}
1109
+ for key in [
1110
+ "tag",
1111
+ "limit",
1112
+ "filter_tags",
1113
+ "select_authors",
1114
+ "select_tags",
1115
+ "truncate_body",
1116
+ "start_author",
1117
+ "start_permlink",
1118
+ ]:
1119
+ if key in discussion_query:
1120
+ reduced_query[key] = discussion_query[key]
1121
+ posts = []
1122
+ # Try to use the bridge API first (preferred method)
1123
+ account = reduced_query.get("tag", "")
1124
+ if account:
1125
+ bridge_query = {
1126
+ "sort": "blog",
1127
+ "account": account,
1128
+ "limit": reduced_query.get("limit", 20),
1129
+ }
1130
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1131
+ bridge_query["start_author"] = reduced_query["start_author"]
1132
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
1133
+ posts = self.blockchain.rpc.get_account_posts(bridge_query)
1134
+
1135
+ if posts is None:
1136
+ posts = []
1137
+ if raw_data:
1138
+ super().__init__([x for x in posts])
1139
+ else:
1140
+ super().__init__(
1141
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1142
+ )
1143
+
1144
+
1145
+ class Discussions_by_comments(list):
1146
+ """Get discussions by comments
1147
+
1148
+ :param Query discussion_query: Defines the parameter
1149
+ searching posts, start_author and start_permlink must be set.
1150
+
1151
+ :param bool raw_data: returns list of comments when False, default is False
1152
+ :param Hive blockchain_instance: Hive instance
1153
+
1154
+ .. testcode::
1155
+
1156
+ from nectar.discussions import Query, Discussions_by_comments
1157
+ q = Query(limit=10, start_author="hiveio", start_permlink="firstpost")
1158
+ for h in Discussions_by_comments(q):
1159
+ print(h)
1160
+
1161
+ """
1162
+
1163
+ def __init__(
1164
+ self,
1165
+ discussion_query,
1166
+ lazy=False,
1167
+ raw_data=False,
1168
+ blockchain_instance=None,
1169
+ **kwargs,
1170
+ ):
1171
+ """
1172
+ Initialize Discussions_by_comments.
1173
+ """
1174
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1175
+ reduced_query = {}
1176
+ for key in ["start_author", "start_permlink", "limit"]:
1177
+ if key in discussion_query:
1178
+ reduced_query[key] = discussion_query[key]
1179
+ posts = []
1180
+ # Try to use the bridge API first (preferred method) when permlink is provided
1181
+ if (
1182
+ "start_author" in reduced_query
1183
+ and "start_permlink" in reduced_query
1184
+ and reduced_query["start_permlink"] is not None
1185
+ ):
1186
+ # The bridge.get_discussion API retrieves an entire discussion tree
1187
+ author = reduced_query["start_author"]
1188
+ permlink = reduced_query["start_permlink"]
1189
+ bridge_query = {
1190
+ "author": author,
1191
+ "permlink": permlink,
1192
+ }
1193
+ # The bridge API returns a discussion tree, we need to flatten it
1194
+ discussion = self.blockchain.rpc.get_discussion(bridge_query)
1195
+ # Extract comments from the discussion tree
1196
+ if discussion and isinstance(discussion, dict):
1197
+ posts = []
1198
+ # Start with the main post
1199
+ main_post = discussion.get(f"@{author}/{permlink}")
1200
+ if main_post:
1201
+ posts.append(main_post)
1202
+ # Add replies
1203
+ for key, value in discussion.items():
1204
+ if key != f"@{author}/{permlink}" and isinstance(value, dict):
1205
+ posts.append(value)
1206
+ # Limit the number of posts if needed
1207
+ if "limit" in reduced_query and len(posts) > reduced_query["limit"]:
1208
+ posts = posts[: reduced_query["limit"]]
1209
+ elif "start_author" in reduced_query:
1210
+ # When start_permlink is None, we cannot use bridge API as it requires a specific permlink
1211
+ # For now, return empty list since there's no direct API to get all comments by author
1212
+ # This is a limitation of the current API structure
1213
+ posts = []
1214
+
1215
+ if posts is None:
1216
+ posts = []
1217
+ if raw_data:
1218
+ super().__init__([x for x in posts])
1219
+ else:
1220
+ super().__init__(
1221
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1222
+ )
1223
+
1224
+
1225
+ class Discussions_by_promoted(list):
1226
+ """Get discussions by promoted
1227
+
1228
+ :param Query discussion_query: Defines the parameter
1229
+ searching posts
1230
+
1231
+ :param bool raw_data: returns list of comments when False, default is False
1232
+ :param Hive blockchain_instance: Hive instance
1233
+
1234
+ .. testcode::
1235
+
1236
+ from nectar.discussions import Query, Discussions_by_promoted
1237
+ q = Query(limit=10, tag="hive")
1238
+ for h in Discussions_by_promoted(q):
1239
+ print(h)
1240
+
1241
+ """
1242
+
1243
+ def __init__(
1244
+ self,
1245
+ discussion_query,
1246
+ lazy=False,
1247
+ raw_data=False,
1248
+ blockchain_instance=None,
1249
+ **kwargs,
1250
+ ):
1251
+ """
1252
+ Initialize Discussions_by_promoted.
1253
+ """
1254
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1255
+ reduced_query = {}
1256
+ for key in [
1257
+ "tag",
1258
+ "limit",
1259
+ "filter_tags",
1260
+ "select_authors",
1261
+ "select_tags",
1262
+ "truncate_body",
1263
+ "start_author",
1264
+ "start_permlink",
1265
+ ]:
1266
+ if key in discussion_query:
1267
+ reduced_query[key] = discussion_query[key]
1268
+ posts = []
1269
+ # Try to use the bridge API first (preferred method)
1270
+ bridge_query = {
1271
+ "sort": "promoted",
1272
+ "tag": reduced_query.get("tag", ""),
1273
+ "observer": "",
1274
+ }
1275
+ if "limit" in reduced_query:
1276
+ bridge_query["limit"] = reduced_query["limit"]
1277
+ if "start_author" in reduced_query and "start_permlink" in reduced_query:
1278
+ bridge_query["start_author"] = reduced_query["start_author"]
1279
+ bridge_query["start_permlink"] = reduced_query["start_permlink"]
1280
+ posts = self.blockchain.rpc.get_ranked_posts(bridge_query)
1281
+
1282
+ if posts is None:
1283
+ posts = []
1284
+ if raw_data:
1285
+ super().__init__([x for x in posts])
1286
+ else:
1287
+ super().__init__(
1288
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1289
+ )
1290
+
1291
+
1292
+ class Discussions_by_replies(list):
1293
+ """Get replies for an author's post
1294
+
1295
+ :param Query discussion_query: Defines the parameter
1296
+ searching posts, start_parent_author, start_permlink must be set.
1297
+
1298
+ :param bool raw_data: returns list of comments when False, default is False
1299
+ :param Hive blockchain_instance: Hive instance
1300
+
1301
+ .. testcode::
1302
+
1303
+ from nectar.discussions import Query, Discussions_by_replies
1304
+ q = Query(limit=10, start_parent_author="hiveio", start_permlink="firstpost")
1305
+ for h in Discussions_by_replies(q):
1306
+ print(h)
1307
+
1308
+ """
1309
+
1310
+ def __init__(
1311
+ self,
1312
+ discussion_query,
1313
+ lazy=False,
1314
+ raw_data=False,
1315
+ blockchain_instance=None,
1316
+ **kwargs,
1317
+ ):
1318
+ """
1319
+ Initialize Discussions_by_replies.
1320
+ """
1321
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1322
+ reduced_query = {}
1323
+ for key in ["start_parent_author", "start_permlink", "limit"]:
1324
+ if key in discussion_query:
1325
+ reduced_query[key] = discussion_query[key]
1326
+ posts = []
1327
+ author = reduced_query.get("start_parent_author")
1328
+ permlink = reduced_query.get("start_permlink")
1329
+
1330
+ # Try to use the bridge API first (preferred method)
1331
+ if author and permlink:
1332
+ bridge_query = {"author": author, "permlink": permlink}
1333
+ discussion = self.blockchain.rpc.get_discussion(bridge_query)
1334
+ if discussion and isinstance(discussion, dict):
1335
+ # Exclude the main post itself
1336
+ posts = [
1337
+ v
1338
+ for k, v in discussion.items()
1339
+ if k != f"@{author}/{permlink}" and isinstance(v, dict)
1340
+ ]
1341
+ if "limit" in reduced_query and len(posts) > reduced_query["limit"]:
1342
+ posts = posts[: reduced_query["limit"]]
1343
+
1344
+ if posts is None:
1345
+ posts = []
1346
+ if raw_data:
1347
+ super().__init__([x for x in posts])
1348
+ else:
1349
+ super().__init__(
1350
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1351
+ )
1352
+
1353
+
1354
+ class Replies_by_last_update(list):
1355
+ """Returns a list of replies by last update
1356
+
1357
+ :param Query discussion_query: Defines the parameter
1358
+ searching posts start_parent_author and start_permlink must be set.
1359
+
1360
+ :param bool raw_data: returns list of comments when False, default is False
1361
+ :param Hive blockchain_instance: Hive instance
1362
+
1363
+ .. testcode::
1364
+
1365
+ from nectar.discussions import Query, Replies_by_last_update
1366
+ q = Query(limit=10, start_parent_author="hiveio", start_permlink="firstpost")
1367
+ for h in Replies_by_last_update(q):
1368
+ print(h)
1369
+
1370
+ """
1371
+
1372
+ def __init__(
1373
+ self,
1374
+ discussion_query,
1375
+ lazy=False,
1376
+ raw_data=False,
1377
+ blockchain_instance=None,
1378
+ **kwargs,
1379
+ ):
1380
+ """
1381
+ Initialize a Replies_by_last_update iterator that loads replies to a specific post.
1382
+ """
1383
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1384
+ posts = []
1385
+ author = discussion_query.get("start_author")
1386
+ permlink = discussion_query.get("start_permlink")
1387
+ limit_value = discussion_query.get("limit", 100)
1388
+
1389
+ if author and permlink:
1390
+ try:
1391
+ posts = self.blockchain.rpc.get_replies_by_last_update(
1392
+ author,
1393
+ permlink,
1394
+ limit_value,
1395
+ )
1396
+ except Exception:
1397
+ posts = []
1398
+
1399
+ if posts is None:
1400
+ posts = []
1401
+ if raw_data:
1402
+ super().__init__([x for x in posts])
1403
+ else:
1404
+ super().__init__(
1405
+ [Comment(x, lazy=lazy, blockchain_instance=self.blockchain) for x in posts]
1406
+ )
1407
+
1408
+
1409
+ class Trending_tags(list):
1410
+ """Get trending tags
1411
+
1412
+ :param Query discussion_query: Defines the parameter
1413
+ searching posts, start_tag is used if set
1414
+ :param Hive blockchain_instance: Hive instance
1415
+
1416
+ .. testcode::
1417
+
1418
+ from nectar.discussions import Query, Trending_tags
1419
+ q = Query(limit=10)
1420
+ for h in Trending_tags(q):
1421
+ print(h)
1422
+
1423
+ """
1424
+
1425
+ def __init__(self, discussion_query, lazy=False, blockchain_instance=None, **kwargs):
1426
+ """
1427
+ Initialize a Trending_tags iterator by fetching trending tags from the blockchain RPC.
1428
+ """
1429
+ self.blockchain = blockchain_instance or shared_blockchain_instance()
1430
+ limit = discussion_query["limit"] if "limit" in discussion_query else 0
1431
+ tags = []
1432
+ try:
1433
+ tags = self.blockchain.rpc.get_trending_tags("", limit)
1434
+ except Exception:
1435
+ # If API fails, return empty list
1436
+ pass
1437
+ super().__init__(tags)