pretty logs

This commit is contained in:
mcinj 2022-05-14 11:13:29 -04:00
parent 54054b4f6d
commit d76452bdc3
3 changed files with 25 additions and 37 deletions

View file

@ -84,18 +84,18 @@ class SteamGifts:
self.points = int(soup.find('span', {'class': 'nav__points'}).text) # storage points
self.contributor_level = int(float(soup.select_one('nav a>span[title]')['title']))
except TypeError:
logger.error(" Cookie is not valid.")
raise SteamGiftsException("Cookie is not valid.")
logger.error("⛔⛔ Cookie is not valid. A new one must be added.⛔⛔⛔")
raise SteamGiftsException("Cookie is not valid. A new one must be added.")
won = soup.select("a[title='Giveaways Won'] div")
if won:
number_won = soup.select_one("a[title='Giveaways Won'] div").text
won_notifications = TableNotification.get_won_notifications_today()
if won_notifications and len(won_notifications) >= 1:
logger.info("Win(s) detected, but we have already notified that there are won games waiting "
logger.info("🆒️ Win(s) detected, but we have already notified that there are won games waiting "
"to be received. Doing nothing.")
else:
logger.info(f"WINNER! You have {number_won} game(s) waiting to be claimed.")
logger.info(f"💰💰 WINNER! You have {number_won} game(s) waiting to be claimed. 💰💰")
self.notification.send_won(f"WINNER! You have {number_won} game(s) waiting to be claimed.")
else:
logger.debug('No wins detected. Doing nothing.')
@ -109,30 +109,30 @@ class SteamGifts:
if self.blacklist is not None and self.blacklist != ['']:
for keyword in self.blacklist:
if giveaway.game_name.lower().find(keyword.lower()) != -1:
txt = f"Game {giveaway.game_name} contains the blacklisted keyword {keyword}"
txt = f"〰️ Game {giveaway.game_name} contains the blacklisted keyword {keyword}"
logger.info(txt)
return False
if giveaway.contributor_level is None or self.contributor_level < giveaway.contributor_level:
txt = f"Game {giveaway.game_name} requires at least level {giveaway.contributor_level} contributor level " \
f"to enter. Your level: {self.contributor_level}"
txt = f"〰️ Game {giveaway.game_name} requires at least level {giveaway.contributor_level} contributor " \
f"level to enter. Your level: {self.contributor_level}"
logger.info(txt)
return False
if self.points - int(giveaway.cost) < 0:
txt = f" Not enough points to enter: {giveaway.game_name}"
txt = f"〰️ Not enough points to enter: {giveaway.game_name}"
logger.info(txt)
return False
if giveaway.cost < self.minimum_game_points:
txt = f"Game {giveaway.game_name} costs {giveaway.cost}P and is below your cutoff of " \
txt = f"〰️ Game {giveaway.game_name} costs {giveaway.cost}P and is below your cutoff of " \
f"{self.minimum_game_points}P."
logger.info(txt)
return False
if giveaway.time_remaining_in_minutes > self.max_time_left:
txt = f"Game {giveaway.game_name} has {giveaway.time_remaining_in_minutes} minutes left and is " \
txt = f"〰️ Game {giveaway.game_name} has {giveaway.time_remaining_in_minutes} minutes left and is " \
f"above your cutoff of {self.max_time_left} minutes."
logger.info(txt)
return False
if giveaway.game_entries / giveaway.copies > self.max_entries:
txt = f"Game {giveaway.game_name} has {giveaway.game_entries} entries and is above your cutoff " \
txt = f"〰️ Game {giveaway.game_name} has {giveaway.game_entries} entries and is above your cutoff " \
f"of {self.max_entries} entries."
logger.info(txt)
return False
@ -153,14 +153,14 @@ class SteamGifts:
logger.debug(f"Successfully entered giveaway {giveaway.giveaway_game_id}: {json_data}")
return True
else:
logger.error(f"Failed entering giveaway {giveaway.giveaway_game_id}: {json_data}")
logger.error(f"Failed entering giveaway {giveaway.giveaway_game_id}: {json_data}")
return False
def evaluate_giveaways(self, page=1):
n = page
run = True
while run and n < 3: # hard stop safety net at page 3 as idk why we would ever get to this point
txt = "⚙️ Retrieving games from %d page." % n
txt = "〰️ Retrieving games from %d page." % n
logger.info(txt)
filtered_url = self.filter_url[self.gifts_type] % n
@ -176,21 +176,21 @@ class SteamGifts:
# game_list = soup.find_all('div', {'class': 'giveaway__row-inner-wrap'})
if not len(unentered_game_list) or (all_games_list_count == pinned_giveaway_count):
txt = f"We have run out of gifts to consider."
txt = f"〰️ We have run out of gifts to consider."
logger.info(txt)
break
for item in unentered_game_list:
giveaway = Giveaway(item)
txt = f"{giveaway.game_name} - {giveaway.cost}P - {giveaway.game_entries} entries (w/ {giveaway.copies} " \
txt = f"〰️ {giveaway.game_name} - {giveaway.cost}P - {giveaway.game_entries} entries (w/ {giveaway.copies} " \
f"copies) - Created {giveaway.time_created_string} ago with {giveaway.time_remaining_string} remaining."
logger.info(txt)
if giveaway.pinned and not self.pinned:
logger.info(f"Giveaway {giveaway.game_name} is pinned. Ignoring.")
logger.info(f"〰️ Giveaway {giveaway.game_name} is pinned. Ignoring.")
continue
if self.points == 0 or self.points < self.min_points:
txt = f"🛋️ We have {self.points} points, but we need {self.min_points} to start."
txt = f" We have {self.points} points, but we need {self.min_points} to start."
logger.info(txt)
run = False
break
@ -203,7 +203,7 @@ class SteamGifts:
if res:
TableGiveaway.upsert_giveaway(giveaway, True)
self.points -= int(giveaway.cost)
txt = f"🎉 One more game! Has just entered {giveaway.game_name}"
txt = f"✅ Entered giveaway '{giveaway.game_name}'"
logger.info(txt)
sleep(randint(4, 15))
else:
@ -215,7 +215,7 @@ class SteamGifts:
# after this point will also exceed the max time left
if self.gifts_type != "New" and not giveaway.pinned and \
giveaway.time_remaining_in_minutes > self.max_time_left:
logger.info("We have run out of gifts to consider.")
logger.info("🟡 We have run out of gifts to consider.")
run = False
break
@ -224,10 +224,10 @@ class SteamGifts:
def start(self):
self.update_info()
if self.points >= self.min_points:
txt = f"🤖 You have {self.points} points. Evaluating '{self.gifts_type}' giveaways..."
txt = f" You have {self.points} points. Evaluating '{self.gifts_type}' giveaways..."
logger.info(txt)
self.evaluate_giveaways()
else:
txt = f"You have {self.points} points which is below your minimum point threshold of " \
txt = f"🟡 You have {self.points} points which is below your minimum point threshold of " \
f"{self.min_points} points for '{self.gifts_type}' giveaways. Not evaluating right now."
logger.info(txt)

View file

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello!</title>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a simple paragraph.</p>
</body>
</html>

View file

@ -117,18 +117,20 @@ class GiveawayEntererThread(threading.Thread):
wishlist_max_entries, wishlist_max_time_left, 0, '', notification)
if not main_page_enabled and not wishlist_page_enabled:
logger.error("Both 'Default' and 'Wishlist' configurations are disabled. Nothing will run. Exiting...")
logger.error("⁉️ Both 'Default' and 'Wishlist' configurations are disabled. Nothing will run. Exiting...")
sleep(10)
exit(-1)
while True:
logger.info("🟢 Evaluating giveaways.")
if wishlist_page_enabled:
wishlist_page.start()
if main_page_enabled:
all_page.start()
logger.info("🔴 All giveaways evaluated.")
random_seconds = randint(1740, 3540) # sometime between 29-59 minutes
logger.info(f"Going to sleep for {random_seconds / 60} minutes.")
logger.info(f"🛋 Going to sleep for {random_seconds / 60} minutes.")
sleep(random_seconds)
def run(self):