Browse code

Pylint boobank-history.

Xavier G authored on 10/11/2017 18:52:31
Showing 1 changed files

... ...
@@ -1,22 +1,32 @@
1 1
 #!/usr/bin/env python
2 2
 # -*- coding: utf-8 -*-
3
+"""
4
+boobank-history takes a JSON file, as created by boobank-cacher when running
5
+and caching a "boobank history" command, and display its contents.
6
+"""
3 7
 
4
-import os
5
-import sys
6
-import json
7 8
 import time
8 9
 import argparse
9 10
 from prettytable import PrettyTable
10 11
 from termcolor import colored
11
-from boobank_utils import *
12
+from boobank_utils import format_amount, load_json, format_timestamp_colored
13
+from boobank_utils import MAX_AGE, DEFAULT_CURRENCY, COLORING_SIMPLE
12 14
 
13 15
 def parse_args():
14
-    args_parser = argparse.ArgumentParser(description='Display the contents of a cached "boobank history" JSON file.')
16
+    """
17
+    Parse command-line arguments.
18
+    """
19
+    description = 'Display the contents of a cached "boobank history" JSON file.'
20
+    args_parser = argparse.ArgumentParser(description=description)
15 21
     args_parser.add_argument('json_file', nargs='?', default='-', help='JSON file to display')
16
-    args_parser.add_argument('-c', '--count', default=None, type=int, help='Maximum number of operations to display.')
22
+    args_parser.add_argument('-c', '--count', default=None, type=int,
23
+                             help='Maximum number of operations to display.')
17 24
     return args_parser.parse_args()
18 25
 
19 26
 def main():
27
+    """
28
+    Main function.
29
+    """
20 30
     args = parse_args()
21 31
     filepath = args.json_file
22 32
     max_operations = args.count
... ...
@@ -32,17 +42,23 @@ def main():
32 42
     print(table)
33 43
 
34 44
 def get_table(timestamp):
35
-    pt = PrettyTable()
45
+    """
46
+    Create and return the PrettyTable instance used to display data.
47
+    """
48
+    ptable = PrettyTable()
36 49
     field_names = ['Date', 'Label', 'Amount']
37 50
     field_names = [colored(x, 'white', attrs=['bold']) for x in field_names]
38 51
     timestamp = format_timestamp_colored(timestamp, MAX_AGE)
39 52
     field_names[1] += ' -- data cached on %s' % timestamp
40
-    pt.field_names = field_names
41
-    pt.align = 'l'
42
-    pt.align[pt.field_names[2]] = 'r'
43
-    return pt
53
+    ptable.field_names = field_names
54
+    ptable.align = 'l'
55
+    ptable.align[ptable.field_names[2]] = 'r'
56
+    return ptable
44 57
 
45 58
 def add_operation(table, operation):
59
+    """
60
+    Add the given bank operation to the given PrettyTable instance.
61
+    """
46 62
     date = colored(operation.get('date'), 'cyan')
47 63
     label = colored(operation.get('label')[:80], 'cyan')
48 64
     currency = operation.get('currency', DEFAULT_CURRENCY)