GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 598b8e...6df1c2 )
by Andrew
01:03
created

main()   F

Complexity

Conditions 12

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 1 Features 2
Metric Value
cc 12
c 7
b 1
f 2
dl 0
loc 60
rs 3.0169

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like main() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
"""A sample CLI with API interaction."""
2
3
import logging
4
5
import click
0 ignored issues
show
introduced by
Unable to import 'click'
Loading history...
Unused Code introduced by
The import click seems to be unused.
Loading history...
6
7
from getpass import getpass
0 ignored issues
show
Unused Code introduced by
Unused getpass imported from getpass
Loading history...
introduced by
standard import "from getpass import getpass" should be placed before "import click"
Loading history...
8
import argparse, sys
0 ignored issues
show
introduced by
Multiple imports on one line (argparse, sys)
Loading history...
Unused Code introduced by
The import sys seems to be unused.
Loading history...
introduced by
standard import "import argparse, sys" should be placed before "import click"
Loading history...
9
from jsonjuggler import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like jsonjuggler should generally be avoided.
Loading history...
Unused Code introduced by
DictJugglerTaskDepends was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DictJugglerTaskAllocate was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DictJugglerTask was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JsonJuggler was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
json was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DictJugglerTaskEffort was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
math was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTaskStart was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OrderedDict was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
from_identifier was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
to_tj3time was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTaskEffort was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerResource was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTask was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerSource was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DictJugglerTaskPriority was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
subprocess was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerProject was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerOutputdir was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DEFAULT_OUTPUT was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTimesheet was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
TJP_DASH_PREFIX was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
dateutil was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTaskAllocate was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTaskProperty was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
icalendar was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
tempfile was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerCompoundKeyword was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
is_number was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
os was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTaskPriority was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTaskDepends was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
TJP_SPACE_PREFIX was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
TAB was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
shutil was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
TJP_NUM_ID_PREFIX was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerBooking was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
datetime was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerIcalreport was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerTimezone was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
to_tj3interval was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DictJugglerTaskStart was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JugglerSimpleProperty was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
GenericJuggler was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
to_identifier was imported with wildcard, but is not used.
Loading history...
10
import juggler
11
12
from airtable import Airtable
0 ignored issues
show
introduced by
Unable to import 'airtable'
Loading history...
13
14
DEFAULT_LOGLEVEL = 'warning'
15
DEFAULT_OUTPUT = 'export.tjp'
16
log = logging.getLogger(__name__)
17
18
19
# @click.argument('')
20
# @click.command()
21
def main():
22
    logging.basicConfig(level=logging.INFO)
23
24
    ARGPARSER = argparse.ArgumentParser()
25
    ARGPARSER.add_argument('-l', '--loglevel', dest='loglevel', default=DEFAULT_LOGLEVEL,
26
                          action='store', required=False,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
27
                          help='Level for logging (strings from logging python package: "warning", "info", "debug")')
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (117/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
28
    ARGPARSER.add_argument('-a', '--api', dest='api', default=None,
29
                          action='store', required=True, choices=['airtable'],
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
30
                          help='Execute specified API: only "airtable" is currently supported')
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
31
    ARGPARSER.add_argument('-k', '--api-key', dest='apikey', default="",
32
                          action='store', required=True,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
33
                          help='Specify API key where appropriate (e.g. -k keyAnIuYcufa3dD)')
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
34
    ARGPARSER.add_argument('-b', '--base', dest='base', default="",
35
                          action='store', required=True,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
36
                          help='Specify Base ID where appropriate (e.g. -b appA8ZuLosBV4GDSd)')
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
37
    ARGPARSER.add_argument('-t', '--table', dest='table', default="",
38
                          action='store', required=True,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
39
                          help='Specify Table ID where appropriate (e.g. -t Tasks)')
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
40
    ARGPARSER.add_argument('-v', '--view', dest='view', default="",
41
                          action='store', required=True,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
42
                          help='Specify Table View where appropriate (e.g. -v Work)')
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 1 space).
Loading history...
43
    # ARGPARSER.add_argument('-o', '--output', dest='output', default=DEFAULT_OUTPUT,
44
    #                       action='store', required=False,
45
    #                       help='Output .tjp file for task-juggler')
46
    ARGS = ARGPARSER.parse_args()
47
48
    set_logging_level(ARGS.loglevel)
49
50
    # PASSWORD = getpass('Enter generic password for {user}: '.format(user=ARGS.username))
51
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
52
    airtable = Airtable(ARGS.base, ARGS.table, api_key=ARGS.apikey)
53
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
54
    data = [x["fields"] for x in airtable.get_all(view=ARGS.view)] 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
55
    for rec in data:
56
        preference = 0
57
        if "preference" in rec:
58
            preference = int(rec['preference'])
59
        if "priority" in rec:
60
            if rec["priority"] == "Low":
61
                pri = preference + 100
62
            elif rec["priority"] == "High":
63
                pri = preference + 200
64
            elif rec["priority"] == "CRITICAL":
65
                pri = preference + 300
66
            else:
67
                pri = 1
68
        else:
69
            pri = preference + 100 # low
70
        rec["priority"] = pri
71
        if 'appointment' in rec:
72
            rec['start'] = rec['appointment']
73
        if 'depends' in rec:
74
            rec['depends'] = [int(x) for x in re.findall(r"[\w']+", rec["depends"])]
75
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
76
    JUGGLER = DictJuggler(data)
77
    JUGGLER.run()
78
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
79
    for t in JUGGLER.walk(juggler.JugglerTask):
80
        airtable.update_by_field("id", t.get_id(), {"booking": t.walk(juggler.JugglerBooking)[0].decode()[0].isoformat()})
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (122/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
81
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
82
if __name__ == '__main__':  # pragma: no cover
83
    main()
84