|
@@ -12,6 +12,10 @@ except ImportError:
|
|
|
return text
|
|
|
|
|
|
|
|
|
+def is_group_subscribed(mSubscribeFlags):
|
|
|
+ return bool(mSubscribeFlags & 4)
|
|
|
+
|
|
|
+
|
|
|
def req(args, location, data=None):
|
|
|
kwargs = {}
|
|
|
if data is not None:
|
|
@@ -23,12 +27,58 @@ def req(args, location, data=None):
|
|
|
return r
|
|
|
|
|
|
|
|
|
+def main_forum_list(args):
|
|
|
+ r = req(args, "/rsGxsForums/getForumsSummaries")
|
|
|
+ forums = r.json()["forums"]
|
|
|
+ for item in forums:
|
|
|
+ if is_group_subscribed(item["mSubscribeFlags"]):
|
|
|
+ if "notsubscribed" in args.select:
|
|
|
+ continue
|
|
|
+ style = "bold"
|
|
|
+ else:
|
|
|
+ if "subscribed" in args.select:
|
|
|
+ continue
|
|
|
+ style = None
|
|
|
+ print(color(item["mGroupName"], style=style, fg="green"))
|
|
|
+ print(" " + color(item["mGroupId"], style="underline"))
|
|
|
+
|
|
|
+def main_forum_read(args):
|
|
|
+ r = req(args, "/rsGxsForums/getForumMsgMetaData", {"forumId": args.forum_id})
|
|
|
+ items = r.json()["msgMetas"]
|
|
|
+ if args.long:
|
|
|
+ msgs = [item["mMsgId"] for item in items[: args.num_posts]]
|
|
|
+ items_r = req(
|
|
|
+ args,
|
|
|
+ "/rsGxsForums/getForumContent",
|
|
|
+ {"forumId": args.forum_id, "msgsIds": msgs},
|
|
|
+ )
|
|
|
+ pprint(items_r.json())
|
|
|
+ items = items_r.json()["msgs"]
|
|
|
+ for item in items:
|
|
|
+ print(color(item["mMeta"]["mMsgName"], style="bold", fg="green"))
|
|
|
+ print()
|
|
|
+ print(color(item["mMsg"])) # TODO: html2txt
|
|
|
+ print()
|
|
|
+ else:
|
|
|
+ for item in posts[: args.num_posts]:
|
|
|
+ print(color(item["mMsgName"], style="bold", fg="green"))
|
|
|
+ print(" " + color(item["mMsgId"], style="underline"))
|
|
|
+
|
|
|
+
|
|
|
def main_channel_list(args):
|
|
|
r = req(args, "/rsGxsChannels/getChannelsSummaries")
|
|
|
channels = r.json()["channels"]
|
|
|
- for chan in channels:
|
|
|
- print(color(chan["mGroupName"], style="bold", fg="green"))
|
|
|
- print(" " + color(chan["mGroupId"], style="underline"))
|
|
|
+ for item in channels:
|
|
|
+ if is_group_subscribed(item["mSubscribeFlags"]):
|
|
|
+ if "notsubscribed" in args.select:
|
|
|
+ continue
|
|
|
+ style = "bold"
|
|
|
+ else:
|
|
|
+ if "subscribed" in args.select:
|
|
|
+ continue
|
|
|
+ style = None
|
|
|
+ print(color(item["mGroupName"], style=style, fg="green"))
|
|
|
+ print(" " + color(item["mGroupId"], style="underline"))
|
|
|
|
|
|
|
|
|
def main_channel_read(args):
|
|
@@ -48,7 +98,7 @@ def main_channel_read(args):
|
|
|
print(color(post["mMsg"]))
|
|
|
print()
|
|
|
else:
|
|
|
- for post in posts[:args.num_posts]:
|
|
|
+ for post in posts[: args.num_posts]:
|
|
|
print(color(post["mMsgName"], style="bold", fg="green"))
|
|
|
print(" " + color(post["mMsgId"], style="underline"))
|
|
|
|
|
@@ -122,6 +172,12 @@ def get_parser():
|
|
|
ch.add_argument("--channel-id")
|
|
|
ch_sub = ch.add_subparsers()
|
|
|
ch_list = ch_sub.add_parser("list")
|
|
|
+ ch_list.add_argument(
|
|
|
+ "--select",
|
|
|
+ nargs="+",
|
|
|
+ choices=["all", "subscribed", "notsubscribed"],
|
|
|
+ default=["all"],
|
|
|
+ )
|
|
|
ch_list.set_defaults(mainfunc=main_channel_list)
|
|
|
|
|
|
ch_show = ch_sub.add_parser("show")
|
|
@@ -137,6 +193,26 @@ def get_parser():
|
|
|
ch_post.add_argument("--post-title")
|
|
|
ch_post.add_argument("--post-body")
|
|
|
|
|
|
+ forum = p_sub.add_parser("forum")
|
|
|
+ forum.add_argument("--forum-id")
|
|
|
+ forum_sub = forum.add_subparsers()
|
|
|
+ forum_list = forum_sub.add_parser("list")
|
|
|
+ forum_list.add_argument(
|
|
|
+ "--select",
|
|
|
+ nargs="+",
|
|
|
+ choices=["all", "subscribed", "notsubscribed"],
|
|
|
+ default=["all"],
|
|
|
+ )
|
|
|
+ forum_list.set_defaults(mainfunc=main_forum_list)
|
|
|
+
|
|
|
+ forum_read = forum_sub.add_parser("read")
|
|
|
+ forum_read.add_argument("--long", action="store_true", default=False)
|
|
|
+ forum_read.add_argument("--num-posts", type=int, default=10)
|
|
|
+ forum_read.set_defaults(mainfunc=main_forum_read)
|
|
|
+
|
|
|
+
|
|
|
+ # TODO: channel rss -> read and convert to rss
|
|
|
+
|
|
|
return p
|
|
|
|
|
|
|