|
44 | 44 | from textwrap import indent |
45 | 45 |
|
46 | 46 |
|
47 | | -class ColorFallback(): |
48 | | - __getattr__ = lambda self, name: '' # noqa: E731 |
| 47 | +class ColorFallback: |
| 48 | + __getattr__ = lambda self, name: "" # noqa: E731 |
49 | 49 |
|
50 | 50 |
|
51 | 51 | try: |
52 | 52 | from colorama import Fore, Style, init |
| 53 | + |
53 | 54 | init() # needed for Windows |
54 | 55 | except ImportError: # fallback so that the imported classes always exist |
55 | 56 | Fore = Style = ColorFallback() |
56 | 57 |
|
57 | 58 |
|
58 | | -Comment = namedtuple('Comment', ('uri', 'id', 'parent', 'created', 'text', 'author', 'email', 'website', 'likes', 'dislikes', 'replies')) |
| 59 | +Comment = namedtuple( |
| 60 | + "Comment", ("uri", "id", "parent", "created", "text", "author", "email", "website", "likes", "dislikes", "replies") |
| 61 | +) |
59 | 62 |
|
60 | | -INDENT = ' ' |
61 | | -QUERY = 'SELECT uri, comments.id, parent, created, text, author, email, website, likes, dislikes FROM comments INNER JOIN threads on comments.tid = threads.id' |
| 63 | +INDENT = " " |
| 64 | +QUERY = "SELECT uri, comments.id, parent, created, text, author, email, website, likes, dislikes FROM comments INNER JOIN threads on comments.tid = threads.id" |
62 | 65 |
|
63 | 66 |
|
64 | 67 | def main(): |
@@ -95,34 +98,44 @@ def main(): |
95 | 98 |
|
96 | 99 |
|
97 | 100 | def print_comment(prefix, comment): |
98 | | - author = comment.author or 'Anonymous' |
99 | | - email = comment.email or '' |
100 | | - website = comment.website or '' |
| 101 | + author = comment.author or "Anonymous" |
| 102 | + email = comment.email or "" |
| 103 | + website = comment.website or "" |
101 | 104 | when = date.fromtimestamp(comment.created) |
102 | | - popularity = '' |
| 105 | + popularity = "" |
103 | 106 | if comment.likes: |
104 | | - popularity = '+{.likes}'.format(comment) |
| 107 | + popularity = "+{.likes}".format(comment) |
105 | 108 | if comment.dislikes: |
106 | 109 | if popularity: |
107 | | - popularity += '/' |
108 | | - popularity = '-{.dislikes}'.format(comment) |
109 | | - print(prefix + '{Style.BRIGHT}{author}{Style.RESET_ALL} {Style.DIM}- {email} {website}{Style.RESET_ALL} {when} {Style.DIM}{popularity}{Style.RESET_ALL}'.format(Style=Style, **locals())) |
| 110 | + popularity += "/" |
| 111 | + popularity = "-{.dislikes}".format(comment) |
| 112 | + print( |
| 113 | + prefix |
| 114 | + + "{Style.BRIGHT}{author}{Style.RESET_ALL} {Style.DIM}- {email} {website}{Style.RESET_ALL} {when} {Style.DIM}{popularity}{Style.RESET_ALL}".format( |
| 115 | + Style=Style, **locals() |
| 116 | + ) |
| 117 | + ) |
110 | 118 | print(indent(comment.text, prefix)) |
111 | 119 |
|
112 | 120 |
|
113 | 121 | def parse_args(): |
114 | | - parser = argparse.ArgumentParser(description='Dump all Isso comments in chronological order, grouped by replies', |
115 | | - formatter_class=ArgparseHelpFormatter) |
116 | | - parser.add_argument('db_path', help='File path to Isso Sqlite DB') |
117 | | - parser.add_argument('--sort-by-last-reply', action='store_true', help='By default comments are sorted by "parent" comment date, this sort comments based on the last replies') |
118 | | - parser.add_argument('--url-prefix', default='', help='Optional domain name to prefix to pages URLs') |
119 | | - parser.add_argument('--no-colors', action='store_false', dest='colors', default=True, help='Disabled colored output') |
| 122 | + parser = argparse.ArgumentParser( |
| 123 | + description="Dump all Isso comments in chronological order, grouped by replies", formatter_class=ArgparseHelpFormatter |
| 124 | + ) |
| 125 | + parser.add_argument("db_path", help="File path to Isso Sqlite DB") |
| 126 | + parser.add_argument( |
| 127 | + "--sort-by-last-reply", |
| 128 | + action="store_true", |
| 129 | + help='By default comments are sorted by "parent" comment date, this sort comments based on the last replies', |
| 130 | + ) |
| 131 | + parser.add_argument("--url-prefix", default="", help="Optional domain name to prefix to pages URLs") |
| 132 | + parser.add_argument("--no-colors", action="store_false", dest="colors", default=True, help="Disabled colored output") |
120 | 133 | return parser.parse_args() |
121 | 134 |
|
122 | 135 |
|
123 | 136 | class ArgparseHelpFormatter(argparse.RawTextHelpFormatter, argparse.ArgumentDefaultsHelpFormatter): |
124 | 137 | pass |
125 | 138 |
|
126 | 139 |
|
127 | | -if __name__ == '__main__': |
| 140 | +if __name__ == "__main__": |
128 | 141 | main() |
0 commit comments