deprecate fields
This commit is contained in:
parent
d83bc0f49f
commit
96652893e2
3 changed files with 16 additions and 11 deletions
|
@ -2,10 +2,6 @@
|
||||||
cookie = PHPSESSIONCOOKIEGOESHERE
|
cookie = PHPSESSIONCOOKIEGOESHERE
|
||||||
# should we consider giveaways on the 'ALL' page? it is the main page
|
# should we consider giveaways on the 'ALL' page? it is the main page
|
||||||
enabled = true
|
enabled = true
|
||||||
# gift_types options: All
|
|
||||||
gift_types = All
|
|
||||||
# should we consider pinned-at-the-top giveaways
|
|
||||||
pinned = false
|
|
||||||
# minimum number of points in your account before entering into giveaways
|
# minimum number of points in your account before entering into giveaways
|
||||||
minimum_points = 50
|
minimum_points = 50
|
||||||
# max number of entries in a giveaway for it to be considered
|
# max number of entries in a giveaway for it to be considered
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from random import randint
|
from random import randint
|
||||||
|
import log
|
||||||
|
|
||||||
|
logger = log.get_logger(__name__)
|
||||||
|
|
||||||
class ConfigException(Exception):
|
class ConfigException(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -13,8 +15,6 @@ class ConfigReader(ConfigParser):
|
||||||
required_values = {
|
required_values = {
|
||||||
'DEFAULT': {
|
'DEFAULT': {
|
||||||
'enabled': ('true', 'false'),
|
'enabled': ('true', 'false'),
|
||||||
'gift_types': ('All'),
|
|
||||||
'pinned': ('false'),
|
|
||||||
'minimum_points': '%s' % (value_range(0, 400)),
|
'minimum_points': '%s' % (value_range(0, 400)),
|
||||||
'max_entries': '%s' % (value_range(0, 100000)),
|
'max_entries': '%s' % (value_range(0, 100000)),
|
||||||
'max_time_left': '%s' % (value_range(0, 21600)),
|
'max_time_left': '%s' % (value_range(0, 21600)),
|
||||||
|
@ -31,8 +31,6 @@ class ConfigReader(ConfigParser):
|
||||||
'DEFAULT': {
|
'DEFAULT': {
|
||||||
'cookie': '',
|
'cookie': '',
|
||||||
'enabled': 'true',
|
'enabled': 'true',
|
||||||
'gift_types': 'All',
|
|
||||||
'pinned': 'false',
|
|
||||||
'minimum_points': f"{randint(20, 100)}",
|
'minimum_points': f"{randint(20, 100)}",
|
||||||
'max_entries': f"{randint(1000, 2500)}",
|
'max_entries': f"{randint(1000, 2500)}",
|
||||||
'max_time_left': f"{randint(180,500)}",
|
'max_time_left': f"{randint(180,500)}",
|
||||||
|
@ -46,6 +44,12 @@ class ConfigReader(ConfigParser):
|
||||||
'wishlist.max_time_left': f"{randint(180,500)}"
|
'wishlist.max_time_left': f"{randint(180,500)}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
deprecated_values = {
|
||||||
|
'DEFAULT': {
|
||||||
|
'pinned': 'false',
|
||||||
|
'gift_types': 'All'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, config_file):
|
def __init__(self, config_file):
|
||||||
super(ConfigReader, self).__init__()
|
super(ConfigReader, self).__init__()
|
||||||
|
@ -54,6 +58,7 @@ class ConfigReader(ConfigParser):
|
||||||
if modified:
|
if modified:
|
||||||
with open(config_file, 'w+') as file:
|
with open(config_file, 'w+') as file:
|
||||||
self.write(file)
|
self.write(file)
|
||||||
|
self.find_deprecated()
|
||||||
self.validate_config()
|
self.validate_config()
|
||||||
|
|
||||||
def create_defaults(self):
|
def create_defaults(self):
|
||||||
|
@ -68,6 +73,12 @@ class ConfigReader(ConfigParser):
|
||||||
modified = True
|
modified = True
|
||||||
return modified
|
return modified
|
||||||
|
|
||||||
|
def find_deprecated(self):
|
||||||
|
for section, keys in self.deprecated_values.items():
|
||||||
|
for key, values in keys.items():
|
||||||
|
if key in self[section]:
|
||||||
|
logger.warn(f"config.ini : Key '{key}' in {section} is no longer used. Please remove.")
|
||||||
|
|
||||||
def validate_config(self):
|
def validate_config(self):
|
||||||
for section, keys in self.required_values.items():
|
for section, keys in self.required_values.items():
|
||||||
if section not in self:
|
if section not in self:
|
||||||
|
|
|
@ -25,15 +25,13 @@ def run():
|
||||||
config.read(file_name)
|
config.read(file_name)
|
||||||
cookie = config['DEFAULT'].get('cookie')
|
cookie = config['DEFAULT'].get('cookie')
|
||||||
enabled = config['DEFAULT'].getboolean('enabled')
|
enabled = config['DEFAULT'].getboolean('enabled')
|
||||||
pinned_games = config['DEFAULT'].getboolean('pinned')
|
|
||||||
gift_types = config['DEFAULT'].get('gift_types')
|
|
||||||
minimum_points = config['DEFAULT'].getint('minimum_points')
|
minimum_points = config['DEFAULT'].getint('minimum_points')
|
||||||
max_entries = config['DEFAULT'].getint('max_entries')
|
max_entries = config['DEFAULT'].getint('max_entries')
|
||||||
max_time_left = config['DEFAULT'].getint('max_time_left')
|
max_time_left = config['DEFAULT'].getint('max_time_left')
|
||||||
minimum_game_points = config['DEFAULT'].getint('minimum_game_points')
|
minimum_game_points = config['DEFAULT'].getint('minimum_game_points')
|
||||||
blacklist = config['DEFAULT'].get('blacklist_keywords')
|
blacklist = config['DEFAULT'].get('blacklist_keywords')
|
||||||
|
|
||||||
all_page = SteamGifts(cookie, gift_types, pinned_games, minimum_points, max_entries,
|
all_page = SteamGifts(cookie, 'All', False, minimum_points, max_entries,
|
||||||
max_time_left, minimum_game_points, blacklist)
|
max_time_left, minimum_game_points, blacklist)
|
||||||
|
|
||||||
wishlist_enabled = config['WISHLIST'].getboolean('wishlist.enabled')
|
wishlist_enabled = config['WISHLIST'].getboolean('wishlist.enabled')
|
||||||
|
|
Loading…
Reference in a new issue