def calendar_info(self): weekday = time.strftime("%A") month = time.strftime("%B") date = int(time.strftime("%e")) c = calendar.LocaleHTMLCalendar() q = c.formatmonth(int(time.strftime('%Y')), int(time.strftime('%m'))).replace('\n', '') month_table_temp = q.replace('padding="0"', 'padding="2"') month_table_temp = month_table_temp.replace('td class="', 'td align="right" class="') today = time.strftime("%e").strip() j = len(today) + 1 x = month_table_temp.find('>' + today + '<') if x != -1: month_table = month_table_temp[:x + 1] \ + '<span style="font-weight:bold;color:yellow;">' \ + today + '</span>' + month_table_temp[x + j:] else: month_table = month_table_temp outstring_calendar = '<table align="center" cellspacing="2">\ <tr><td align="center" style="font-size:16pt;font-weight:bold;color:white;">' \ + weekday + ' ' + str(date) + ' ' + month + '</td></tr><tr align="center"><td align="center">' + month_table + '</td></tr></table>' with open(os.path.expanduser('~/.local/share/skutter/calendar'), 'w') as f: f.write(outstring_calendar)
def get(self): print("getが通りました") now = datetime.datetime.now() thismonth = now.month nextmonth = thismonth + 1 thisyear = now.year pycalendar = calendar.LocaleHTMLCalendar(0).formatmonth(thisyear, nextmonth, withyear=True) self.render('index.html', pycalendar=pycalendar)
def test_locale_html_calendar_custom_css_class_weekday(self): try: cal = calendar.LocaleHTMLCalendar(locale='') local_weekday = cal.formatweekday(6) except locale.Error: # cannot set the system default locale -- skip rest of test raise unittest.SkipTest('cannot set the system default locale') self.assertIn('class="sun"', local_weekday) cal.cssclasses_weekday_head = ["mon2", "tue2", "wed2", "thu2", "fri2", "sat2", "sun2"] local_weekday = cal.formatweekday(6) self.assertIn('class="sun2"', local_weekday)
def test_locale_html_calendar_custom_css_class_month_name(self): try: cal = calendar.LocaleHTMLCalendar(locale='') local_month = cal.formatmonthname(2010, 10, 10) except locale.Error: # cannot set the system default locale -- skip rest of test raise unittest.SkipTest('cannot set the system default locale') self.assertIn('class="month"', local_month) cal.cssclass_month_head = "text-center month" local_month = cal.formatmonthname(2010, 10, 10) self.assertIn('class="text-center month"', local_month)
def index(): today = date.today() if len(request.args) > 0: an = int(request.args[0]) else: an = today.year if len(request.args) > 1: luna = int(request.args[1]) else: luna = today.month intai = date(an, luna, 1) if len(request.vars): page = int(request.vars.page) else: page = 0 session.firma_id = (session.firma_id or 1) tcs = db(db.tip_concediu.id > 0) angajati_pe_pagina = 20 limitby = (page * angajati_pe_pagina, (page + 1) * angajati_pe_pagina + 1) angajati = db((db.angajat.activ == True) & (db.angajat.firma == session.firma_id)).select( orderby=db.angajat.nume | db.angajat.prenume, limitby=limitby) firma = db.firma(session.firma_id) c = calendar.Calendar() for a in angajati: if not db.pontaj((db.pontaj.angajat == a) & (db.pontaj.luna == intai)): pontaje = [] zile_lucratoare = 0 for zi in c.itermonthdays2(an, luna): if zi[0] == 0: continue # skip start and end 0s if zi[1] in (5, 6): # if weekend pontaje.append(0) else: pontaje.append(a.norma) zile_lucratoare += 1 db.pontaj.insert(angajat=a, luna=intai, zile=pontaje, concedii=[0] * tcs.count(), nr_zile_lucratoare=zile_lucratoare) ro = locale.setlocale(locale.LC_ALL, 'ro_RO') return dict(angajati=angajati, an=an, luna=luna, tcs=tcs, c=c, cal=calendar.LocaleHTMLCalendar(0, ro), nr_zile=calendar.monthrange(an, luna)[1], intai=intai, firma=firma, page=page, angajati_pe_pagina=angajati_pe_pagina, inapoi=_prev_month(intai), inainte=_next_month(intai))
def test_localecalendars(self): # ensure that Locale{Text,HTML}Calendar resets the locale properly # (it is still not thread-safe though) old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) try: calendar.LocaleTextCalendar(locale='').formatmonthname(2010, 10, 10) except locale.Error: # cannot set the system default locale -- skip rest of test return calendar.LocaleHTMLCalendar(locale='').formatmonthname(2010, 10) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEquals(old_october, new_october)
def monthly_cal(): """ Creates a monthly calendar with current date and local weekday names Reference: https://docs.python.org/3/library/calendar.html """ today = date.today() day = int(today.strftime("%d")) year = int(today.strftime("%Y")) month = int(today.strftime("%m")) c = calendar.LocaleHTMLCalendar(calendar.MONDAY, "sv_SE") cal_html = format_cal(c.formatmonth(year, month)) cal_html = cal_html.replace( f">{day}<", f"><div class='Current'>{day}</div><") # Marks the current day return cal_html
def test_locale_calendars(self): old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) try: cal = calendar.LocaleTextCalendar(locale='') local_weekday = cal.formatweekday(1, 10) local_month = cal.formatmonthname(2010, 10, 10) except locale.Error: raise unittest.SkipTest('cannot set the system default locale') self.assertIsInstance(local_weekday, str) self.assertIsInstance(local_month, str) self.assertEqual(len(local_weekday), 10) self.assertGreaterEqual(len(local_month), 10) cal = calendar.LocaleHTMLCalendar(locale='') local_weekday = cal.formatweekday(1) local_month = cal.formatmonthname(2010, 10) self.assertIsInstance(local_weekday, str) self.assertIsInstance(local_month, str) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEqual(old_october, new_october)
def test_locale_calendars(self): # ensure that Locale{Text,HTML}Calendar resets the locale properly # (it is still not thread-safe though) old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) try: cal = calendar.LocaleTextCalendar(locale='') local_weekday = cal.formatweekday(1, 10) local_month = cal.formatmonthname(2010, 10, 10) except locale.Error: # cannot set the system default locale -- skip rest of test raise unittest.SkipTest('cannot set the system default locale') self.assertIsInstance(local_weekday, str) self.assertIsInstance(local_month, str) self.assertEqual(len(local_weekday), 10) self.assertGreaterEqual(len(local_month), 10) cal = calendar.LocaleHTMLCalendar(locale='') local_weekday = cal.formatweekday(1) local_month = cal.formatmonthname(2010, 10) self.assertIsInstance(local_weekday, str) self.assertIsInstance(local_month, str) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEqual(old_october, new_october)
def _generate_calendar(self, cr, uid, year, name): #Genero el Calendario #myCal = calendar.HTMLCalendar(calendar.MONDAY) myCal = calendar.LocaleHTMLCalendar(calendar.MONDAY, 'en_US.UTF-8') myCalendar = myCal.formatyear(year, 3) # Meto el meta myCalendar2 = '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">' + myCalendar myCalendar = myCalendar2 myCalendar = myCalendar.replace(str(year), name + ' - CALENDAR: ' + str(year)) # Cambio cosas del calendario myCalendar = myCalendar.replace('January', 'ENERO') myCalendar = myCalendar.replace('February', 'FEBRERO') myCalendar = myCalendar.replace('March', 'MARZO') myCalendar = myCalendar.replace('April', 'ABRIL') myCalendar = myCalendar.replace('May', 'MAYO') myCalendar = myCalendar.replace('June', 'JUNIO') myCalendar = myCalendar.replace('July', 'JULIO') myCalendar = myCalendar.replace('August', 'AGOSTO') myCalendar = myCalendar.replace('September', 'SEPTIEMBRE') myCalendar = myCalendar.replace('October', 'OCTUBRE') myCalendar = myCalendar.replace('November', 'NOVIEMBRE') myCalendar = myCalendar.replace('December', 'DICIEMBRE') myCalendar = myCalendar.replace('Mon', 'Lun') myCalendar = myCalendar.replace('Tue', 'Mar') myCalendar = myCalendar.replace('Wed', 'Mie') myCalendar = myCalendar.replace('Thu', 'Jue') myCalendar = myCalendar.replace('Fri', 'Vie') myCalendar = myCalendar.replace('Sat', 'Sab') myCalendar = myCalendar.replace('Sun', 'Dom') # Pongo color blanco a las celdas de la tabla myCalendar = myCalendar.replace( 'td class', 'td valign="top" bgcolor="White" class') # Quito las clases myCalendar = myCalendar.replace('class="mon"', '') myCalendar = myCalendar.replace('class="tue"', '') myCalendar = myCalendar.replace('class="wed"', '') myCalendar = myCalendar.replace('class="thu"', '') myCalendar = myCalendar.replace('class="fri"', '') myCalendar = myCalendar.replace('class="sat"', '') myCalendar = myCalendar.replace('class="sun"', '') # Cambio la alineacion myCalendar = myCalendar.replace('<td>', '<td valign="top">') # Pongo en Azul los días del calendario myCalendar = myCalendar.replace( '>1<', 'align="right"><font color="blue">1</font><') myCalendar = myCalendar.replace( '>2<', 'align="right"><font color="blue">2</font><') myCalendar = myCalendar.replace( '>3<', 'align="right"><font color="blue">3</font><') myCalendar = myCalendar.replace( '>4<', 'align="right"><font color="blue">4</font><') myCalendar = myCalendar.replace( '>5<', 'align="right"><font color="blue">5</font><') myCalendar = myCalendar.replace( '>6<', 'align="right"><font color="blue">6</font><') myCalendar = myCalendar.replace( '>7<', 'align="right"><font color="blue">7</font><') myCalendar = myCalendar.replace( '>8<', 'align="right"><font color="blue">8</font><') myCalendar = myCalendar.replace( '>9<', 'align="right"><font color="blue">9</font><') myCalendar = myCalendar.replace( '>10<', 'align="right"><font color="blue">10</font><') myCalendar = myCalendar.replace( '>11<', 'align="right"><font color="blue">11</font><') myCalendar = myCalendar.replace( '>12<', 'align="right"><font color="blue">12</font><') myCalendar = myCalendar.replace( '>13<', 'align="right"><font color="blue">13</font><') myCalendar = myCalendar.replace( '>14<', 'align="right"><font color="blue">14</font><') myCalendar = myCalendar.replace( '>15<', 'align="right"><font color="blue">15</font><') myCalendar = myCalendar.replace( '>16<', 'align="right"><font color="blue">16</font><') myCalendar = myCalendar.replace( '>17<', 'align="right"><font color="blue">17</font><') myCalendar = myCalendar.replace( '>18<', 'align="right"><font color="blue">18</font><') myCalendar = myCalendar.replace( '>19<', 'align="right"><font color="blue">19</font><') myCalendar = myCalendar.replace( '>20<', 'align="right"><font color="blue">20</font><') myCalendar = myCalendar.replace( '>21<', 'align="right"><font color="blue">21</font><') myCalendar = myCalendar.replace( '>22<', 'align="right"><font color="blue">22</font><') myCalendar = myCalendar.replace( '>23<', 'align="right"><font color="blue">23</font><') myCalendar = myCalendar.replace( '>24<', 'align="right"><font color="blue">24</font><') myCalendar = myCalendar.replace( '>25<', 'align="right"><font color="blue">25</font><') myCalendar = myCalendar.replace( '>26<', 'align="right"><font color="blue">26</font><') myCalendar = myCalendar.replace( '>27<', 'align="right"><font color="blue">27</font><') myCalendar = myCalendar.replace( '>28<', 'align="right"><font color="blue">28</font><') myCalendar = myCalendar.replace( '>29<', 'align="right"><font color="blue">29</font><') myCalendar = myCalendar.replace( '>30<', 'align="right"><font color="blue">30</font><') myCalendar = myCalendar.replace( '>31<', 'align="right"><font color="blue">31</font><') # Pongo separacion entre los meses myCalendar = myCalendar.replace( '</td><td valign="top"><table', '</td><td width="10px"></td><td valign="top"><table') return myCalendar
print(hc.cssclass_noday) # noday hc_sun = calendar.HTMLCalendar(firstweekday=6) print(hc_sun.formatmonth(2019, 1)) # <table border="0" cellpadding="0" cellspacing="0" class="month"> # <tr><th colspan="7" class="month">January 2019</th></tr> # <tr><th class="sun">Sun</th><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th></tr> # <tr><td class="noday"> </td><td class="noday"> </td><td class="tue">1</td><td class="wed">2</td><td class="thu">3</td><td class="fri">4</td><td class="sat">5</td></tr> # <tr><td class="sun">6</td><td class="mon">7</td><td class="tue">8</td><td class="wed">9</td><td class="thu">10</td><td class="fri">11</td><td class="sat">12</td></tr> # <tr><td class="sun">13</td><td class="mon">14</td><td class="tue">15</td><td class="wed">16</td><td class="thu">17</td><td class="fri">18</td><td class="sat">19</td></tr> # <tr><td class="sun">20</td><td class="mon">21</td><td class="tue">22</td><td class="wed">23</td><td class="thu">24</td><td class="fri">25</td><td class="sat">26</td></tr> # <tr><td class="sun">27</td><td class="mon">28</td><td class="tue">29</td><td class="wed">30</td><td class="thu">31</td><td class="noday"> </td><td class="noday"> </td></tr> # </table> # lhc = calendar.LocaleHTMLCalendar(firstweekday=6, locale='ja_jp') print(lhc.formatmonth(2019, 1)) # <table border="0" cellpadding="0" cellspacing="0" class="month"> # <tr><th colspan="7" class="month">1月 2019</th></tr> # <tr><th class="sun">日</th><th class="mon">月</th><th class="tue">火</th><th class="wed">水</th><th class="thu">木</th><th class="fri">金</th><th class="sat">土</th></tr> # <tr><td class="noday"> </td><td class="noday"> </td><td class="tue">1</td><td class="wed">2</td><td class="thu">3</td><td class="fri">4</td><td class="sat">5</td></tr> # <tr><td class="sun">6</td><td class="mon">7</td><td class="tue">8</td><td class="wed">9</td><td class="thu">10</td><td class="fri">11</td><td class="sat">12</td></tr> # <tr><td class="sun">13</td><td class="mon">14</td><td class="tue">15</td><td class="wed">16</td><td class="thu">17</td><td class="fri">18</td><td class="sat">19</td></tr> # <tr><td class="sun">20</td><td class="mon">21</td><td class="tue">22</td><td class="wed">23</td><td class="thu">24</td><td class="fri">25</td><td class="sat">26</td></tr> # <tr><td class="sun">27</td><td class="mon">28</td><td class="tue">29</td><td class="wed">30</td><td class="thu">31</td><td class="noday"> </td><td class="noday"> </td></tr> # </table> #
# LocaleTextCalendar - позволяет вывести календарь в виде простого текста. Названия # месяцев и дней недели выводятся в соответствии с указанной локалью. Формат конструктора: # LocaleTextCalendar([<Пepвый день недели>[, <Название локали>]]) c = calendar.LocaleTextCalendar(0, "Russian_Russia.1251") print(c.formatyear(2015)) # HTМLCa.lendar - позволяет вывести календарь в формате НТМL. Формат конструктора: # НТМLСаlеndаr([<Первый день недели>]) c = calendar.HTMLCalendar(0) print(c.formatyear(2011)) # ocaleHTМLCalendar - позволяет вывести календарь в формате HTML. Названия месяцев # и дней недели выводятся в соответствии с указанной локалью. Формат конструктора: # LocaleHTМLCalendar([<Пepвый день недели>[, <Название локали>))) c = calendar.LocaleHTMLCalendar(0, "Russian_Russia.1251") xhtml = c.formatyearpage(2011, encoding="windows-1251") print(xhtml.decode("cp1251")) # Text calendar output c = calendar.LocaleTextCalendar(0, "Russian_Russia.1251") c.prmonth(2015, 4, 4) c = calendar.LocaleTextCalendar(0, "Russian_Russia.1251") print(c.formatyear(2015, m=4, c=2)) c = calendar.LocaleTextCalendar(0, "Russian_Russia.1251") c.pryear(2015, 2, 1, 4, 2) # forrnatmonth (<Год>, <Месяц> [, <True I False>] ) - возвращает календарь на указанный
<button type="button" class="btn btn-danger btn-sm m-1" data-bs-toggle="modal" data-bs-target="#deleteModalUser">Delete</button> <!-- Modal --> <div class="modal fade" id="deleteModalUser" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="deleteModalLabel">Delete User?</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <form action="{{ url_for('user.delete_person', user_id=current_user) }}" method="POST" name=""> <input class="btn btn-danger" type="submit" name="" value="Delete"> </form> </div> </div> </div> </div> # https://pythonworld.ru/moduli/modul-calendar.html import calendar a = calendar.LocaleHTMLCalendar(locale="Russian_Russia") with open('calendar.html', 'w') as g: print(a.formatyear(2014, width=4), file=g)
import calendar c = calendar.LocaleHTMLCalendar(calendar.MONDAY) strr = c.formatyear(2021)
import calendar import locale from django.template.loader import render_to_string locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8') calendar.LocaleHTMLCalendar(calendar.SUNDAY, 'pt_BR') def criar_botao(req, mostrar): return render_to_string( template_name="lab/includes/calendario_button.html", context={ "req": req, "mostrar": mostrar }) class ReqCalendario(calendar.HTMLCalendar): def __init__(self, events=None, user=None): super(ReqCalendario, self).__init__() self.setfirstweekday(calendar.SUNDAY) self.events = events.order_by('hora_inicio') self.user = user def formatday(self, day, weekday, events): """ Return a day as a table cell. """ events_from_day = events.filter(data__day=day) events_html = '<div class="container-fluid" style="max-width: 15em">'
import calendar a = calendar.LocaleHTMLCalendar(locale='Russian_Russia') with open('calendar.html', 'w') as g: print(a.formatyear(2014, width=4), file=g)
def show_calendar(request, m=1, y=2020): c = calendar.LocaleHTMLCalendar(locale='eng_gb') with open('webcalenda/templates/webcalenda/month.html', "w") as f: print(c.formatmonth(themonth=m, theyear=y, ), file=f) return render(request, 'webcalenda/month.html', {})
import calendar año = eval(input("Escribe un año: ")) calendario = calendar.LocaleHTMLCalendar(locale='') calendario.cssclasses = ["lun", "mar", "mie", "jue", "vie", "sab", "dom"] calendario.cssclass_noday = "enblanco" calendario.cssclass_month = "mes" calendario.cssclass_year = "anyo" calendario.cssclass_year_head = "anyo_h" cal = calendario.formatyearpage(año, 4, 'calendario_estilos.css') nombre = 'calendario_%s.html' % año file = open(nombre, 'wb') file.write(cal) file.close() print("Archivo '%s' creado en la misma ubicación que este programa." % nombre)
} .sun, .mon, .tue, .wed, .thu, .fri, .sat { padding: 5px; text-align: right; } .sun { color: red; font-weight: bold; } </style> </head> <body>''') print(cal.encode('utf-8')) print('''</body> </html>''') cal = calendar.LocaleHTMLCalendar(calendar.MONDAY, 'pl_PL') # only table #print(cal.formatmonth(2017, 1)) #print(cal.formatyear(2017)) # full HTML #print_full_html(cal.formatmonth(2017, 1)) print_full_html(cal.formatyear(2017))
def print_calendar(last_name_of_last_month, month, days_to_skip_str, saturdays_to_include_str, names_file, calendar_title, output_file, config_file): """Prints a HTML calendar to the stdout Sample usage: python3 fcal.py --month next --last_name_of_last_month 'Bilbo Baggins' --days_to_skip 2,5""" # Setup data nevek = [line.rstrip('\n') for line in open(names_file)] holidays, working_days = parse_config(config_file) loc = locale.getlocale() # get current locale fruit_calendar = calendar.LocaleHTMLCalendar(calendar.MONDAY, loc) next_names = get_next_name(nevek, last_name_of_last_month) reference_date = TODAY if month == 'current': pass elif month == 'next': reference_date = add_months(TODAY, 1) else: raise Exception("Only values 'current and 'next' are accepted") if days_to_skip_str: merge_into_dict( holidays, parse_days( list_to_hash(days_to_skip_str.split(",")), month=reference_date.month) ) if saturdays_to_include_str: merge_into_dict( working_days, parse_days( list_to_hash(saturdays_to_include_str.split(",")), month=reference_date.month) ) html_str = fruit_calendar.\ formatmonth(reference_date.year, reference_date.month).replace(" ", " ") root = etree.fromstring(html_str) header = list(list(root)[0])[0] (yearstr, monthstr) = header.text.split(" ") if loc[0] == 'hu_HU': header.text = "%s %s %s" % (calendar_title, monthstr, yearstr) else: header.text = "%s %s %s" % (calendar_title, yearstr, monthstr) root.attrib = {k:v for (k, v) in root.attrib.items() if k == 'class'} for elem in root.findall("tr"): children = elem.getchildren() if len(children) == 1: continue elem.remove(children[calendar.SUNDAY]) for elem in root.findall("*//td"): if elem.get('class') != 'noday': dayno = elem.text day_elem = etree.SubElement(elem, "span") day_elem.attrib['class'] = 'day' day_elem.text = dayno elem.text = '' name = etree.SubElement(elem, "span") name.attrib['class'] = 'name' day = datetime.datetime(reference_date.year, reference_date.month, int(dayno)) is_saturday = day.weekday() == 5 if day in holidays.keys(): name.text = holidays[day] elem.set('class', 'holiday') elif (is_saturday and day not in working_days.keys()): name.text = "" elem.set('class', 'holiday') else: name.text = next(next_names) body = etree.tostring(root, encoding="unicode") context = { 'calendar_title': 'calendar_title', 'body' : body } with open(output_file, "w") as target: output = render('./fcal.html', context) target.write(output)
def create_calendar(): aln = calendar.LocaleHTMLCalendar(locale="en_US.UTF-8") show = aln.formatyear(2021) return show