Esempio n. 1
0
    def __format_calendar(self, year, month, rows):
        """ カレンダー形式のレスポンスに整形 """
        # 日曜始まり
        cl = TextCalendar(firstweekday=6)
        # 週単位での日付と曜日を取得
        weeks = cl.monthdays2calendar(year, month)
        res = []

        for week in weeks:
            week_data = []
            for day in week:
                current_date, weekday = day
                data = next(
                    (row for row in rows if row['sales_day'] == current_date),
                    None)
                is_saturday = True if weekday == self.SATURDAY else False
                is_sunday = True if weekday == self.SUNDAY else False
                sales_day = None
                total_price = None
                if data is not None:
                    sales_day = data['sales_date'].strftime('%Y-%m-%d')
                    total_price = int(data['total_price'])
                week_data.append({
                    'sales_date': current_date,
                    'sales_day': sales_day,
                    'amount': total_price,
                    'is_saturday': is_saturday,
                    'is_holiday': is_sunday,
                    'daily_sales_url': ''
                })
            res.append(week_data)
        return res
Esempio n. 2
0
 def __init__(self, root):
     self.root = root
     self.root.title(APP_NAME)
     self.instance = TextCalendar()
     self.root.resizable(False, False)
     self.init_gui()
     self.update_display()
     self.root.mainloop()
Esempio n. 3
0
 def generating_calendar_content(self):
     """
     return:: None
     """
     for i in range(1, 13):
         self._content.append(TextCalendar(firstweekday=0).formatmonth(int(self.title), i))
         self._calendar_pages.append(len(self._content))
         for k in Calendar().itermonthdates(int(self.title), i):
             if k.month == i:
                 self._content.append(str(k))
Esempio n. 4
0
 def __init__(self, root):
     self.root = root
     self.root.title(APP_NAME)
     self.instance = TextCalendar()
     self.root.resizable(False, False)
     self.init_gui()
     self.update_display()
     print(self.display_widget.winfo_width(),
           self.display_widget.winfo_height())
     self.root.mainloop()
Esempio n. 5
0
        def __init__(self, parent, values):
		self.values = values
		self.parent = parent
		
		self.cal = TextCalendar(calendar.SUNDAY)
		self.year = datetime.date.today().year
		self.month = datetime.date.today().month

		self.yearSelected = self.year
		self.monthSelected = self.month
		self.daySelected = 1
Esempio n. 6
0
def calendar():
    settings = sys.argv
    now = datetime.now()
    year = now.year
    month = now.month
    # print(settings, year, month)
    numArg = len(sys.argv)

    try:
        if numArg > 1:
            if numArg > 2:
                print(
                    TextCalendar(6).prmonth(
                        int(settings[2][1:len(settings[2]) - 1]),
                        int(settings[1])))
            else:
                print(TextCalendar(6).prmonth(year, int(settings[1])))
        else:
            print(TextCalendar(6).prmonth(year, month))

    except:  # analogous to the try/catch blocks in JS
        print(
            "\"Please input parameters in the format '14_cal.py month [year]'\""
        )
Esempio n. 7
0
    def horizontalImages(self):

        today = date.today()
        image = Image.new("1", size=(self.width, self.height), color=255)
        imagey = Image.new("1", size=(self.width, self.height), color=255)

        cal = TextCalendar().formatmonth(today.year, today.month)

        draw = ImageDraw.Draw(image)
        drawy = ImageDraw.Draw(imagey)

        draw.text((50, 10), today.strftime("%b"), font=self.font_heading)
        draw.text((30, 70), today.strftime("%d"), font=self.font_big)
        draw.text((50, 220), today.strftime("%Y"), font=self.font_heading)
        drawy.text((210, 30), cal, font=self.font_cal)
        draw.text((210, 220), today.strftime("%A"), font=self.font_heading)
        drawy.text((50, 300),
                   "\n".join(textwrap.wrap(getQuote())),
                   font=self.font_quote)
        return image, imagey
def get_month_ary(year: int, month: int) -> list:
    """Get the formatted month as a list of lists"""
    c = TextCalendar(6)  # to make week start on Sunday

    month_str = c.formatmonth(year, month)
    weeks = month_str.split('\n')

    title = weeks[0].strip()
    weeks = weeks[1:]

    month = [title]

    for week in weeks:
        week_list_stripped = week.strip()
        week_list_split_filtered = list(
            filter(None, week_list_stripped.split(' ')))
        month.append(week_list_split_filtered)

    if not month[-1]:
        month.pop()

    return month[:]
