diff --git a/Dockerfile b/Dockerfile index 42b358f..ebc1613 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,6 @@ FROM python:3.9-alpine RUN mkdir -p /app WORKDIR /app -# resolves gcc issue with installing regex dependency RUN apk add tzdata --no-cache ENV TZ=America/New_York diff --git a/src/SteamGifts.py b/src/SteamGifts.py index 08c01e8..213d8b7 100644 --- a/src/SteamGifts.py +++ b/src/SteamGifts.py @@ -92,10 +92,9 @@ class SteamGifts: 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.debug("Win(s) detected, but we have already notified that there are won games waiting " - "to be received. Doing nothing.") + logger.info("Win(s) detected, but we have already notified that there are won games waiting " + "to be received. Doing nothing.") else: - logger.debug("Win(s) detected. Going to send a notification.") 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: @@ -106,39 +105,36 @@ class SteamGifts: return False if giveaway.time_created_in_minutes is None: return False - 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.debug(txt) 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}" - logger.debug(txt) + 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}" - logger.debug(txt) + logger.info(txt) return False if self.points - int(giveaway.cost) < 0: txt = f"⛔ Not enough points to enter: {giveaway.game_name}" - logger.debug(txt) + 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 " \ f"{self.minimum_game_points}P." - logger.debug(txt) + 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 " \ f"above your cutoff of {self.max_time_left} minutes." - logger.debug(txt) + 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 " \ f"of {self.max_entries} entries." - logger.debug(txt) + logger.info(txt) return False return True @@ -148,15 +144,16 @@ class SteamGifts: 'User-Agent': self.user_agent } payload = {'xsrf_token': self.xsrf_token, 'do': 'entry_insert', 'code': giveaway.giveaway_game_id} + logger.debug(f"Sending enter giveaway payload: {payload}") entry = requests.post('https://www.steamgifts.com/ajax.php', data=payload, cookies=self.cookie, headers=headers) json_data = json.loads(entry.text) if json_data['type'] == 'success': - logger.debug(f"Successfully entered giveaway {giveaway.giveaway_game_id}") + 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}") + logger.error(f"Failed entering giveaway {giveaway.giveaway_game_id}: {json_data}") return False def evaluate_giveaways(self, page=1): @@ -185,7 +182,11 @@ class SteamGifts: for item in unentered_game_list: giveaway = Giveaway(item) + 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.") continue if self.points == 0 or self.points < self.min_points: diff --git a/src/giveaway.py b/src/giveaway.py index 9ffc1fc..e648152 100644 --- a/src/giveaway.py +++ b/src/giveaway.py @@ -47,6 +47,7 @@ class Giveaway: self.time_created_timestamp = int(times[1]['data-timestamp']) self.time_created_string = times[1].text self.time_created_in_minutes = self.determine_time_in_minutes(times[1]['data-timestamp']) + logger.debug(f"Scraped Giveaway: {self}") def determine_contributor_level(self, contributor_level): if contributor_level is None: @@ -104,3 +105,6 @@ class Giveaway: txt = f"Unable to determine cost or num copies of {game_name} with id {game_id}." logger.error(txt) return None, None + + def __str__(self): + return str(self.__class__) + ": " + str(self.__dict__) diff --git a/src/log.py b/src/log.py index dedfe66..562e677 100644 --- a/src/log.py +++ b/src/log.py @@ -14,7 +14,7 @@ console_output.setLevel(logging.INFO) console_format = logging.Formatter(log_format) console_output.setFormatter(console_format) -info_log_file = RotatingFileHandler('../config/info.log', maxBytes=500000, backupCount=10) +info_log_file = RotatingFileHandler('../config/info.log', maxBytes=10000, backupCount=10) info_log_file.setLevel(logging.INFO) info_log_format = logging.Formatter(log_format) info_log_file.setFormatter(info_log_format) @@ -22,19 +22,6 @@ info_log_file.setFormatter(info_log_format) logging.root.addHandler(console_output) logging.root.addHandler(info_log_file) -logging.info(""" -------------------------------------------------------------------------------------- - _____ _ _ __ _ ____ _ - / ____|| | (_) / _|| | | _ \ | | - | (___ | |_ ___ __ _ _ __ ___ __ _ _ | |_ | |_ ___ | |_) | ___ | |_ - \___ \ | __|/ _ \ / _` || '_ ` _ \ / _` || || _|| __|/ __| | _ < / _ \ | __| - ____) || |_| __/| (_| || | | | | || (_| || || | | |_ \__ \ | |_) || (_) || |_ - |_____/ \__|\___| \__,_||_| |_| |_| \__, ||_||_| \__||___/ |____/ \___/ \__| - __/ | - |___/ -------------------------------------------------------------------------------------- -""") - def get_logger(name): l = logging.getLogger(name) diff --git a/src/run.py b/src/run.py index fa1ec81..327b155 100644 --- a/src/run.py +++ b/src/run.py @@ -14,6 +14,10 @@ logger = log.get_logger(__name__) class WebServerThread(threading.Thread): + def __init__(self): + Thread.__init__(self) + self.exc = None + def run_webserver(self): from flask import Flask from flask import render_template @@ -33,7 +37,7 @@ class WebServerThread(threading.Thread): @app.route("/stream") def stream(): def generate(): - with open('../config/debug.log') as f: + with open('../config/info.log') as f: while True: yield f.read() sleep(10) @@ -166,4 +170,16 @@ def run(): if __name__ == '__main__': + logger.info(""" + ------------------------------------------------------------------------------------- + _____ _ _ __ _ ____ _ + / ____|| | (_) / _|| | | _ \ | | + | (___ | |_ ___ __ _ _ __ ___ __ _ _ | |_ | |_ ___ | |_) | ___ | |_ + \___ \ | __|/ _ \ / _` || '_ ` _ \ / _` || || _|| __|/ __| | _ < / _ \ | __| + ____) || |_| __/| (_| || | | | | || (_| || || | | |_ \__ \ | |_) || (_) || |_ + |_____/ \__|\___| \__,_||_| |_| |_| \__, ||_||_| \__||___/ |____/ \___/ \__| + __/ | + |___/ + ------------------------------------------------------------------------------------- + """) run()