コード例 #1
0
ファイル: backend.py プロジェクト: zerxis/qpanel
    def parse_asterisk(self, data):
        # convert references manager to string
        for q in data:
            for e in data[q]['entries']:
                tmp = data[q]['entries'].pop(e)
                data[q]['entries'][str(e)] = tmp
                tmp = data[q]['entries'][str(e)]['Channel']
                data[q]['entries'][str(e)]['Channel'] = str(tmp)
            for m in data[q]['members']:
                member = data[q]['members'][m]
                # Asterisk 1.8 dont have StateInterface
                if 'StateInterface' not in member:
                    member['StateInterface'] = m

                member['LastCallAgo'] = format_timedelta(
                    timedelta_from_field_dict('LastCall', member),
                    granularity='second')
                # Time last pause
                member['LastPauseAgo'] = format_timedelta(
                    timedelta_from_field_dict('LastPause', member),
                    granularity='second')

                # introduced in_call flag
                # asterisk commit 90b06d1a3cc14998cd2083bd0c4c1023c0ca7a1f
                if 'InCall' in member and member['InCall'] == '1':
                    member['Status'] = '10'

            for c in data[q]['entries']:
                data[q]['entries'][c]['WaitAgo'] = format_timedelta(
                    timedelta_from_field_dict('Wait',
                                              data[q]['entries'][c], True),
                    granularity='second')

        return data
コード例 #2
0
ファイル: backend.py プロジェクト: pathcl/qpanel
    def parse_asterisk(self, data):
        # convert references manager to string
        for q in data:
            for e in data[q]['entries']:
                tmp = data[q]['entries'].pop(e)
                data[q]['entries'][str(e)] = tmp
                tmp = data[q]['entries'][str(e)]['Channel']
                data[q]['entries'][str(e)]['Channel'] = str(tmp)
            for m in data[q]['members']:
                member = data[q]['members'][m]
                # Asterisk 1.8 dont have StateInterface
                if 'StateInterface' not in member:
                    member['StateInterface'] = m

                member['LastCallAgo'] = format_timedelta(
                    timedelta_from_field_dict('LastCall', member),
                    granularity='second')
                # Time last pause
                member['LastPauseAgo'] = format_timedelta(
                    timedelta_from_field_dict('LastPause', member),
                    granularity='second')

                # introduced in_call flag
                # asterisk commit 90b06d1a3cc14998cd2083bd0c4c1023c0ca7a1f
                if 'InCall' in member and member['InCall'] == '1':
                    member['Status'] = '10'

            for c in data[q]['entries']:
                data[q]['entries'][c]['WaitAgo'] = format_timedelta(
                    timedelta_from_field_dict('Wait',
                                              data[q]['entries'][c], True),
                    granularity='second')

        return data
コード例 #3
0
ファイル: backend.py プロジェクト: alexcr-telecom/qpanel
    def parse_fs(self, data):
        for q in data:
            for m in data[q]['members']:
                member = data[q]['members'][m]
                member['LastBridgeEndAgo'] = format_timedelta(timedelta_from_field_dict('LastBridgeEnd', member), granularity='second')
                member['LastStatusChangeAgo'] = format_timedelta(timedelta_from_field_dict('LastStatusChange', member), granularity='second')

            for c in data[q]['entries']:
                data[q]['entries'][c]['CreatedEpochAgo'] = format_timedelta(timedelta_from_field_dict('CreatedEpoch', data[q]['entries'][c]), granularity='second')

        return data
コード例 #4
0
ファイル: coffeebot.py プロジェクト: taybenlor/ncss-coffeerun
def list_runs(slackclient, user, channel, match):
    """Handle the 'open runs' command.

  This command only displays the open runs. If there are multiple runs
  currently open, it orders them by time (on the assumption that you want
  things in the first available run).

  Args:
    slackclient: the slackclient.SlackClient object for the current
      connection to Slack.
    user: the slackclient.User object for the user who send the
      message to us.
    channel: the slackclient.Channel object for the channel the
      message was received on.
    match: the object returned by re.match (an _sre.SRE_Match object).
  """
    now = sydney_timezone_now()
    q = Run.query.filter_by(is_open=True).order_by('time').all()
    if not q:
        channel.send_message('No open runs')
        return (True, None)
    for run in q:
        person = User.query.filter_by(id=run.person).first()
        time_to_run = run.time - now
        channel.send_message('Run {}: {} is going to {} in {} (at {})'.format(
            run.id, person.name, run.cafe.name,
            flask_babel.format_timedelta(time_to_run), run.time))
    return (True, None)