Esempio n. 9
0
    def verticalImages(self):
        today = date.today()
        image = Image.new("1", size=(self.width, self.height), color=255)
        imagey = Image.new("1", size=(self.width, self.height), color=255)

        cal = TextCalendar().formatmonth(today.year, today.month)

        draw = ImageDraw.Draw(image)
        drawy = ImageDraw.Draw(imagey)

        draw.text((50, 10), today.strftime("%b %d %Y"), font=self.font_heading)
        drawy.text((50, 80), today.strftime("%A"), font=self.font_heading)
        self.makeCalImg()

        calimg = Image.open("./cal.jpg").convert("1")
        image.paste(calimg, (40, 160))

        # draw.text((40, 160), cal, font = self.font_cal)
        # drawy.text((50, 400), "\n".join(textwrap.wrap(getQuote(), width=30)), font = self.font_quote)
        self.makeImage(imagey)

        return image, imagey
Esempio n. 10
0
def main():
    current_year = current_date.year
    current_month = current_date.month
    current_month_name = current_date.strftime("%B")
    current_weekday = current_date.weekday()
    current_weekday_name = current_date.strftime("%A")

    cal = TextCalendar().monthdatescalendar(current_year, current_month)

    events_dict = load_json("events.json")
    dates = []
    message = []

    for week in cal:
        for day in week:
            if day.month == current_month and day.weekday() == current_weekday:
                dates.append(day)

    if current_month_name in events_dict \
            and current_weekday_name in events_dict[current_month_name]:
        events = events_dict[current_month_name][current_weekday_name]

        if "First" in events and events["First"]:
            if current_date.date() == dates[0]:
                message.append(events["First"])

        if "Last" in events and events["Last"]:
            if current_date.date() == dates[-1]:
                message.append(events["Last"])

        if "Every" in events and events["Every"]:
            message.append(events["Every"])

    if message:
        send_text(', '.join(message))
    else:
        print("No notifications")
Esempio n. 11
0
   month and render the calendar for that month of the current year.
 - If the user specifies two arguments, assume they passed in
   both the month and the year. Render the calendar for that
   month and year.
 - Otherwise, print a usage statement to the terminal indicating
   the format that your program expects arguments to be given.
   Then exit the program.
"""

import sys
from calendar import TextCalendar
from datetime import datetime

current_year = datetime.now().year
cal_input = input("Please input year and month (XXXX XX): ").strip().split(" ")

if len(cal_input) < 2 and len(cal_input) > 0:
    TextCalendar().prmonth(current_year, int(cal_input[0]))
else:
    TextCalendar().prmonth(int(cal_input[0]), int(cal_input[1]))
print(current_year)
print(cal_input)








Esempio n. 12
0
		events.append( (calname, component))

events.sort(key = lambda t : t[1]['DTEND'].dt)
output_string = ''

shorthands = [
		'🌞',
		'🐒',
		'🇹',
		'💍',
		'🌩️',
		'🍟',
		'📡'
		]
calendar_lines = TextCalendar(firstweekday=6).formatmonth(
		theyear = now.year,
		themonth = now.month,
		).strip().split('\n')
calendar_lines[1] = ' '.join(shorthands)
k = now.isoweekday() % 7
d = now.day
# that means the 1st was on (k-d+1)'th day of week
# so the calendar starts with (k-d+1) extra days
row = (d + ((k-d+1)%7) - 1) // 7 # 0-indexed row number to get

calendar_lines[row+2] = calendar_lines[row+2][:3*k] \
		+ '💚' + calendar_lines[row+2][3*k+2:]
calendar_text = '\n'.join(calendar_lines)
embed = DiscordEmbed(
		title = options.get('title', 'Calendar'),
		description = f"Generated on {now.strftime('%A, %B %d, %H:%M')}" \
				+ "\n" + f"Time zone: {tz.zone}" + "\n" \
Esempio n. 13
0
# -*- coding: utf-8 -*-

from calendar import TextCalendar, HTMLCalendar

tc = TextCalendar(firstweekday=6)
# print [tc.prmonth(x,y) for x in range(2010,2011) for y in range(1,13)]

for x in range(2010, 2011):
    for y in range(1, 13):
        tc.prmonth(x, y)

        # f = lambda x : x +10
        # print map(f,range(10))

        # f = lambda x,y : x * y
        # list = []
        # list.append(f)
        # print list
        # print list[0](range(10),2)
        # # print reduce(f,range(1,10))

        # f = lambda x : x < 5
        # print filter(f,range(10))
        # lambda x+y : x,y for x,y in (range(2016,2017) ,range(1,13))

        # class test():
        # def __init__(self,name = "self name"):
        # self.name = name
        #     def printname(self,name = "self name"):
        #         if name is None:
        #             name = self.name
Esempio n. 14
0
Note: the user should provide argument input (in the initial call to run the file) and not 
prompted input. Also, the brackets around year are to denote that the argument is
optional, as this is a common convention in documentation.

This would mean that from the command line you would call `python3 14_cal.py 4 2015` to 
print out a calendar for April in 2015, but if you omit either the year or both values, 
it should use today’s date to get the month and year.
"""

