Giter VIP home page Giter VIP logo

Comments (8)

LiquidFun avatar LiquidFun commented on July 23, 2024

Hey, yeah this is not too hard, the first function in the create_aoc_tiles.py script is exactly meant for that:

# You can change this code entirely, or just change patterns above. You get more control if you change the code.
def get_solution_paths_dict_for_years() -> dict[int, dict[int, list[str]]]:
"""Returns a dictionary which maps years to days to a list of solution paths,
E.g.: {2022: {1: [Path("2022/01/01.py"), Path("2022/01/01.kt")], ...}}
This functions gives you more control of which solutions should be shown in the tiles. For example, you
can filter by extension, or only show a single solution, or show tiles for days that have been completed
but do not have a solution.
These can also be links to external solutions, e.g. if you want to show a solution from a different repository.
(Untested however)
"""
solution_paths_dict: dict[int, dict[int, list[str]]] = {}
# If you use a new repo for years you might just remove this if, and assign the year manually
for year_dir in sorted(get_paths_matching_regex(AOC_DIR, YEAR_PATTERN), reverse=True):
year = find_first_number(year_dir.name)
solution_paths_dict[year] = {}
# If you have a deep structure then you can adjust the year dir as well:
# year_dir = year_dir / "src/main/kotlin/com/example/aoc"
for day_dir in get_paths_matching_regex(year_dir, DAY_PATTERN):
day = find_first_number(day_dir.name)
solutions = sorted(find_recursive_solution_files(day_dir))
# To filter by extension:
# solutions = [s for s in solutions if s.suffix == ".py"]
# To only show a single solution:
# solutions = [solutions[0]]
# To show tiles for days that have been completed but do not have a solution:
# if len(solutions) == 0:
# solutions = [Path("dummy.kt")]
solutions = [solution.relative_to(AOC_DIR) for solution in solutions]
solution_paths_dict[year][day] = [s.as_posix() for s in solutions]
return solution_paths_dict

So:

  1. Put the AoCTiles folder in your repository
  2. Install requirements: pip install requirements.txt
  3. Change that function get_solution_paths_dict_for_years() to this (I have modified it so it works for your structure, it shouldn't need to be changed):
def get_solution_paths_dict_for_years() -> dict[int, dict[int, list[str]]]:
    solution_paths_dict: dict[int, dict[int, list[str]]] = {}

    year = 2022
    solution_paths_dict[year] = {}

    for solution_path in AOC_DIR.rglob("src/solutions/day*.rs"):
        day = find_first_number(solution_path.name)
        solution_paths_dict[year][day] = [solution_path.relative_to(AOC_DIR).as_posix()]
    return solution_paths_dict
  1. Add <!-- AOC TILES BEGIN --> and <!-- AOC TILES END --> to your README.md
  2. Put your session cookie in the root folder of the repository into the file session.cookie (do NOT commit this)
  3. Commit the files in Media and the README.md. Commiting the AoCTiles folder is optional.
  4. (Optional, if you want to add the images on each commit: add my .pre-commit-config.yaml to your repository and install with pre-commit install)

from adventofcode.

Rietty avatar Rietty commented on July 23, 2024

Thank you so much! I really appreciate you taking the time to help me with this. I will try it out!

from adventofcode.

Rietty avatar Rietty commented on July 23, 2024

Seems as if the the line: solution_paths_dict[year][day] = solution_path.relative_to(AOC_DIR).as_posix() has some syntax error or something? Does this need to be run on a linux environment of some sort?

from adventofcode.

LiquidFun avatar LiquidFun commented on July 23, 2024

Can you add the error here?

from adventofcode.

Rietty avatar Rietty commented on July 23, 2024

Hi @LiquidFun Apologies. I figured out the issue. I was running Python 3.8, it needed Python 3.10 or newer, doing so resolved all issues. Thank you!!!

from adventofcode.

Rietty avatar Rietty commented on July 23, 2024

Oh sorry, apparently I do get a multicolored image with a bunch of file extensions instead of just .rs and a singular colour. I think that it is picking up random file extensions outside the solutions folder?

Example:
image

from adventofcode.

LiquidFun avatar LiquidFun commented on July 23, 2024

oops, yeah, my mistake, I forgot that it needs to be a list. The function needs to be like this:

def get_solution_paths_dict_for_years() -> dict[int, dict[int, list[str]]]:
    solution_paths_dict: dict[int, dict[int, list[str]]] = {}

    year = 2022
    solution_paths_dict[year] = {}

    for solution_path in AOC_DIR.rglob("src/solutions/day*.rs"):
        day = find_first_number(solution_path.name)
        solution_paths_dict[year][day] = [solution_path.relative_to(AOC_DIR).as_posix()]
    return solution_paths_dict

The only difference is in the second to last line, I added [] around the solution.

from adventofcode.

Rietty avatar Rietty commented on July 23, 2024

Perfect, thank you so much!

from adventofcode.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.