コード例 #5
0
def dashboard():
    last_cons, now = {}, datetime.utcnow()
    users = list(UserController().read().order_by('id'))
    form = InformationMessageForm()
    for user in users:
        last_cons[user.id] = format_timedelta(now - user.last_seen)
    return render_template('admin/dashboard.html', now=datetime.utcnow(),
            last_cons=last_cons, users=users, current_user=current_user,
            form=form)
コード例 #6
0
ファイル: backend.py プロジェクト: zerxis/qpanel
    def parse_fs(self, data):
        for q in data:
            for m in data[q]['members']:
                member = data[q]['members'][m]
                member['LastBridgeEndAgo'] = format_timedelta(
                    timedelta_from_field_dict('LastBridgeEnd', member),
                    granularity='second')
                member['LastStatusChangeAgo'] = format_timedelta(
                    timedelta_from_field_dict('LastStatusChange', member),
                    granularity='second')

            for c in data[q]['entries']:
                data[q]['entries'][c]['CreatedEpochAgo'] = format_timedelta(
                    timedelta_from_field_dict('CreatedEpoch',
                                              data[q]['entries'][c]),
                    granularity='second')

        return data
コード例 #7
0
def dashboard():
    last_cons, now = {}, datetime.utcnow()
    users = list(UserController().read().order_by('id'))
    form = InformationMessageForm()
    for user in users:
        last_cons[user.id] = format_timedelta(now - user.last_seen)
    return render_template('admin/dashboard.html',
                           now=datetime.utcnow(),
                           last_cons=last_cons,
                           users=users,
                           current_user=current_user,
                           form=form)
コード例 #8
0
ファイル: tests.py プロジェクト: python-babel/flask-babel
    def test_basics(self):
        app = flask.Flask(__name__)
        babel.Babel(app)
        d = datetime(2010, 4, 12, 13, 46)
        delta = timedelta(days=6)

        with app.test_request_context():
            assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00 PM'
            assert babel.format_date(d) == 'Apr 12, 2010'
            assert babel.format_time(d) == '1:46:00 PM'
            assert babel.format_timedelta(delta) == '1 week'
            assert babel.format_timedelta(delta, threshold=1) == '6 days'

        with app.test_request_context():
            app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Vienna'
            assert babel.format_datetime(d) == 'Apr 12, 2010, 3:46:00 PM'
            assert babel.format_date(d) == 'Apr 12, 2010'
            assert babel.format_time(d) == '3:46:00 PM'

        with app.test_request_context():
            app.config['BABEL_DEFAULT_LOCALE'] = 'de_DE'
            assert babel.format_datetime(d, 'long') == \
                '12. April 2010 um 15:46:00 MESZ'
コード例 #9
0
ファイル: tests.py プロジェクト: quantus/flask-babel
    def test_basics(self):
        app = flask.Flask(__name__)
        babel.Babel(app)
        d = datetime(2010, 4, 12, 13, 46)
        delta = timedelta(days=6)

        with app.test_request_context():
            assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00 PM'
            assert babel.format_date(d) == 'Apr 12, 2010'
            assert babel.format_time(d) == '1:46:00 PM'
            assert babel.format_timedelta(delta) == '1 week'
            assert babel.format_timedelta(delta, threshold=1) == '6 days'

        with app.test_request_context():
            app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Vienna'
            assert babel.format_datetime(d) == 'Apr 12, 2010, 3:46:00 PM'
            assert babel.format_date(d) == 'Apr 12, 2010'
            assert babel.format_time(d) == '3:46:00 PM'

        with app.test_request_context():
            app.config['BABEL_DEFAULT_LOCALE'] = 'de_DE'
            assert babel.format_datetime(d, 'long') == \
                '12. April 2010 um 15:46:00 MESZ'