import sys
import calendar
from calendar import TextCalendar
from datetime import datetime

print(len(sys.argv))
cal = TextCalendar()

if len(sys.argv) == 1:
    cal.prmonth(theyear=2020, themonth=6)

elif len(sys.argv) == 2:
    month = int(sys.argv[1])
    cal.prmonth(theyear=2020, themonth=month)

elif len(sys.argv) == 3:
    month = int(sys.argv[1])
    year = int(sys.argv[2])
    cal.prmonth(theyear=year, themonth=month)

elif len(sys.argv) > 3:
    print('Too many inputs')
Esempio n. 15
0
# Use the sys module to look for command line arguments in the `argv` list
# variable.
#
# If the user specifies two command line arguments, month and year, then draw
# the calendar for that month.

# Stretch goal: if the user doesn't specify anything on the command line, show
# the calendar for the current month. See the 'datetime' module.

# Hint: this should be about 15 lines of code. No loops are required. Read the
# docs for the calendar module closely.

import sys
from calendar import TextCalendar
from datetime import datetime

tc = TextCalendar()

try:
    month = int(sys.argv[1])
except Exception as e:
    month = datetime.today().month

try:
    year = int(sys.argv[2])
except Exception as e:
    year = datetime.today().year

tc.prmonth(year, month)

Esempio n. 16
0
def asciiMonth(year: int = today.year, month: int = today.month):
    return ("''%s''" % i
            for i in TextCalendar(0).formatmonth(year, month).split('\n'))
Esempio n. 17
0
from calendar import TextCalendar

year = 0
month = 1

while True:
    year = abs(int(input('Enter the year: ')))

    if year:
        break

while True:
    month = abs(int(input('Enter the month: ')))
    
    if month <= 12 and month > 0:
        break
    else:
        print('The number must be in range of 1 to 12')

calendar = TextCalendar(firstweekday=0)

calendar.prmonth(year, month)
Esempio n. 18
0
print(calendar.monthrange(2021,10))
print(calendar.monthcalendar(2019, 10))
print(calendar.prmonth(2021, 10))
print(calendar.prcal(2021))
print(calendar.day_name[0])
print(calendar.day_abbr[0])
print(calendar.month_name[1])
print(calendar.month_abbr[1])

print('--------------------------------')

c = Calendar()
print(list(c.itermonthdates(2021, 7)))
print(list(c.itermonthdays2(2020, 7)))
print(list(c.itermonthdays3(2021, 7)))
print(list(c.itermonthdays4(2021, 7)))

print('--------------------------------')

tx = TextCalendar()
print(tx.formatmonth(2021, 9))
print(tx.prmonth(2021, 9))
print(tx.formatyear(2021))
print(tx.pryear(2021))

print('---------------------------------')

hc = HTMLCalendar()
print(hc.formatmonth(2021, 10))
print(hc.formatyear(2021))
print(hc.formatyearpage(2021))
Esempio n. 19
0
"""

import sys
from calendar import TextCalendar
from datetime import datetime

ERROR_MSG = 'Invalid arguments (expected numbers in format "[month] [year]")'
START_DAY = 6  # Start weeks on Sunday

console_args = sys.argv[1:]

try:
    arg_count = len(console_args)
    if arg_count == 0:
        present_datetime = datetime.now()
        month = present_datetime.month
        year = present_datetime.year
        TextCalendar(START_DAY).prmonth(year, month)
    elif arg_count == 1:
        month = console_args[0]
        year = datetime.now().year
        TextCalendar(START_DAY).prmonth(year, int(month))
    elif arg_count == 2:
        # pylint: disable=unbalanced-tuple-unpacking
        month, year = console_args
        TextCalendar(START_DAY).prmonth(int(year), int(month))
    else:
        raise Exception("")
except Exception as error:
    print(ERROR_MSG if error.__str__() == "" else f"\nTrace:\n'{error}'")
Esempio n. 20
0
def on_domination(self, room, *args):
    calendar = TextCalendar()
    self.send_message(room, calendar.formatmonth(2020, 1))