def timeinterval(v, key=None): # this import is at function level because it relies on the cythonized # modules being present which is a problem for plugin __init__s that # use this module since they are imported in the early stages of the # makefile from r2.lib.utils import timeinterval_fromstr return timeinterval_fromstr(v)
def check_account_thresholds(self, account, data): """Check karma/age thresholds against an account.""" thresholds = ["comment_karma", "link_karma", "combined_karma", "account_age"] # figure out which thresholds/values we need to check against checks = {} for threshold in thresholds: compare_value = getattr(self, threshold, None) if compare_value is not None: checks[threshold] = compare_value # if we don't need to actually check anything, just return True if not checks: return True # banned accounts should never satisfy threshold checks if account._spam: return False for check, compare_value in checks.iteritems(): match = re.match(self._operator_regex, compare_value) if match: operator = match.group(1) compare_value = compare_value[len(operator) :].strip() if not match or operator == "==": operator = "=" # special handling for time period comparison value if check == "account_age": # if it's just a number, default to days try: compare_value = int(compare_value) compare_value = "%s days" % compare_value except ValueError: pass compare_value = timeinterval_fromstr(compare_value) else: compare_value = int(compare_value) value = self.get_field_value_from_item(account, data, check) if operator == "<": result = value < compare_value elif operator == ">": result = value > compare_value elif operator == "=": result = value == compare_value # if satisfy_any_threshold is True, we can return True as soon # as a single check is successful. If it's False, they all need # to be satisfied, so we can return False as soon as one fails. if result == self.satisfy_any_threshold: return result # if we make it to here, the return statement inside the loop was # never triggered, so that means that if satisfy_any_threshold is # True, all the checks must have been False, and if it's False # they all must have been True return not self.satisfy_any_threshold
def timeinterval(v, key=None, data=None): return timeinterval_fromstr(v)