diff --git a/clients/nntp_client.py b/clients/nntp_client.py index bb8e51c..71b6fb7 100644 --- a/clients/nntp_client.py +++ b/clients/nntp_client.py @@ -8,6 +8,8 @@ import ssl import email.utils from collections import namedtuple +import os + class BBJNews(object): # this module isnt exactly complete. The below description claims # `all of its endpoints are mapped to native methods` though this @@ -74,22 +76,23 @@ class BBJNews(object): If you set this to False, anonymous network usage is guaranteed. """ + host = "news.tildeverse.org" self.host = host self.port = port self.tls = https - self.group = "tilde.team" + self.group = "local.test" self.user_name = None self.user_auth = None self.send_auth = True self.user = { "user_id": "", - "user_name": "", + "user_name": "anonymous", "is_admin": False, "color": 0, } self.instance_info = { - "instance_name": "", + "instance_name": "TEST nntp TEST", "allow_anon": True, "admins": [], } @@ -120,12 +123,11 @@ class BBJNews(object): def connect(self): - self.conn = nntplib.NNTP(self.host, self.port) + self.conn = nntplib.NNTP(self.host, self.port, usenetrc=False) if self.tls: context = ssl.create_default_context() self.conn.starttls(context) - # TODO: reconnect automatically @@ -147,6 +149,19 @@ class BBJNews(object): See raise_exception() for details on how this function reacts to various failure conditions. """ + + if endpoint == "get_me": + return {"error": False, "data": self.user.copy(), "usermap": {}} + + return { + "error": { + "code": 0, + "description": "unsupported endpoint", + }, + "data": None, + "usermap": {}, + } + headers = {"Content-Type": "application/json"} if params.get("no_auth"): params.pop("no_auth") @@ -222,8 +237,9 @@ class BBJNews(object): "admins": (list) // usernames of those who have admin rights on the server } """ - response = self("instance_info") - self.instance_info = response["data"] + # TODO + #response = self("instance_info") + #self.instance_info = response["data"] # unsupported @@ -321,14 +337,12 @@ class BBJNews(object): ) """ self.conn.login(user_name, user_auth, usernetrc=False) - - if check_validity and not self.validate_credentials(user_name, user_auth): - self.user_auth = self.user_name = None - raise ConnectionRefusedError("Auth and User do not match") + # TODO: catch self.user_auth = user_auth self.user_name = user_name - self.user = self("get_me")["data"] + #self.user = self("get_me")["data"] + self.user['user_name'] = user_name return True @@ -440,7 +454,7 @@ class BBJNews(object): self.user_name = params["user_name"] if params.get("auth_hash"): self.user_auth = params["auth_hash"] - self.user = dict(params) + self.user.update(**params) return self.user @@ -486,6 +500,8 @@ class BBJNews(object): # :lines - the number of lines in the body (deprecated) response, overviews = self.conn.over((first, None)) + with open("overview_cache.bbj.json", "wt") as f: + json.dump(overviews, f) if False: # build up a map of message references @@ -546,11 +562,14 @@ class BBJNews(object): print(usermap[author_id]["user_name"]) print(message["body"]) """ + return {}, {} + response = self("thread_load", format=format, thread_id=thread_id, op_only=op_only) return response["data"], response["usermap"] + # POST def thread_create(self, title, body): """ Submit a new thread, and return its new object. Requires the @@ -558,15 +577,20 @@ class BBJNews(object): 120 chars in length, else UserWarning is raised. Body must also not be empty. """ + raise NotImplementedError + response = self("thread_create", title=title, body=body) return response["data"] + # POST def thread_reply(self, thread_id, body): """ Submits a new reply to a thread and returns the new object. Requires the thread's id and a non-empty body string. """ + raise NotImplementedError + response = self("thread_reply", thread_id=thread_id, body=body) return response["data"] diff --git a/clients/urwid/main.py b/clients/urwid/main.py index 6bcb99e..7da00db 100644 --- a/clients/urwid/main.py +++ b/clients/urwid/main.py @@ -20,7 +20,10 @@ Please mail me (~desvox) for feedback and for any of your "OH MY GOD WHY WOULD YOU DO THIS"'s or "PEP8 IS A THING"'s. """ -from network import BBJ, URLError +import sys, os; sys.path.append(os.path.dirname(os.path.dirname(__file__))) + +#from network import BBJ, URLError +from nntp_client import BBJNews as BBJ, URLError from string import punctuation from datetime import datetime from sys import argv, version @@ -2599,9 +2602,10 @@ def main(): exit() try: - network = BBJ(get_arg("host", "127.0.0.1"), - get_arg("port", 7099), - get_arg("https", False, False)) + #network = BBJ(get_arg("host", "127.0.0.1"), + # get_arg("port", 7099), + # get_arg("https", False, False)) + network = BBJ(https=get_arg("https", False, False)) except URLError as e: # print the connection error in red exit("\033[0;31m%s\033[0m" % repr(e))