# that we can look up the text of one to show in a 'Re:' header
self.status_cache = {}
+ self.readonly = False
+
def set_instance_url(self, instance_url):
self.instance_url = instance_url
self.urls = {
self.log_response = log_response
+ def set_readonly(self):
+ self.readonly = True
+
def method_start(self, method, path, base, params, stream, links={}):
headers = {}
if self.bearer_token is not None:
def get(self, path, base='api', **params):
return self.method(requests.get, path, base, params)
def post(self, path, base='api', **params):
+ assert not self.readonly, "HTTP POST got through in readonly mode"
return self.method(requests.post, path, base, params)
def get_incremental(self, path, base='api', **params):
target = self.statuses[self.select_target]
reply_id = target.get_reply_id()
verb = "favourite" if direction > 0 else "unfavourite"
+ if self.cc.readonly:
+ print(verb, reply_id, file=sys.stderr)
+ return
data = self.cc.post(f"statuses/{reply_id}/{verb}")
target.update_fave_boost(data)
target = self.statuses[self.select_target]
reply_id = target.get_reply_id()
verb = "reblog" if direction > 0 else "unreblog"
+ if self.cc.readonly:
+ print(verb, reply_id, file=sys.stderr)
+ return
data = self.cc.post(f"statuses/{reply_id}/{verb}")
target.update_fave_boost(data)
}
if self.reply_id is not None:
params["in_reply_to_id"] = self.reply_id
+ if self.cc.readonly:
+ print("post", file=sys.stderr)
+ for key, value in params.items():
+ print(f" {key}: {value!r}", file=sys.stderr)
+ return
self.cc.post("statuses", **params)
class testComposerLayout(unittest.TestCase):
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("--readonly", action="store_true",
+ help="Disable write operations (posting, favouriting "
+ "etc), and just log on stderr what would have been "
+ "done.")
parser.add_argument("--combined", action="store_const", dest="action",
const=CombinedUI, help="Temporary mode to fetch "
"the user's timeline and mentions, interleave them, "
login.setup_client(client)
if args.log is not None:
client.enable_debug(args.log)
+ if args.readonly:
+ client.set_readonly()
client.run()
if __name__ == '__main__':