diff --git a/.gitignore b/.gitignore index bb4b176..235073f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*/inputs \ No newline at end of file +*/inputs +**/__pycache__ \ No newline at end of file diff --git a/utils/cli.py b/utils/cli.py index 8de1258..4eee35f 100755 --- a/utils/cli.py +++ b/utils/cli.py @@ -7,6 +7,7 @@ Suggéré: alias aoc="$CHEMIN_VERS_CE_REPO/utils/cli.py" from optparse import OptionParser from pathlib import Path import datetime +import colors import os import requests @@ -30,10 +31,23 @@ def download_input(year, day): print("ok") -def show_puzzle(year, day, part=None): +def show_puzzle(year, day, part=None, colored=False): """Affiche l'énoncé du jour demandé""" request = session.get(f"https://adventofcode.com/{year}/day/{int(day)}") - soup = BeautifulSoup(request.content, "html.parser") + + content = request.content.decode("utf-8") + if colored: + content = content.replace("', f'{colors.bold}{colors.yellow}') + content = content.replace('', f'{colors.bold}') + content = content.replace('", f"{colors.reset}\n") + content = content.replace("", f"{colors.reset}") + content = content.replace("", f"{colors.reset}") + + + + soup = BeautifulSoup(content, "html.parser") day_desc = soup.find_all("article", {"class": "day-desc"}) if part is None: for i in range(len(day_desc)): @@ -67,7 +81,7 @@ def __main__(options, args): options.level = None else: options.level = int(options.level) - show_puzzle(options.year, options.day, options.level) + show_puzzle(options.year, options.day, options.level, colored=True) elif args[0] == "submit" or args[0] == "sb": if len(args) < 2: answer = input("Answer ?\n>> ") diff --git a/utils/colors.py b/utils/colors.py new file mode 100644 index 0000000..8d02bcb --- /dev/null +++ b/utils/colors.py @@ -0,0 +1,11 @@ +reset = "\033[0m" +bold = "\033[1m" + +magenta = "\033[35m" +yellow = "\033[33m" +white = "\033[37m" +green = "\033[32m" +black = "\033[30m" +cyan = "\033[36m" +blue = "\033[34m" +red = "\033[31m" \ No newline at end of file