-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpytly.py
77 lines (65 loc) · 2.2 KB
/
pytly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from PyInquirer import prompt
import configargparse
from src.create.create import createBitlink
from src.expand.expand import expandBitlink
from src.information.information import getInformation
from src.generate.generate import generateAccessToken
print("""Pytly - Made by Snowleoo
------------------------------------""")
def init_parser():
parser = configargparse.ArgParser(
config_file_parser_class=configargparse.YAMLConfigFileParser,
default_config_files=["config.yaml"],
description='CLI application for managing Bit.ly links.'
)
parser.add_argument("-c", "--config-path", is_config_file=True, default="config.yaml", dest="config_path", help="path to the config file")
parser.add_argument("-t", "--access-token", dest="access_token", help="Bit.ly access token")
return parser.parse()
questions = [
{
'type': 'list',
'name': 'action',
'message': 'Which action do you want to perform?',
"choices": [
{
'key': 's',
'name': 'Shorten a Link',
'value': "shorten"
},
{
"key": "e",
"name": "Expand a Bitlink",
"value": "expand"
},
{
"key": "i",
"name": "Get information about a Bitlink",
"value": "information"
},
{
"key": "g",
"name": "Generate an access token and safe it to the configuration file",
"value": "generate_access_token"
},
{
"key": "q",
"name": "Quit",
"value": "quit"
}
],
}
]
if __name__ == "__main__":
config = init_parser()
answers = prompt(questions)
action = answers["action"]
if action == "shorten":
createBitlink(config)
elif action == "expand":
expandBitlink(config)
elif action == "information":
getInformation(config)
elif action == "generate_access_token":
generateAccessToken(config)
elif action == "quit":
pass