forked from snori74/auto-luc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
125 lines (103 loc) · 2.81 KB
/
settings.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#
# Pull settings, including 'secrets', from local dot file
#
import configparser
import os
import sys
import json
config = configparser.ConfigParser()
config_dir = os.path.expanduser("~/.auto-luc/")
full_path = config_dir + "config"
settings = [
"REDDIT_CLIENT_SECRET",
"REDDIT_CLIENT_ID",
"REDDIT_USER_AGENT",
"REDDIT_USERNAME",
"REDDIT_PASSWORD",
"GITHUB_ACCESS_TOKEN",
]
"""
The ~/.auto-luc/config file is essentially in ".ini" format, like this:
[Global]
# Reddit
REDDIT_CLIENT_ID = "ABC998EDILHGA"
REDDIT_CLIENT_SECRET = "ZXCbhRmoLZo4xAIRD754aC3YaQ0"
REDDIT_USER_AGENT = "thud"
REDDIT_USERNAME = "smellytoes"
REDDIT_PASSWORD = "tuulip99Wanderspring!"
# GitHub
GITHUB_ACCESS_TOKEN = "fbb9fe26660855920b5dfa098755391095e413d"
(NB these creds are bogus)
"""
try:
config.read(full_path)
REDDIT_CLIENT_SECRET = json.loads(config.get("Global", "REDDIT_CLIENT_SECRET"))
except:
sys.exit(
"\n[Error]: ",
"REDDIT_CLIENT_SECRET",
" not found.\n"
"\n The script expects settings to be stored"
"\n in the file: ~/.auto-luc/config "
"\n",
)
try:
config.read(full_path)
REDDIT_CLIENT_ID = json.loads(config.get("Global", "REDDIT_CLIENT_ID"))
except:
sys.exit(
"\n[Error]: ",
"REDDIT_CLIENT_ID",
" not found.\n"
"\n The script expects settings to be stored"
"\n in the file: ~/.auto-luc/config "
"\n",
)
try:
config.read(full_path)
REDDIT_USER_AGENT = json.loads(config.get("Global", "REDDIT_USER_AGENT"))
except:
sys.exit(
"\n[Error]: ",
"REDDIT_USER_AGENT",
" not found.\n"
"\n The script expects settings to be stored"
"\n in the file: ~/.auto-luc/config "
"\n",
)
try:
config.read(full_path)
REDDIT_USERNAME = json.loads(config.get("Global", "REDDIT_USERNAME"))
except:
sys.exit(
"\n[Error]: ",
"REDDIT_USERNAME",
" not found.\n"
"\n The script expects settings to be stored"
"\n in the file: ~/.auto-luc/config "
"\n",
)
try:
config.read(full_path)
REDDIT_PASSWORD = json.loads(config.get("Global", "REDDIT_PASSWORD"))
except:
sys.exit(
"\n[Error]: ",
"REDDIT_PASSWORD",
" not found.\n"
"\n The script expects settings to be stored"
"\n in the file: ~/.auto-luc/config "
"\n",
)
try:
config.read(full_path)
GITHUB_ACCESS_TOKEN = json.loads(config.get("Global", "GITHUB_ACCESS_TOKEN"))
except:
sys.exit(
"\n[Error]: ",
"GITHUB_ACCESS_TOKEN",
" not found.\n"
"\n The script expects settings to be stored"
"\n in the file: ~/.auto-luc/config "
"\n",
)