<commit_before>from dogapi.v1 import CommentService

from dogshell.common import report_errors, report_warnings, CommandLineClient

class CommentClient(CommandLineClient):

    def __init__(self, config):
        self.config = config

    def setup_parser(self, subparsers):
        parser = subparsers.add_parser('comment', help='post comments')
        parser.add_argument('handle', help='handle to post as')
        parser.add_argument('comment', help='comment to post')
        parser.set_defaults(r_func=self.r_comment)
        parser.set_defaults(p_func=self.p_comment)
        parser.set_defaults(l_func=self.p_comment)

    def _comment(self, handle, comment):
        svc = CommentService(self.config['apikey'], self.config['appkey'])
        return svc.post(handle, comment)

    def r_comment(self, args):
        res = self._comment(args.handle, args.comment)
        report_warnings(res)
        if report_errors(res):
            return
        print res

    def p_comment(self, args):
        res = self._comment(args.handle, args.comment)
        report_warnings(res)
        if report_errors(res):
            return
        print 'id\t\t' + str(res['comment']['id'])
        print 'url\t\t' + res['comment']['url']
        print 'resource\t' + res['comment']['resource']
        print 'handle\t\t' + res['comment']['handle']
        print 'message\t\t' + res['comment']['message']
<commit_msg>read comments from stdin and make handle optional (implicit)<commit_after>import sys

from dogapi.v1 import CommentService

from dogshell.common import report_errors, report_warnings, CommandLineClient

class CommentClient(CommandLineClient):

    def __init__(self, config):
        self.config = config

    def setup_parser(self, subparsers):
        parser = subparsers.add_parser('comment', help='post comments')
        parser.add_argument('--handle', help='handle to post as. if unset, posts as the owner of the application key used to authenticate')
        parser.add_argument('comment', help='comment to post. if unset, reads from stdin.', nargs="?")
        parser.set_defaults(r_func=self.r_comment)
        parser.set_defaults(p_func=self.p_comment)
        parser.set_defaults(l_func=self.l_comment)

    def _comment(self, handle, comment):
        if comment is None:
            comment = sys.stdin.read()
        svc = CommentService(self.config['apikey'], self.config['appkey'])
        return svc.post(handle, comment)

    def r_comment(self, args):
        res = self._comment(args.handle, args.comment)
        report_warnings(res)
        if report_errors(res):
            return
        print res

    def p_comment(self, args):
        res = self._comment(args.handle, args.comment)
        report_warnings(res)
        if report_errors(res):
            return
        message = res['comment']['message']
        lines = message.split('\n')
        message = '\n'.join(['    ' + line for line in lines])
        print 'id\t\t' + str(res['comment']['id'])
        print 'url\t\t' + res['comment']['url']
        print 'resource\t' + res['comment']['resource']
        print 'handle\t\t' + res['comment']['handle']
        print 'message\n' + message

    def l_comment(self, args):
        res = self._comment(args.handle, args.comment)
        report_warnings(res)
        if report_errors(res):
            return
        print 'id\t\t' + str(res['comment']['id'])
        print 'url\t\t' + res['comment']['url']
        print 'resource\t' + res['comment']['resource']
        print 'handle\t\t' + res['comment']['handle']
        print 'message\t\t' + res['comment']['message'].__repr__()

{'fraction_non_alphanumeric': 0.1354998622968879, 'fraction_numerical': 0.000550812448361333, 'mean_word_length': 2.9478260869565216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5796407', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1065, 'n_words': 237}