-
Notifications
You must be signed in to change notification settings - Fork 15
/
env_to_config.py
61 lines (46 loc) · 1.19 KB
/
env_to_config.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
#!/usr/bin/python3
############################
# ENV TO CONFIG
# https://github.com/co8/hds
#
# Grab Docker ENV variables for HDS and convert config values to save to config.json JSON file
#
# co8.com
# enrique r grullon
# discord: co8#1934
############################
# modules/libraries
import sys
import requests
import json
# USAGE
# $ python3 env_to_config.py HOTSPOT="112MWdscG3Dj" DISCORD_WEBHOOK="https://disord/webhook/url" BOBCAT_LOCAL_ENDPOINT="https://192.168.0.100"
# define config file
config_file = "config.json"
config = {}
def load_config():
global config
with open(config_file) as json_data_file:
config = json.load(json_data_file)
# Load ENVs as arguments passed to this script
# Add all ENV variables to json
def add_env_to_config():
global config
args = sys.argv[1:]
for a in args:
var = a.split("=")
key = var[0].lower()
config[key] = var[1]
# Update config.json file
def update_config():
global config
with open(config_file, "w") as outfile:
json.dump(config, outfile)
def main():
load_config()
add_env_to_config()
update_config()
# Run Script
if __name__ == "__main__":
main()