self.log_response = lambda *args, **kws: None
def set_instance(self, instance):
+ self.instance = instance
self.urls = {
- 'auth': instance + "/oauth/",
- 'api': instance + "/api/v1/",
+ 'auth': "https://" + instance + "/oauth/",
+ 'api': "https://" + instance + "/api/v1/",
}
+ def set_username(self, username, account_id):
+ self.username = username
+ self.fq_username = f"{self.username}@{self.instance}"
+ self.at_fq_username = f"@{self.username}@{self.instance}"
+ self.account_id = account_id
+
def enable_debug(self, logfile):
self.logfh = open(logfile, "w")
pr = lambda *args, **kws: print(*args, file=self.logfh, **kws)
json.dump(data, fh, indent=4)
finally:
os.umask(old_umask)
+
+def setup_client(cl):
+ if isinstance(cl, LoginUI):
+ return # that would be silly
+
+ with open(config_file()) as fh:
+ data = json.load(fh)
+ cl.set_instance(data['instance'])
+ cl.set_username(data['username'], data['account_id'])
+ cl.bearer_token = data['user_token']
import cursesclient
import login
-class PublicTimelineUI(client.Client):
+class TimelineUI(client.Client):
def run(self):
- self.set_instance("https://hachyderm.io") # FIXME
- for item in self.get("timelines/public", limit=10):
+ login.setup_client(self)
+ for item in reversed(self.get("timelines/home", limit=20)):
p = client.Status(item)
for thing in p.text():
for line in thing.render(80):
parser.add_argument("--log", help="File to log debug information to.")
parser.add_argument("--test", nargs=argparse.REMAINDER,
help="Run unit tests.")
- parser.add_argument("--public", action="store_const", dest="action",
- const=PublicTimelineUI, help="Temporary mode to fetch "
- "a public timeline and print it on the terminal.")
+ parser.add_argument("--timeline", action="store_const", dest="action",
+ const=TimelineUI, help="Temporary mode to fetch "
+ "the user's timeline and print it on the terminal.")
parser.add_argument("--login", action="store_const", dest="action",
const=login.LoginUI, help="Log in to a user account.")
parser.set_defaults(action=cursesclient.CursesUI)
return unittest.main(argv=[sys.argv[0]] + args.test,
testLoader=MyTestLoader())
- thing = args.action()
+ client = args.action()
+ login.setup_client(client)
if args.log is not None:
- thing.enable_debug(args.log)
- thing.run()
+ client.enable_debug(args.log)
+ client.run()
if __name__ == '__main__':
main()