当前位置: 首页>>代码示例>>Python>>正文


Python calendar.month_abbr方法代码示例

本文整理汇总了Python中calendar.month_abbr方法的典型用法代码示例。如果您正苦于以下问题:Python calendar.month_abbr方法的具体用法?Python calendar.month_abbr怎么用?Python calendar.month_abbr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在calendar的用法示例。


在下文中一共展示了calendar.month_abbr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_data

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def handle_data(self,data):
        ds = data.split(' ')
        lds = len(ds)
        if ds[lds-1].isdigit():
            if lds == 3 or lds == 4:
                day = str(ds[lds-3])
                month = str(ds[lds-2])
                year = str(ds[lds-1])
                if len(day) == 1:
                    day = '0' + day
                month = month[0:3]
                monthNum = str(list(calendar.month_abbr).index(month))
                if len(monthNum) == 1:
                    monthNum = '0' + monthNum
                newDate = year +monthNum + day
                self.dates.append(str(newDate)) 
开发者ID:achael,项目名称:eht-imaging,代码行数:18,代码来源:dynamical_imaging.py

示例2: month_or_day_formater

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def month_or_day_formater(month_or_day):
    """
    Parameters
    ----------
    month_or_day: str or int
        must be one of the following:
            (i)  month: a three letter month abbreviation, e.g., 'Jan'.
            (ii) day: an integer.

    Returns
    -------
    numeric: str
        a month of the form 'MM' or a day of the form 'DD'.
        Note: returns None if:
            (a) the input could not be mapped to a known month abbreviation OR
            (b) the input was not an integer (i.e., a day).
    """
    if month_or_day.replace(".", "") in filter(None, calendar.month_abbr):
        to_format = strptime(month_or_day.replace(".", ""), "%b").tm_mon
    elif month_or_day.strip().isdigit() and "." not in str(month_or_day):
        to_format = int(month_or_day.strip())
    else:
        return None

    return ("0" if to_format < 10 else "") + str(to_format) 
开发者ID:titipata,项目名称:pubmed_parser,代码行数:27,代码来源:utils.py

示例3: __str__

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def __str__(self):
        d1 = self.start.astimezone(BRISBANE_TZ)
        d2 = self.end.astimezone(BRISBANE_TZ)

        start_str = (f"{day_abbr[d1.weekday()].upper()}"
                     + f" {month_abbr[d1.month].upper()} {d1.day} {d1.hour}:{d1.minute:02}")
        if (d1.month, d1.day) != (d2.month, d2.day):
            end_str = (f"{day_abbr[d2.weekday()].upper()}"
                       + f" {month_abbr[d2.month].upper()} {d2.day} {d2.hour}:{d2.minute:02}")
        else:
            end_str = f"{d2.hour}:{d2.minute:02}"

        # Encode user-provided text to prevent certain characters
        # being interpreted as slack commands.
        summary_str = Event.encode_text(self.summary)
        location_str = Event.encode_text(self.location)

        if self.link is None:
            return f"{'*' if self.source == 'UQCS' else ''}" \
                   f"`{summary_str}`" \
                   f"{'*' if self.source == 'UQCS' else ''}\n" \
                   f"*{start_str} - {end_str}* {'_(' + location_str + ')_' if location_str else ''}"
        else:
            return f"`<{self.link}|{summary_str}>`\n" \
                   f"*{start_str} - {end_str}* {'_(' + location_str + ')_' if location_str else ''}" 
开发者ID:UQComputingSociety,项目名称:uqcsbot,代码行数:27,代码来源:events.py

示例4: month_or_day_formater

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def month_or_day_formater(month_or_day):
    """
    Parameters
    ----------
    month_or_day: str or int
        must be one of the following:
            (i)  month: a three letter month abbreviation, e.g., 'Jan'.
            (ii) day: an integer.

    Returns
    -------
    numeric: str
        a month of the form 'MM' or a day of the form 'DD'.
        Note: returns None if:
            (a) the input could not be mapped to a known month abbreviation OR
            (b) the input was not an integer (i.e., a day).
    """
    if month_or_day.replace(".", "") in filter(None, calendar.month_abbr):
        to_format = strptime(month_or_day.replace(".", ""),'%b').tm_mon
    elif month_or_day.strip().isdigit() and "." not in str(month_or_day):
        to_format = int(month_or_day.strip())
    else:
        return None

    return ("0" if to_format < 10 else "") + str(to_format) 
