Code Monkey home page Code Monkey logo

Comments (5)

amoffat avatar amoffat commented on July 19, 2024

It's a good idea. I had considered this, but there is the problem of how to include the decorators in the blacklist file. If the decorator definition wasn't embedded directly into the focus_blacklist.py, it would need to be imported from somewhere obvious. It makes the learning curve a little steeper for writing rules.

One thing I should probably document better is that this:

def domain_somedomain_com(dt): return True

would match *.somedomain.com. You can write more specific subdomain functions to whitelist/blacklist specific subdomains, and then have a catch-all function for the entire domain. The way I had figured it, regexes would be mainly for matching subdomains, so doing this would eliminate the need for 99% of the regexes.

from focus.

eric-wieser avatar eric-wieser commented on July 19, 2024

Can't you just run the blacklist code in the scope of the main program? I'm not too experienced with execfile, but wouldn't this work?

#Define the decorator
allRules = {}
def domainfilter(regex):
    def decorator(f):
        allRules[regex] = f
        return f

def loadConfig():
    allRules.clear()
    execfile('focus_blacklist.py', {"domainfilter": domainfilter})

from focus.

amoffat avatar amoffat commented on July 19, 2024

Yeah that would. I still think that the learning curve cost / benefit ratio of adding it is high though, since the current implementation handles most of what regexes would be used for. I'll leave this issue open though and see if anyone else wants to weigh in.

from focus.

eric-wieser avatar eric-wieser commented on July 19, 2024

Perhaps have two decorators? I agree that forcing users to use regex isn't the right way to go. A solution would be to have one decorator for your current behaviour:

@focus.filter("facebook.com")
def stopMeFacebooking(dt):
    return 12 >= dt.hour >= 14

And then something like one of these for regex behaviour:

@focus.filter.regex(r".*\.co.uk")
def ignoreEngland(dt, groups):
    return dt.hour % 2 == 0
@focus.filter(regex = r".*\.co.uk")
def ignoreEngland(dt, groups):
    return dt.hour % 2 == 0
@focus.regexFilter(r".*\.co.uk")
def ignoreEngland(dt, groups):
    return dt.hour % 2 == 0

from focus.

amoffat avatar amoffat commented on July 19, 2024

As it stands, I'll have to vote no. Regexes aren't necessary in the current scheme (for most of the uses), so the regex decorators are out. That leaves the regular focus.filter decorator, which, to me, seems to be just another step that doesn't gain much. The gains of the decorator is that it allows for arbitrary domain names easily...domains with weird characters, etc, that would have to be filtered out of a function name. The drawbacks are that it's another piece for users to learn and it's another line to write that feels redundant.

from focus.

Related Issues (10)

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.