本文整理汇总了Python中calendar.Calendar.monthdayscalendar方法的典型用法代码示例。如果您正苦于以下问题:Python Calendar.monthdayscalendar方法的具体用法?Python Calendar.monthdayscalendar怎么用?Python Calendar.monthdayscalendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calendar.Calendar
的用法示例。
在下文中一共展示了Calendar.monthdayscalendar方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_week_count
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdayscalendar [as 别名]
def get_week_count(firstdayofweek, firstweekofyear, year, month, day):
cl = Calendar(firstdayofweek)
data = cl.monthdayscalendar(year, 1)
week_cnt = 0
day_cnt = 0
# counting for first month
for i in range(0, 7):
if data[0][i] != 0:
day_cnt += 1
if (firstweekofyear == 2 and day_cnt < 4) or (firstweekofyear == 3 and day_cnt < 7):
week_cnt = -1
if month != 1:
week_cnt += len(data)
if data[len(data)-1][6] == 0:
week_cnt -= 1
#counting for other monthes
for m in range(2, month):
data = cl.monthdayscalendar(year, m)
week_cnt += len(data)
if data[len(data)-1][6] == 0:
week_cnt -= 1
#here we have week count in week_cnt before current month
data = cl.monthdayscalendar(year, month)
for week in range(0, len(data)):
week_cnt += 1
if day in data[week]:
break
return week_cnt
示例2: events_source_in_week
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdayscalendar [as 别名]
def events_source_in_week(self, request, pk, format=None):
"""
Lista todos los eventos de la semana en la que nos encontramos
:param request:
:param pk:
:param format:
:return:
"""
_pk = 0
list_week = []
list_events_week = []
calendary = Calendar(0)
today = timezone.localtime(timezone.now())
year = today.year
month = today.month
events_in_week = 0
if type(pk) is DictType:
_pk = pk['pk']
list_week = pk['list_week']
month = pk['month']
year = pk['year']
events_in_week = pk['events_db']
else:
_pk = pk
for it in calendary.monthdayscalendar(today.year, today.month):
try:
if it.index(today.day):
list_week = it
except ValueError:
pass
if not events_in_week:
try:
events_in_week = Events.objects.filter(ID_Source=_pk)
except Events.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
for it in list_week:
if not it == 0:
dict_day = {'day': it, 'pk': _pk, 'year': year, 'month': month, 'events_db': events_in_week}
list_events_week.append(EventsInformation().events_source_in_day(request, dict_day))
result = [] # Esta lista es para el uso interno de las otras funciones de la clase
result_json = [] # Esta lista es para dar más información al json de la api
count = 0
for it in list_events_week:
count += 1
result_json.append({'day_week': count, 'events': it})
for it_dict in it:
if it_dict:
result.append(it_dict)
if type(pk) is DictType:
return result
else:
return JSONResponse(result_json)
示例3: get_business_days_quantity
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdayscalendar [as 别名]
def get_business_days_quantity(limit_day = 31):
"""
Retorna quatidade de dias úteis no mês.
"""
args = get_args()
businessdays = 0
calendar = Calendar()
for week in calendar.monthdayscalendar(args.year, args.month):
for i, day in enumerate(week):
if day == 0 or i >= 5:
continue
for holiday in HOLIDAYS:
if holiday['month'] == args.month and holiday['day'] == day:
businessdays -= 1
continue
businessdays += 1
if (int(day) == int(limit_day)):
return businessdays
return businessdays
示例4: calendarSite
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdayscalendar [as 别名]
def calendarSite(year, month):
cal = Calendar()
weeks = cal.monthdayscalendar(year = year, month = month)
for week in weeks:
for i in range(0, len(week)):
if week[i] == 0:
week[i] = ""
return {'year': year, 'month': months[month-1] ,'dayNames' : dayNames, 'weeks' : weeks}
示例5: events_source_in_month
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdayscalendar [as 别名]
def events_source_in_month(self, request, pk, format=None):
"""
Lista todos los eventos de una source en el mes actual
:param request:
:param pk:
:param format:
:return:
"""
list_events_month = []
calendary = Calendar(0)
today = timezone.localtime(timezone.now())
year = today.year
month = today.month
events_in_month = 0
if type(pk) is DictType:
_pk = pk['pk']
list_month = pk['list_month']
month = pk['month']
year = pk['year']
events_in_month = pk['events_db']
else:
_pk = pk
list_month = calendary.monthdayscalendar(today.year, today.month)
if not events_in_month:
try:
events_in_month = Events.objects.filter(ID_Source=_pk)
except Events.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
for it in list_month:
dict_month = {'pk': _pk, 'list_week': it, 'year': year, 'month': month, 'events_db': events_in_month}
list_events_month.append(EventsInformation().events_source_in_week(request, dict_month))
result = []
count = 0
for it in list_events_month:
count += 1
result.append({'week': count, 'days': it})
if type(pk) is DictType:
return result
else:
return JSONResponse(result)
示例6: get_calendar
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdayscalendar [as 别名]
def get_calendar(professor, month=6):
"""
get calendar for given month
:return:
"""
now = datetime.datetime.now().date().replace(month=month)
events = ProfessorDay.objects.filter(professor=professor)
calendar = Calendar(0)
weeks = calendar.monthdayscalendar(month=month, year=now.year)
days = dict(
map(lambda entry: (entry.date.day, {'date': entry.date,
'available': entry.available,
'exam': entry.exam_group}
), events)
)
weeks = map(lambda week: map(lambda day: days[day] if day in days else {}, week), weeks)
return weeks
示例7: post_count_possible
# 需要导入模块: from calendar import Calendar [as 别名]
# 或者: from calendar.Calendar import monthdayscalendar [as 别名]
def post_count_possible(self,period=None):
if period == 'week':
calendar_week = range_of_date_week(date.today())
interval = (calendar_week[0], calendar_week[-1])
completed = jmodels.Entry.objects.filter(user__username=self.username,date__range=interval).count()
total_possible = 7
return "Completed %s out of the %s possible journal entries this week" % (completed, total_possible)
elif period == 'month':
c = Calendar(0)
weeks = c.monthdayscalendar(date.today().year,date.today().month)
max_days = 1
for w in weeks:
max_days = max(w)
completed = jmodels.Entry.objects.filter(user__username=self.username,date__year=date.today().year,date__month=date.today().month).count()
total_possible = max_days
return "Completed %s out of the %s possible journal entries this month" % (completed, total_possible)
else:
completed = jmodels.Entry.objects.filter(user__username=self.username).count()
total_possible = (date.today() - self.profile.user.date_joined.date()).days + 4
return "Completed %s out of the %s possible entries since you started journaling on Emovolution." % (completed, total_possible)