コード例 #10
0
def localised_nice_date(datetime_: datetime.datetime,
                        show_date: bool = False,
                        with_hours: bool = False,
                        with_seconds: bool = False,
                        format: Optional[str] = None) -> str:
    ''' Returns a friendly localised unicode representation of a datetime.
    e.g. '31 minutes ago'
         '1 day ago'
         'April 24, 2013'  (show_date=True)
         'October 25, 2017, 16:03 (UTC)' (show_date=True, with_hours=True)
         'Apr 3, 2020, 4:00:31 PM' (
                 show_date=True, with_hours=True, format='medium')
         'April 03, 20' (show_date=True, format='MMMM dd, YY')

    :param datetime_: The date to format
    :type datetime_: datetime
    :param show_date: Show 'April 24, 2013' instead of '2 days ago'
    :type show_date: bool
    :param with_hours: should the `hours:mins` be shown for dates
    :type with_hours: bool
    :param with_seconds: should the `hours:mins:seconds` be shown for dates
    :type with_seconds: bool
    :param format: override format of datetime representation using babel
        date/time pattern syntax of predefined pattern.
    :type format: str


    :rtype: sting
    '''
    if datetime_.tzinfo is None:
        datetime_ = datetime_.replace(tzinfo=pytz.utc)
    if not show_date:
        now = datetime.datetime.now(pytz.utc)
        date_diff = datetime_ - now
        if abs(date_diff) < datetime.timedelta(seconds=1):
            return _('Just now')
        return format_timedelta(date_diff, add_direction=True)

    if with_seconds:
        return format_datetime(datetime_, format or 'long')
    elif with_hours:
        fmt_str = "MMMM d, YYYY, HH:mm (z)"
        return format_datetime(datetime_, format or fmt_str)
    else:
        return format_date(datetime_, format or 'long')
コード例 #11
0
ファイル: filters.py プロジェクト: chokribr/invenio-1
def filter_format_timedelta(dt, format=None, rebase=True):
    """Return a date formatted according to the given pattern."""
    return format_timedelta(dt, format=format, rebase=rebase)
コード例 #12
0
ファイル: template_filters.py プロジェクト: xenonca/contentdb
def datetime(value):
    delta = dt.utcnow() - value
    if delta.days == 0:
        return gettext("%(delta)s ago", delta=format_timedelta(value))
    else:
        return full_datetime(value)
コード例 #13
0
def duration_to_str(previous_date):
    time_delta = datetime.utcnow() - previous_date
    delta_str = format_timedelta(time_delta)
    return '{} trước'.format(delta_str)
コード例 #14
0
 def last_updated_timedelta(self):
     now = datetime.now(tz=timezone.utc)
     last_updated = self.last_updated.astimezone(tz=timezone.utc)
     return format_timedelta(now - last_updated)
コード例 #15
0
ファイル: filters.py プロジェクト: SCOAP3/invenio
def filter_format_timedelta(dt, format=None, rebase=True):
    """Return a date formatted according to the given pattern."""
    return format_timedelta(dt, format=format, rebase=rebase)
コード例 #16
0
ファイル: app.py プロジェクト: gunsch/brackets
def format_datetime(time):
  delta = datetime.now() - time
  return flask_babel.format_timedelta(delta, granularity = 'minute')
コード例 #17
0
def datetime(value):
	delta = dt.utcnow() - value
	if delta.days == 0:
		return gettext("%(delta)s ago", delta=format_timedelta(value))
	else:
		return value.strftime("%Y-%m-%d %H:%M") + " UTC"
コード例 #18
0
def format_to_hours(t):
    result = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
    return format_timedelta(result)
コード例 #19
0
 def humanformat(value):
     # return human(value, precision=1)
     return gettext("Posted %(ago)s ago", ago=format_timedelta(value, granularity="second"))
コード例 #20
0
ファイル: formats.py プロジェクト: jctt1983/PythonBlog
def humanformat(eval_ctx, value):
    if not value:
        return ''

    return _('APP_PUBLISHED_AGO', ago=format_timedelta(value, granularity='second'))
コード例 #21
0
ファイル: template_filters.py プロジェクト: xenonca/contentdb
def timedelta(value):
    return format_timedelta(value)
コード例 #22
0
def humanformat(eval_ctx, value):
    if not value:
        return ''

    return gettext('APP_PUBLISHED_AGO',
                   ago=format_timedelta(value, granularity='second'))
コード例 #23
0
 def format_timedelta(dt, **kwargs):
     return flask_babel.format_timedelta(dt, **kwargs)