Commit a5f04d41 authored by Romain Bignon's avatar Romain Bignon

Revert "Revert "Allow ResultsCondition to compare timedelta""

This reverts commit 780ffa98.
parent 13720861
Pipeline #2037 passed with stages
in 16 minutes and 25 seconds
...@@ -173,7 +173,7 @@ def analyze_application(app, script_name): ...@@ -173,7 +173,7 @@ def analyze_application(app, script_name):
script_name, app.VERSION.replace('.', '\\&.')) script_name, app.VERSION.replace('.', '\\&.'))
name = ".SH NAME\n%s \- %s" % (script_name, application.SHORT_DESCRIPTION) name = ".SH NAME\n%s \- %s" % (script_name, application.SHORT_DESCRIPTION)
condition = """.SH CONDITION condition = """.SH CONDITION
The \-c and \-\-condition is a flexible way to filter and get only interesting results. It supports conditions on numerical values, dates, and strings. Dates are given in YYYY\-MM\-DD or YYYY\-MM\-DD HH:MM format. The \-c and \-\-condition is a flexible way to filter and get only interesting results. It supports conditions on numerical values, dates, durations and strings. Dates are given in YYYY\-MM\-DD or YYYY\-MM\-DD HH:MM format. Durations look like XhYmZs where X, Y and Z are integers. Any of them may be omitted. For instance, YmZs, XhZs or Ym are accepted.
The syntax of one expression is "\\fBfield operator value\\fR". The field to test is always the left member of the expression. The syntax of one expression is "\\fBfield operator value\\fR". The field to test is always the left member of the expression.
.LP .LP
The field is a member of the objects returned by the command. For example, a bank account has "balance", "coming" or "label" fields. The field is a member of the objects returned by the command. For example, a bank account has "balance", "coming" or "label" fields.
......
...@@ -100,7 +100,8 @@ class ResultsCondition(IResultsCondition): ...@@ -100,7 +100,8 @@ class ResultsCondition(IResultsCondition):
def is_valid(self, obj): def is_valid(self, obj):
import weboob.tools.date as date_utils import weboob.tools.date as date_utils
from datetime import date, datetime import re
from datetime import date, datetime, timedelta
d = obj.to_dict() d = obj.to_dict()
# We evaluate all member of a list at each iteration. # We evaluate all member of a list at each iteration.
for _or in self.condition: for _or in self.condition:
...@@ -123,6 +124,12 @@ class ResultsCondition(IResultsCondition): ...@@ -123,6 +124,12 @@ class ResultsCondition(IResultsCondition):
splitted_datetime = condition.right.split(' ') splitted_datetime = condition.right.split(' ')
tocompare = datetime(*([int(x) for x in splitted_datetime[0].split('-')] + tocompare = datetime(*([int(x) for x in splitted_datetime[0].split('-')] +
[int(x) for x in splitted_datetime[1].split(':')])) [int(x) for x in splitted_datetime[1].split(':')]))
elif isinstance(d[condition.left], timedelta):
time_dict = re.match('^\s*((?P<hours>\d+)\s*h)?\s*((?P<minutes>\d+)\s*m)?\s*((?P<seconds>\d+)\s*s)?\s*$',
condition.right).groupdict()
tocompare = timedelta(seconds=int(time_dict['seconds'] or "0"),
minutes=int(time_dict['minutes'] or "0"),
hours=int(time_dict['hours'] or "0"))
else: else:
tocompare = typed(condition.right) tocompare = typed(condition.right)
myeval = functions[condition.op](tocompare, d[condition.left]) myeval = functions[condition.op](tocompare, d[condition.left])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment