diff --git a/bot.py b/bot.py index 0fe6efd..6c69995 100644 --- a/bot.py +++ b/bot.py @@ -156,7 +156,7 @@ def retry_mastodon_call(self, func, *args, retries=5, interval=10, **kwargs): for _ in range(retries): try: return func(*args, **kwargs) - except RequestException as e: + except Exception as e: print(f"Failure to execute {func.__name__}: {e}") time.sleep(interval) return False # Failed to execute @@ -189,7 +189,7 @@ def run(self): frames = self.gameboy.loop_until_stopped() result = False if frames >= 70: - result = self.gameboy.build_gif("gif_images") + result = self.gameboy.build_gif("gif_images", self.gameboy_config['gif_outline']) else: gif_dir = os.path.join(self.script_dir, "gif_images") self.gameboy.empty_directory(gif_dir) @@ -207,7 +207,10 @@ def run(self): # Probably add a check here if generating a gif is enabled (so we don't # have to generate one every single hour?) try: - previous_frames = self.gameboy.get_recent_frames("screenshots", 25) + previous_frames = self.gameboy.get_recent_frames("screenshots", + 25, + self.gameboy_config['gif_outline'] + ) previous_media = self.retry_mastodon_call( self.mastodon.media_post, retries=5, @@ -216,7 +219,8 @@ def run(self): description="Video of the previous 45 frames", ) media_ids = [media["id"], previous_media["id"]] - except BaseException: + except BaseException as e: + print(f"ERROR {e}") media_ids = [media["id"]] post = self.retry_mastodon_call( diff --git a/config.toml.example b/config.toml.example index dd0e1d4..041bd8d 100644 --- a/config.toml.example +++ b/config.toml.example @@ -5,4 +5,5 @@ poll_duration = 60 [gameboy] rom = "Pokemon - Gold Version.gbc" -title = "Pokémon Gold" \ No newline at end of file +title = "Pokémon Gold" +gif_outline="gameboy.png" diff --git a/gameboycolor.png b/gameboycolor.png new file mode 100644 index 0000000..4e6e55c Binary files /dev/null and b/gameboycolor.png differ diff --git a/gb.py b/gb.py index 3105fa7..b0f7033 100644 --- a/gb.py +++ b/gb.py @@ -63,7 +63,7 @@ def compare_frames(self, frame1, frame2): print(f"Pixels: {changed_pixels} {percent}%") return percent - def get_recent_frames(self, directory, num_frames=100): + def get_recent_frames(self, directory, num_frames=100, gif_outline='gameboy.png'): """Gets the most recent frames from a provided directory""" script_dir = os.path.dirname(os.path.realpath(__file__)) screenshot_dir = os.path.join(script_dir, directory) @@ -81,7 +81,11 @@ def get_recent_frames(self, directory, num_frames=100): count += 1 shutil.copy(image, os.path.join(script_dir, "tmp", f"{count}.png")) - self.build_gif(os.path.join(script_dir, "tmp"), fps=5, output_name="test.mp4") + self.build_gif(os.path.join(script_dir, "tmp"), + fps=5, + output_name="test.mp4", + gif_outline=gif_outline + ) self.empty_directory(os.path.join(script_dir, "tmp")) return os.path.join(script_dir, "test.mp4") @@ -95,7 +99,7 @@ def empty_directory(self, directory): for img in image_files: os.remove(os.path.join(directory, img)) - def build_gif(self, image_path, delete=True, fps=120, output_name="action.mp4"): + def build_gif(self, image_path, delete=True, fps=120, output_name="action.mp4", gif_outline="gameboy.png"): """Build a gif from a folder of images""" # Get the directory of the current script script_dir = os.path.dirname(os.path.realpath(__file__)) @@ -110,12 +114,12 @@ def build_gif(self, image_path, delete=True, fps=120, output_name="action.mp4"): for file in image_files: gameboy_outline = Image.open( - os.path.join(script_dir, "gameboy.png") + os.path.join(script_dir, gif_outline) ).convert("RGB") img = Image.open(os.path.join(gif_dir, file)).convert("RGB") - img = img.resize((181, 163)) + img = img.resize((184, 170)) combined = gameboy_outline.copy() - combined.paste(img, (165, 151)) + combined.paste(img, (159, 138)) #338, 308 combined.save(os.path.join(gif_dir, file)) images.append(os.path.join(gif_dir, file))