Passed
Push — master ( 816317...cc1553 )
by John
03:01
created

bbarchivist.scripts.escreens.questionnaire()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nop 0
dl 0
loc 14
rs 9.85
c 0
b 0
f 0
1
#!/usr/bin/env python3
2
"""Calculates escreens codes."""
3
4
import sys  # load arguments
5
6
from bbarchivist import argutils  # input validation
7
from bbarchivist import decorators  # enter to exit
8
from bbarchivist import hashutils  # main program
9
10
__author__ = "Thurask"
11
__license__ = "WTFPL v2"
12
__copyright__ = "2015-2018 Thurask"
13
14
15
def escreens_main():
16
    """
17
    Parse arguments from argparse/questionnaire.
18
19
    Invoke :func:`bbarchivist.hashutils.calculate_escreens` with arguments.
20
    """
21
    if len(sys.argv) > 1:
22
        parser = argutils.default_parser("bb-escreens", "Calculate escrens codes")
23
        parser.add_argument("pin",
24
                            help="PIN, 8 characters",
25
                            type=argutils.escreens_pin)
26
        parser.add_argument("app",
27
                            help="OS version, 10.x.y.zzzz")
28
        parser.add_argument("uptime",
29
                            help="Uptime, in ms",
30
                            type=argutils.positive_integer)
31
        parser.add_argument("duration",
32
                            help="1/3/6/15/30 days",
33
                            type=argutils.escreens_duration)
34
        args = parser.parse_args(sys.argv[1:])
35
        key = hashutils.calculate_escreens(
36
            args.pin,
37
            args.app,
38
            str(args.uptime),
39
            args.duration)
40
        print(key)
41
    else:
42
        questionnaire()
43
44
45
def questionnaire():
46
    """
47
    Questions to ask if no arguments given.
48
    """
49
    pin = input("PIN: ")
50
    app = input("APP VERSION: ")
51
    uptime = int(input("UPTIME: "))
52
    duration = int(input("1/3/6/15/30 DAYS: "))
53
    pin = argutils.escreens_pin(pin)
54
    uptime = argutils.positive_integer(uptime)
55
    duration = argutils.escreens_duration(duration)
56
    key = hashutils.calculate_escreens(pin.lower(), app, str(uptime), duration)
57
    print("\n{0}".format(key))
58
    decorators.enter_to_exit(True)
59
60
61
if __name__ == "__main__":
62
    escreens_main()
63