forked from 21isenough/LightningATM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
152 lines (118 loc) · 4.25 KB
/
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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from configparser import ConfigParser
import logging
import os
import math
from shutil import copyfile
import utils
home = os.path.expanduser("~")
ATM_data_dir = home + "/.lightningATM/"
config_file_path = ATM_data_dir + "config.ini"
# check the config directory exists, create it if not
if not os.path.exists(ATM_data_dir):
os.makedirs(ATM_data_dir)
# Set to logging.DEBUG if more info needed
logging.disable(logging.DEBUG)
# Set to logging.DEBUG if more "requests" debugging info needed
logging.getLogger("requests").setLevel(logging.INFO)
logging.getLogger("urllib3.connectionpool").setLevel(logging.INFO)
# Configure basigConfig for the "logging" module
logging.basicConfig(
filename="{}/debug.log".format(ATM_data_dir),
format="%(asctime)-23s %(name)-9s %(levelname)-7s | %(message)s",
datefmt="%Y/%m/%d %I:%M:%S %p",
level=logging.DEBUG,
)
# Create logger for this config file
logger = logging.getLogger("CONFIG")
yes = ["yes", "ye", "y"]
no = ["no", "n"]
def ask_scan_config_val(section, variable):
while True:
try:
res = input(
"Do you want to scan to input {} {}".format(section, variable)
).lower()
if res in yes:
# value = scan the qr for the value
# update_config(section, variable, value
...
elif res in no:
return
else:
print("Input invalid, please try again or KeyboardInterrupt to exit")
except KeyboardInterrupt:
return
def check_config():
"""Checks the config and prompt the user to provide values for missing keys
"""
if conf["lnd"]["macaroon"] is (None or ""):
logger.warning("Missing value for lnd macaroon in config")
ask_scan_config_val("lnd", "macaroon")
if conf["lntxbot"]["creds"] is (None or ""):
logger.warning("Missing value for lntxbot credential in config")
ask_scan_config_val("lntxbot", "creds")
def update_config(section, variable, value):
"""Update the config with the new value for the variable.
If dangermode is on, we save them to config.ini, else we write them to the temporary
dictionary
"""
if conf["atm"]["dangermode"].lower() == "on":
config = create_config()
config[section][variable] = value
with open(CONFIG_FILE, "w") as configfile:
config.write(configfile)
else:
conf[section][variable] = value
def check_dangermode():
if conf["atm"]["dangermode"].lower() == "on":
return True
else:
return False
# config file handling
def get_config_file():
# check that the config file exists, if not copy over the example_config
if not os.path.exists(ATM_data_dir + "config.ini"):
example_config = os.path.join(os.path.dirname(__file__), "example_config.ini")
copyfile(example_config, ATM_data_dir + "config.ini")
return os.environ.get("CONFIG_FILE", config_file_path)
def create_config(config_file=None):
parser = ConfigParser(comment_prefixes="/", allow_no_value=True, strict=False)
parser.read(config_file or CONFIG_FILE)
return parser
CONFIG_FILE = get_config_file()
conf = create_config()
######################################################
### (Do not change and of these parameters unless ###
### you know exactly what you are doing. ###
######################################################
# TODO: Add variable to set certificate check to true or false
# Papirus eInk size is 128 x 96 pixels
WHITE = 1
BLACK = 0
PAPIRUSROT = 0
if "papirus" in conf["atm"]["display"]:
from papirus import Papirus
PAPIRUS = Papirus(rotation=PAPIRUSROT)
# Display - Waveshare 2.13 is 250 * 122 pixels
if "waveshare" in conf["atm"]["display"]:
from waveshare_epd import epd2in13_V2
WAVESHARE = epd2in13_V2.EPD()
# API URL for coingecko
COINGECKO_URL_BASE = "https://api.coingecko.com/api/v3/"
# Fiat and satoshi variables
FIAT = 0
SATS = 0
SATSFEE = 0
INVOICE = ""
# Set btc and sat price
BTCPRICE = utils.get_btc_price(conf["atm"]["cur"])
SATPRICE = math.floor((1 / (BTCPRICE * 100)) * 100000000)
# Button / Acceptor Pulses
LASTIMPULSE = 0
PULSES = 0
LASTPUSHES = 0
PUSHES = 0
COINCOUNT = 0
# Lists for different coin counting, not yet implemented
# COINLIST = []
# PULSLIST = []