开发者ID:Azure-Samples,项目名称:MachineLearningSamples-BiomedicalEntityExtraction,代码行数:27,代码来源:utils.py

示例5: __init__

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def __init__(self, config: Configuration, repository: GitRepository):
        self.path = None
        self.configuration = config
        self.assets_path = os.path.join(HERE, self.assets_subdir)
        self.git_repository_statistics = repository
        self.has_tags_page = config.do_process_tags()
        self._time_sampling_interval = "W"
        self._do_generate_index_page = False
        self._is_blame_data_allowed = False
        self._max_orphaned_extensions_count = 0

        templates_dir = os.path.join(HERE, self.templates_subdir)
        self.j2_env = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True)
        self.j2_env.filters['to_month_name_abr'] = lambda im: calendar.month_abbr[im]
        self.j2_env.filters['to_weekday_name'] = lambda i: calendar.day_name[i]
        self.j2_env.filters['to_ratio'] = lambda val, max_val: (float(val) / max_val) if max_val != 0 else 0
        self.j2_env.filters['to_percentage'] = lambda val, max_val: (100 * float(val) / max_val) if max_val != 0 else 0
        colors = colormaps.colormaps[self.configuration['colormap']]
        self.j2_env.filters['to_heatmap'] = lambda val, max_val: "%d, %d, %d" % colors[int(float(val) / max_val * (len(colors) - 1))] 
开发者ID:vifactor,项目名称:repostat,代码行数:21,代码来源:htmlreportcreator.py

示例6: _parseReq

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def _parseReq(self, requnit, reqval):
        ''' Parse a non-day fixed value '''
        assert reqval[0] != '='

        try:
            retn = []
            for val in reqval.split(','):
                if requnit == 'month':
                    if reqval[0].isdigit():
                        retn.append(int(reqval))  # must be a month (1-12)
                    else:
                        try:
                            retn.append(list(calendar.month_abbr).index(val.title()))
                        except ValueError:
                            retn.append(list(calendar.month_name).index(val.title()))
                else:
                    retn.append(int(val))
        except ValueError:
            return None

        return retn[0] if len(retn) == 1 else retn 
开发者ID:vertexproject,项目名称:synapse,代码行数:23,代码来源:stormtypes.py

示例7: _parse_req

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def _parse_req(requnit, reqval):
        ''' Parse a non-day fixed value '''
        assert reqval[0] != '='

        try:
            retn = []
            for val in reqval.split(','):
                if requnit == 'month':
                    if reqval[0].isdigit():
                        retn.append(int(reqval))  # must be a month (1-12)
                    else:
                        try:
                            retn.append(list(calendar.month_abbr).index(val.title()))
                        except ValueError:
                            retn.append(list(calendar.month_name).index(val.title()))
                else:
                    retn.append(int(val))
        except ValueError:
            return None

        if not retn:
            return None

        return retn[0] if len(retn) == 1 else retn 
开发者ID:vertexproject,项目名称:synapse,代码行数:26,代码来源:cron.py

示例8: __init__

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def __init__(self, wrap=True, ignore_case=True):
        """
        Initializes set builder for month sets
        :param wrap: Set to True to allow wrapping at last month of the year
        :param ignore_case: Set to True to ignore case when mapping month names
        """
        SetBuilder.__init__(self,
                            names=calendar.month_abbr[1:],
                            significant_name_characters=3,
                            offset=1,
                            ignore_case=ignore_case,
                            wrap=wrap) 
开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:14,代码来源:month_setbuilder.py

示例9: test_name

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def test_name(self):
        # abbreviations
        for i, name in enumerate(calendar.month_abbr[1:]):
            self.assertEqual(MonthSetBuilder().build(name), {i + 1})
            self.assertEqual(MonthSetBuilder().build(name.lower()), {i + 1})
            self.assertEqual(MonthSetBuilder().build(name.upper()), {i + 1})

        # full names
        for i, name in enumerate(calendar.month_name[1:]):
            self.assertEqual(MonthSetBuilder().build(name), {i + 1})
            self.assertEqual(MonthSetBuilder().build(name.lower()), {i + 1})
            self.assertEqual(MonthSetBuilder().build(name.upper()), {i + 1}) 
