Ejemplo n.º 1
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')
Ejemplo n.º 2
0
#Example of working with Calendar
import calendar
from calendar import TextCalendar
cal = TextCalendar()

#Returns the calender for the year 2017
cal.pryear(2018)

#Returns the calender for the month of Novemeber in 2017
cal.prmonth(2018, 6)

Ejemplo n.º 3
0
#! env python
"""
Very simply emulate UNIX cal program.
"""

from calendar import TextCalendar
from datetime import datetime
import sys

yearly = False

args=sys.argv[1:]
if args:
	if len(args)>1:
		month, year = int(args[0]), int(args[1])
	else:
		yearly = True
		year = int(args[0])
else:
	now=datetime.now()
	month, year = now.month, now.year

cal=TextCalendar()
if yearly:
	cal.pryear(year)
else:
	cal.prmonth(year, month)
Ejemplo n.º 4
0
from calendar import  TextCalendar

year = int(input("年を入力してください: "))
month = int(input("月を入力してください: "))

cal = TextCalendar(6)
cal.prmonth(year, month)

cal_str = cal.formatmonth(year, month)
print(cal_str)
Ejemplo n.º 5
0
# モジュールからクラスを指定してインスタンスを生成する際はModule名.Class名が必要と言ったなあれは嘘だ
# 正確には、クラスを指定してimportする記法が存在する、よってそれを使用すれば一々Module名を指定する必要がなくなる
# 以下にその例を示す

# calenderModuleからTextCalendarクラスのみをimportする
from calendar import TextCalendar

# fromでModule名とクラス名を指定してインポートしているのでインスタンス生成時に改めてModule名を指定する必要はない
cal = TextCalendar(6)
cal.prmonth(2017,5)

# !ただし、複数のモジュールからimportする場合や独自クラスを作成している場合はクラス名の重複に注意!
# クラス名の重複が起きた場合は、古いクラスから上書きされていく

# FIXME 月日を標準入力から指定することができるように書き換えること
import calendar
# import Calnedar.TextCalendar
Ejemplo n.º 6
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
Ejemplo n.º 7
0
# Example of working with Calendar
from calendar import TextCalendar

cal = TextCalendar()

# Returns the calender for the year 2018
cal.pryear(2018)

# Returns the calender for the month of November in 2018
cal.prmonth(2018, 11)

Ejemplo n.º 8
0
#Example of working with Calendar
import calendar
from calendar import TextCalendar
cal = TextCalendar()

#Returns the calender for the year 2017
cal.pryear(2017)

#Returns the calender for the month of Novemeber in 2017
cal.prmonth(2017, 11)

Ejemplo n.º 9
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)

Ejemplo n.º 10
0
  """)

try:
    if len(sys.argv) == 1:
        query_month = datetime.today().month
        query_year = datetime.today().year
    elif len(sys.argv) == 2:
        query_month = int(sys.argv[1])
        query_year = datetime.today().year
    elif len(sys.argv) == 3:
        query_month = int(sys.argv[1])
        query_year = int(sys.argv[2])
    else:
        raise UsageError

    cal.prmonth(query_year, query_month)
    # if print(cal.prmonth()) then it also prints None, the return value of the print

except:
    print(UsageError)
    exit()


# let proper_usage = Exception('Text ')

# def globalist_month():
#   global query_month
#   try:
#     query_month = int(sys.argv[1])
#   except:
#   finally:
Ejemplo n.º 11
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)
Ejemplo n.º 12
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))