Track DLC page, fix dependencies, refactor config
This commit is contained in:
parent
cc1cbc08f4
commit
e197a19f1c
4 changed files with 70 additions and 32 deletions
|
@ -2,16 +2,18 @@
|
|||
cookie = PHPSESSIONCOOKIEGOESHERE
|
||||
# should we consider giveaways on the 'ALL' page? it is the main page
|
||||
enabled = true
|
||||
|
||||
[ALL]
|
||||
# minimum number of points in your account before entering into giveaways
|
||||
minimum_points = 50
|
||||
all.minimum_points = 50
|
||||
# max number of entries in a giveaway for it to be considered
|
||||
max_entries = 2000
|
||||
all.max_entries = 2000
|
||||
# time left in minutes of a giveaway for it to be considered
|
||||
max_time_left = 300
|
||||
all.max_time_left = 300
|
||||
# the minimum point value for a giveaway to be considered
|
||||
minimum_game_points = 1
|
||||
all.minimum_game_points = 1
|
||||
# a comma separated list of keywords in game titles to ignore
|
||||
blacklist_keywords = hentai,adult
|
||||
all.blacklist_keywords = hentai,adult
|
||||
|
||||
[WISHLIST]
|
||||
# should we consider giveaways on the 'Wishlist' page?
|
||||
|
@ -23,6 +25,16 @@ wishlist.max_entries = 10000
|
|||
# time left in minutes of a giveaway for it to be considered
|
||||
wishlist.max_time_left = 300
|
||||
|
||||
[DLC]
|
||||
# should we consider giveaways on the 'DLC' page?
|
||||
dlc.enabled = true
|
||||
# minimum number of points in your account before entering into giveaways
|
||||
dlc.minimum_points = 1
|
||||
# max number of entries in a giveaway for it to be considered
|
||||
dlc.max_entries = 10000
|
||||
# time left in minutes of a giveaway for it to be considered
|
||||
dlc.max_time_left = 300
|
||||
|
||||
[NOTIFICATIONS]
|
||||
# a prefix for messages sent via notifications
|
||||
notification.prefix = SG-Bot
|
||||
|
|
|
@ -10,3 +10,4 @@ Flask==2.1.2
|
|||
Flask-BasicAuth==0.2.0
|
||||
pyopenssl==22.0.0
|
||||
apscheduler==3.9.1
|
||||
werkzeug==2.2.2
|
||||
|
|
|
@ -29,11 +29,13 @@ def choose_user_agent():
|
|||
class ConfigReader(ConfigParser):
|
||||
required_values = {
|
||||
'DEFAULT': {
|
||||
'enabled': ('true', 'false'),
|
||||
'minimum_points': '%s' % (value_range(0, 400)),
|
||||
'max_entries': '%s' % (value_range(0, 100000)),
|
||||
'max_time_left': '%s' % (value_range(0, 21600)),
|
||||
'minimum_game_points': '%s' % (value_range(0, 50))
|
||||
},
|
||||
'ALL': {
|
||||
'all.enabled': ('true', 'false'),
|
||||
'all.minimum_points': '%s' % (value_range(0, 400)),
|
||||
'all.max_entries': '%s' % (value_range(0, 100000)),
|
||||
'all.max_time_left': '%s' % (value_range(0, 21600)),
|
||||
'all.minimum_game_points': '%s' % (value_range(0, 50))
|
||||
},
|
||||
'WISHLIST': {
|
||||
'wishlist.enabled': ('true', 'false'),
|
||||
|
@ -52,13 +54,15 @@ class ConfigReader(ConfigParser):
|
|||
default_values = {
|
||||
'DEFAULT': {
|
||||
'cookie': '',
|
||||
'user_agent': f"{choose_user_agent()}",
|
||||
'enabled': 'true',
|
||||
'minimum_points': f"{randint(20, 50)}",
|
||||
'max_entries': f"{randint(1000, 2500)}",
|
||||
'max_time_left': f"{randint(180, 500)}",
|
||||
'minimum_game_points': "0",
|
||||
'blacklist_keywords': 'hentai,adult'
|
||||
'user_agent': f"{choose_user_agent()}"
|
||||
},
|
||||
'ALL': {
|
||||
'all.enabled': 'true',
|
||||
'all.minimum_points': f"{randint(20, 50)}",
|
||||
'all.max_entries': f"{randint(1000, 2500)}",
|
||||
'all.max_time_left': f"{randint(180, 500)}",
|
||||
'all.minimum_game_points': "0",
|
||||
'all.blacklist_keywords': 'hentai,adult'
|
||||
},
|
||||
'WISHLIST': {
|
||||
'wishlist.enabled': 'true',
|
||||
|
@ -66,6 +70,12 @@ class ConfigReader(ConfigParser):
|
|||
'wishlist.max_entries': f"{randint(10000, 100000)}",
|
||||
'wishlist.max_time_left': f"{randint(180, 500)}"
|
||||
},
|
||||
'DLC': {
|
||||
'dlc.enabled': 'true',
|
||||
'dlc.minimum_points': '1',
|
||||
'dlc.max_entries': f"{randint(10000, 100000)}",
|
||||
'dlc.max_time_left': f"{randint(180, 500)}"
|
||||
},
|
||||
'NOTIFICATIONS': {
|
||||
'notification.prefix': '',
|
||||
'pushover.enabled': 'false',
|
||||
|
|
|
@ -24,18 +24,22 @@ class GiveawayThread(threading.Thread):
|
|||
self.won_giveaway_job_id = 'eval_won_giveaways'
|
||||
self.evaluate_giveaway_job_id = 'eval_giveaways'
|
||||
|
||||
if config['DEFAULT'].getboolean('enabled'):
|
||||
self._all_page = None
|
||||
self._wishlist_page = None
|
||||
self._dlc_page = None
|
||||
|
||||
cookie = config['DEFAULT'].get('cookie')
|
||||
user_agent = config['DEFAULT'].get('user_agent')
|
||||
|
||||
minimum_points = config['DEFAULT'].getint('minimum_points')
|
||||
max_entries = config['DEFAULT'].getint('max_entries')
|
||||
max_time_left = config['DEFAULT'].getint('max_time_left')
|
||||
minimum_game_points = config['DEFAULT'].getint('minimum_game_points')
|
||||
blacklist = config['DEFAULT'].get('blacklist_keywords')
|
||||
if config['ALL'].getboolean('all.enabled'):
|
||||
all_minimum_points = config['ALL'].getint('all.minimum_points')
|
||||
all_max_entries = config['ALL'].getint('all.max_entries')
|
||||
all_max_time_left = config['ALL'].getint('all.max_time_left')
|
||||
all_minimum_game_points = config['DEFAULT'].getint('minimum_game_points')
|
||||
all_blacklist = config['DEFAULT'].get('blacklist_keywords')
|
||||
|
||||
self._all_page = EnterGiveaways(cookie, user_agent, 'All', False, minimum_points, max_entries,
|
||||
max_time_left, minimum_game_points, blacklist, notification)
|
||||
self._all_page = EnterGiveaways(cookie, user_agent, 'All', False, all_minimum_points, all_max_entries,
|
||||
all_max_time_left, all_minimum_game_points, all_blacklist, notification)
|
||||
|
||||
if config['WISHLIST'].getboolean('wishlist.enabled'):
|
||||
wishlist_minimum_points = config['WISHLIST'].getint('wishlist.minimum_points')
|
||||
|
@ -45,8 +49,16 @@ class GiveawayThread(threading.Thread):
|
|||
self._wishlist_page = EnterGiveaways(cookie, user_agent, 'Wishlist', False, wishlist_minimum_points,
|
||||
wishlist_max_entries, wishlist_max_time_left, 0, '', notification)
|
||||
|
||||
if not self._all_page and not self._wishlist_page:
|
||||
logger.error("⁉️ Both 'Default' and 'Wishlist' configurations are disabled. Nothing will run. Exiting...")
|
||||
if config['DLC'].getboolean('dlc.enabled'):
|
||||
dlc_minimum_points = config['DLC'].getint('dlc.minimum_points')
|
||||
dlc_max_entries = config['DLC'].getint('dlc.max_entries')
|
||||
dlc_max_time_left = config['DLC'].getint('dlc.max_time_left')
|
||||
|
||||
self._dlc_page = EnterGiveaways(cookie, user_agent, 'DLC', False, dlc_minimum_points,
|
||||
dlc_max_entries, dlc_max_time_left, 0, '', notification)
|
||||
|
||||
if not self._all_page and not self._wishlist_page and not self._dlc_page :
|
||||
logger.error("⁉️ 'All', 'Wishlist' and 'DLC' configurations are disabled. Nothing will run. Exiting...")
|
||||
sleep(10)
|
||||
exit(-1)
|
||||
|
||||
|
@ -69,7 +81,7 @@ class GiveawayThread(threading.Thread):
|
|||
if evaluate_giveaway_job:
|
||||
logger.debug("Previous giveaway evaluator job exists. Removing.")
|
||||
evaluate_giveaway_job.remove()
|
||||
runner = GiveawayThread.GiveawayRunner(self._wishlist_page, self._all_page,
|
||||
runner = GiveawayThread.GiveawayRunner(self._dlc_page, self._wishlist_page, self._all_page,
|
||||
self.evaluate_giveaway_job_id)
|
||||
self._scheduler.add_job(runner.run,
|
||||
id=self.evaluate_giveaway_job_id,
|
||||
|
@ -116,13 +128,16 @@ class GiveawayThread(threading.Thread):
|
|||
|
||||
class GiveawayRunner:
|
||||
|
||||
def __init__(self, wishlist_page, all_page, job_id):
|
||||
def __init__(self, dlc_page, wishlist_page, all_page, job_id):
|
||||
self._dlc_page = dlc_page
|
||||
self._wishlist_page = wishlist_page
|
||||
self._all_page = all_page
|
||||
self._job_id = job_id
|
||||
|
||||
def run(self):
|
||||
logger.info("🟢 Evaluating giveaways.")
|
||||
if self._dlc_page:
|
||||
self._dlc_page.start()
|
||||
if self._wishlist_page:
|
||||
self._wishlist_page.start()
|
||||
if self._all_page:
|
||||
|
|
Loading…
Reference in a new issue