Giter Site home page Giter Site logo

Comments (2)

mtshrmn avatar mtshrmn commented on June 11, 2024

Currently, this is the implementation:

def generate_episode_filter(episodes):
    """
    parse the episode specification string to generate a filter function.
    read the docs for understanding the syntax.
    :param episodes: the episode specification string
    :return: filter function for the episodes
    """
    # if no episodes where specified - the generated filter should return false.
    if not episodes:
        def default_filter():
            return False
        return default_filter

    parsed = []
    for token in episodes.split(","):
        sub = token.split("-")
        bounds = float(sub[0]), float(sub[int(len(sub) is 2)])
        parsed.append(bounds)

    def generated_filter(episode):
        return any(map(lambda bound: bound[0] <= float(episode["episode"]) <= bound[1], parsed))

    return generated_filter

I believe that introducing regex solely for this would be over engineering the solution.

from horrible-downloader.

mariogarcc avatar mariogarcc commented on June 11, 2024

I understand writing that whole thing into that small code that actually works for the current state of the program may be a bit ugly, but here's my honest opinion. Although I'm not very good nor experienced at Python, after reading through the whole code, that part of it that you just showed me with lines 108 and 109 are the ones I understand the least (all those filters seem to me that are just a short way to make some exclusive comparisons, but to me are still non-inmediate). I see you know what you're doing, but maybe you're also trying too hard there to keep code extremely short at the cost of readability (and possibly functionality as well, about what we're mentioning).

I repeat, I really don't understand exactly everything that code is doing, but I kind of can see what you're going for and I think adding some lines of code to make everything more readable and even add more functionality would be a good idea. I'm not saying my implementation is the best - I'm sure you can find a better way to put it there in less or more organized lines - but it doesn't look like over engineering to me, even less when there's no current solution to compare it to.

from horrible-downloader.

Related Issues (20)

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.