开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:14,代码来源:test_month_setbuilder.py

示例10: __calc_month

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def __calc_month(self):
        # Set self.f_month and self.a_month using the calendar module.
        a_month = [calendar.month_abbr[i].lower() for i in range(13)]
        f_month = [calendar.month_name[i].lower() for i in range(13)]
        self.a_month = a_month
        self.f_month = f_month 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:_strptime.py

示例11: test_to_datetime_format_microsecond

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def test_to_datetime_format_microsecond(self, cache):

        # these are locale dependent
        lang, _ = locale.getlocale()
        month_abbr = calendar.month_abbr[4]
        val = '01-{}-2011 00:00:01.978'.format(month_abbr)

        format = '%d-%b-%Y %H:%M:%S.%f'
        result = to_datetime(val, format=format, cache=cache)
        exp = datetime.strptime(val, format)
        assert result == exp 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_tools.py

示例12: _get_timestamp

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def _get_timestamp():
        now_month = int(datetime.datetime.now().strftime("%m"))
        timestamp = calendar.month_abbr[now_month] + ' ' + datetime.datetime.now().strftime("%d %H:%M:%S")
        return timestamp 
开发者ID:offensive-hub,项目名称:black-widow,代码行数:6,代码来源:logger.py

示例13: get_timestamp

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def get_timestamp(date_str: str) -> datetime.timestamp:
    month_to_int = dict((v, k) for k, v in enumerate(calendar.month_abbr))
    _, month, day, _, _, year = date_str.split()
    dt = datetime(year=int(year), month=month_to_int[month], day=int(day))
    return datetime.timestamp(dt) 
开发者ID:snorkel-team,项目名称:snorkel-tutorials,代码行数:7,代码来源:utils.py

示例14: month2number

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def month2number(month):
    """Convert BibTeX or BibLateX month to numeric"""
    if len(month) <= 2:  # Assume a 1 or 2 digit numeric month has been given.
        return month.zfill(2)
    else:  # Assume a textual month has been given.
        month_abbr = month.strip()[:3].title()
        try:
            return str(list(calendar.month_abbr).index(month_abbr)).zfill(2)
        except ValueError:
            raise log.error("Please update the entry with a valid month.") 
开发者ID:sourcethemes,项目名称:academic-admin,代码行数:12,代码来源:cli.py

示例15: home

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import month_abbr [as 别名]
def home(request):
  current = datetime.datetime.now().month

  # there seems to be now way to derive a django query from another one
  with connection.cursor() as cursor:
    cursor.execute('''
      SELECT COUNT(*), `subquery`.`mo`
      FROM (SELECT `log_userconnection`.`user_id` AS `Col1`,
                   EXTRACT(MONTH FROM CONVERT_TZ(`log_userconnection`.`disconnected`, 'UTC', 'UTC')) AS `mo`,
                   COUNT(DISTINCT `log_userconnection`.`user_id`) AS `active`
            FROM `log_userconnection`
            GROUP BY `log_userconnection`.`user_id`,
                     `mo`
            ORDER BY NULL) `subquery`
      GROUP BY `subquery`.`mo`;
    ''')

    query = cursor.fetchall()

  query = {i[1]: i[0] for i in query if i[1] is not None}

  population = []
  for month in range(current, current - 12, -1):
    if month < 1:
      month += 12

    value = 0 if month not in query else query[month]
    population.append((calendar.month_abbr[month], value))

  payload = {'population': population[::-1],
             'punishments': Punishment.objects.count(),
             'users': User.objects.count(),
             'servers': Server.objects.count(),
             'actions': LogModel.objects.count()}
  return render(request, 'pages/home.pug', payload) 
开发者ID:indietyp,项目名称:hawthorne,代码行数:37,代码来源:views.py


注:本文中的calendar.month_abbr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。