2022-04-23 18:34:04 +02:00
|
|
|
import configparser
|
2022-04-23 21:00:22 +02:00
|
|
|
from configparser import ConfigParser
|
2022-04-23 18:34:04 +02:00
|
|
|
|
2022-04-23 21:00:22 +02:00
|
|
|
import log
|
|
|
|
|
|
|
|
logger = log.get_logger(__name__)
|
2022-04-23 18:34:04 +02:00
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
|
|
|
|
2022-04-23 21:00:22 +02:00
|
|
|
class MyException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def value_range(min, max):
|
|
|
|
return [str(x) for x in [*range(min, max + 1)]]
|
|
|
|
|
|
|
|
|
|
|
|
class MyConfig(ConfigParser):
|
|
|
|
def __init__(self, config_file):
|
|
|
|
super(MyConfig, self).__init__()
|
|
|
|
|
|
|
|
self.read(config_file)
|
|
|
|
self.validate_config()
|
|
|
|
|
|
|
|
def validate_config(self):
|
|
|
|
required_values = {
|
|
|
|
'DEFAULT': {
|
|
|
|
'gift_types': ('All', 'Wishlist', 'Recommended', 'Copies', 'DLC', 'New'),
|
|
|
|
'pinned': ('true', 'false'),
|
|
|
|
'minimum_points': '%s' % (value_range(0,400)),
|
|
|
|
'max_entries': '%s' % (value_range(0,10000)),
|
|
|
|
'max_time_left': '%s' % (value_range(0,21600))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for section, keys in required_values.items():
|
|
|
|
if section not in self:
|
|
|
|
raise MyException(
|
|
|
|
'Missing section %s in the config file' % section)
|
|
|
|
|
|
|
|
for key, values in keys.items():
|
|
|
|
if key not in self[section] or self[section][key] == '':
|
|
|
|
raise MyException((
|
|
|
|
'Missing value for %s under section %s in ' +
|
|
|
|
'the config file') % (key, section))
|
|
|
|
|
|
|
|
if values:
|
|
|
|
if self[section][key] not in values:
|
|
|
|
raise MyException((
|
|
|
|
'Invalid value for %s under section %s in ' +
|
|
|
|
'the config file') % (key, section))
|
|
|
|
|
|
|
|
|
2022-04-23 18:34:04 +02:00
|
|
|
def run():
|
|
|
|
from main import SteamGifts as SG
|
|
|
|
|
2022-04-23 21:00:22 +02:00
|
|
|
file_name = '../config/config.ini'
|
|
|
|
try:
|
|
|
|
with open(file_name) as f:
|
|
|
|
config.read_file(f)
|
|
|
|
MyConfig(file_name)
|
|
|
|
except IOError:
|
|
|
|
txt = f"{file_name} doesn't exist. Rename {file_name}.example to {file_name} and fill out."
|
|
|
|
logger.warning(txt)
|
|
|
|
exit(-1)
|
|
|
|
except MyException as e:
|
|
|
|
logger.error(e)
|
|
|
|
exit(-1)
|
2022-04-23 18:34:04 +02:00
|
|
|
|
2022-04-23 21:00:22 +02:00
|
|
|
config.read(file_name)
|
|
|
|
cookie = config['DEFAULT'].get('cookie')
|
2022-04-23 18:34:04 +02:00
|
|
|
pinned_games = config['DEFAULT'].getboolean('pinned')
|
|
|
|
gift_types = config['DEFAULT'].get('gift_types')
|
2022-04-23 21:00:22 +02:00
|
|
|
minimum_points = config['DEFAULT'].getint('minimum_points')
|
|
|
|
max_entries = config['DEFAULT'].getint('max_entries')
|
|
|
|
max_time_left = config['DEFAULT'].getint('max_time_left')
|
2022-04-23 18:34:04 +02:00
|
|
|
|
2022-04-23 21:00:22 +02:00
|
|
|
s = SG(cookie, gift_types, pinned_games, minimum_points, max_entries, max_time_left)
|
2022-04-23 18:34:04 +02:00
|
|
|
s.start()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|