Python calendar.month_abbr() Examples
The following are 30
code examples of calendar.month_abbr().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
calendar
, or try the search function
.
Example #1
Source File: utils.py From MachineLearningSamples-BiomedicalEntityExtraction with MIT License | 6 votes |
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)
Example #2
Source File: dynamical_imaging.py From eht-imaging with GNU General Public License v3.0 | 6 votes |
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))
Example #3
Source File: dynamical_imaging.py From eht-imaging with GNU General Public License v3.0 | 6 votes |
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))
Example #4
Source File: htmlreportcreator.py From repostat with GNU General Public License v3.0 | 6 votes |
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))]
Example #5
Source File: stormtypes.py From synapse with Apache License 2.0 | 6 votes |
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
Example #6
Source File: cron.py From synapse with Apache License 2.0 | 6 votes |
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
Example #7
Source File: utils.py From pubmed_parser with MIT License | 6 votes |
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)
Example #8
Source File: events.py From uqcsbot with MIT License | 6 votes |
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 ''}"
Example #9
Source File: _strptime.py From canape with GNU General Public License v3.0 | 5 votes |
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
Example #10
Source File: _strptime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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
Example #11
Source File: month_setbuilder.py From aws-instance-scheduler with Apache License 2.0 | 5 votes |
def __init__(self, wrap=True, ignorecase=True): """ Initializes set builder for month sets :param wrap: Set to True to allow wrapping at last month of the year :param ignorecase: Set to True to ignore case when mapping month names """ SetBuilder.__init__(self, names=calendar.month_abbr[1:], significant_name_characters=3, offset=1, ignorecase=ignorecase, wrap=wrap)
Example #12
Source File: _strptime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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
Example #13
Source File: test_tools.py From twitter-stock-recommendation with MIT License | 5 votes |
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
Example #14
Source File: _strptime.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #15
Source File: _strptime.py From android_universal with MIT License | 5 votes |
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
Example #16
Source File: _strptime.py From unity-python with MIT License | 5 votes |
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
Example #17
Source File: _strptime.py From PokemonGo-DesktopMap with MIT License | 5 votes |
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
Example #18
Source File: test_tools.py From coffeegrindsize with MIT License | 5 votes |
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
Example #19
Source File: _strptime.py From datafari with Apache License 2.0 | 5 votes |
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
Example #20
Source File: server.py From VideoHub with MIT License | 5 votes |
def return_date(video_ID): """ - Returns the upload date of the video with the corresponding video ID. """ if request.method == 'GET': upload_date = str(db.get_upload_date(video_ID)) vid_date = upload_date.split("-") month = calendar.month_abbr[int(vid_date[1])] video_upload_date = "{} {}, {}".format(month, vid_date[2], vid_date[0]) return video_upload_date
Example #21
Source File: _strptime.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
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
Example #22
Source File: test_tools.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_to_datetime_format_microsecond(self): # 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) exp = datetime.strptime(val, format) assert result == exp
Example #23
Source File: calendar.py From choochoo with GNU General Public License v2.0 | 5 votes |
def _add_labels(plot, start, finish, xlo, xhi, yhi, border_day, delta_year): for y in range(start.year, finish.year+1): plot.add_layout(Label(x=xhi + 1.1, y=(start.year - y - 0.4) * delta_year, text=str(y), text_align='center', text_baseline='bottom', angle=3*pi/2)) for d, text in enumerate(day_abbr): plot.add_layout(Label(x=xlo - 1.5, y=(start.year - y) * delta_year - d * (1 + border_day), text=text, text_align='right', text_baseline='middle', text_font_size='7pt', text_color='grey')) dx = (xhi - xlo) / 12 for m, text in enumerate(month_abbr[1:]): plot.add_layout(Label(x=xlo + dx * (m + 0.5), y=yhi + 1.5, text=text, text_align='center', text_baseline='bottom')) plot.toolbar.logo = None
Example #24
Source File: _strptime.py From medicare-demo with Apache License 2.0 | 5 votes |
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
Example #25
Source File: _strptime.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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
Example #26
Source File: Demo_Desktop_Widget_Email_Notification.py From PySimpleGUI with GNU Lesser General Public License v3.0 | 5 votes |
def read_mail(window): """ Reads late emails from IMAP server and displays them in the Window :param window: window to display emails in :return: """ mail = imaplib.IMAP4_SSL(IMAP_SERVER) (retcode, capabilities) = mail.login(LOGIN_EMAIL, LOGIN_PASSWORD) mail.list() typ, data = mail.select('Inbox') n = 0 now = datetime.now() # get messages from today search_string = '(SENTON {}-{}-{})'.format(now.day, calendar.month_abbr[now.month], now.year) (retcode, messages) = mail.search(None, search_string) if retcode == 'OK': # message numbers are separated by spaces, turn into list msg_list = messages[0].split() msg_list.sort(reverse=True) # sort messages descending for n, message in enumerate(msg_list): if n >= MAX_EMAILS: break from_elem = window['{}from'.format(n)] date_elem = window['{}date'.format(n)] from_elem.update('') # erase them so you know they're changing date_elem.update('') window.refresh() typ, data = mail.fetch(message, '(RFC822)') for response_part in data: if isinstance(response_part, tuple): original = email.message_from_bytes(response_part[1]) date_str = original['Date'][:22] from_elem.update(original['From']) date_elem.update(date_str) window.refresh() # make the window changes show up right away
Example #27
Source File: month_setbuilder.py From aws-ops-automator with Apache License 2.0 | 5 votes |
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)
Example #28
Source File: views.py From hawthorne with GNU Lesser General Public License v3.0 | 5 votes |
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)
Example #29
Source File: _strptime.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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
Example #30
Source File: Demo_Desktop_Widget_Email_Notification.py From PySimpleGUI with GNU Lesser General Public License v3.0 | 5 votes |
def read_mail(window): """ Reads late emails from IMAP server and displays them in the Window :param window: window to display emails in :return: """ mail = imaplib.IMAP4_SSL(IMAP_SERVER) (retcode, capabilities) = mail.login(LOGIN_EMAIL, LOGIN_PASSWORD) mail.list() typ, data = mail.select('Inbox') n = 0 now = datetime.now() # get messages from today search_string = '(SENTON {}-{}-{})'.format(now.day, calendar.month_abbr[now.month], now.year) (retcode, messages) = mail.search(None, search_string) if retcode == 'OK': msg_list = messages[0].split() # message numbers are separated by spaces, turn into list msg_list.sort(reverse=True) # sort messages descending for n, message in enumerate(msg_list): if n >= MAX_EMAILS: break from_elem = window.FindElement('{}from'.format(n)) date_elem = window.FindElement('{}date'.format(n)) from_elem.Update('') # erase them so you know they're changing date_elem.Update('') window.Refresh() typ, data = mail.fetch(message, '(RFC822)') for response_part in data: if isinstance(response_part, tuple): original = email.message_from_bytes(response_part[1]) date_str = original['Date'][:22] from_elem.Update(original['From']) date_elem.Update(date_str) window.Refresh() # make the window changes show up right away