Пример #1
0
# Use the 'calendar' module to draw calendars to the console
# https://docs.python.org/3.6/library/calendar.html
#
# 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
import calendar
import datetime

calendarArgs = len(sys.argv)
today = datetime.datetime.today()

if calendarArgs == 1:
    month = today.month
    year = today.year
else:
    month = int(sys.argv[1])
    year = int(sys.argv[2])

calendar.TextCalendar().prmonth(year, month)
Пример #2
0
 def just_month(month):
     return calendar.TextCalendar().prmonth(theyear=2020,
                                            themonth=int(month))
Пример #3
0
 - 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 calendar
import datetime

inputs = input("Type your input as: month year").split(" ")

now = datetime.date

if inputs is None:
    calendar = calendar.TextCalendar()
    format = calendar.formatmonth(now.year, now.month)
    print(format)

elif len(inputs) == 1:
    calendar = calendar.TextCalendar()
    calendar2 = calendar.formatmonth(now.year, inputs[0])
    print(format)
elif len(inputs) == 2:
    calendar = calendar.TextCalendar()
    calendar2 = calendar.formatmonth(inputs[1], inputs[0])
    print(format)
else:
    print("Please input your calendar month and year like: 04 2019")
    exit(1)
Пример #4
0
def CalendarioTexto():
    calendarioTexto = calendar.TextCalendar(calendar.SUNDAY)
    txtCalendario = calendarioTexto.formatmonth(2020, 8)
    print(txtCalendario)
Пример #5
0
 def month_and_year(month, year):
     return calendar.TextCalendar().prmonth(theyear=int(year),
                                            themonth=int(month))
Пример #6
0
# 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
import calendar

l = len(sys.argv)

if l == 2:
    month = None
    year = int(sys.argv[1])
elif l == 3:
    month = int(sys.argv[1])
    year = int(sys.argv[2])
else:
    print("usage: cal.py [month] year")
    sys.exit(1)

c = calendar.TextCalendar()

if month != None:
    c.prmonth(year, month)
else:
    c.pryear(year)
Пример #7
0
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 datetime import datetime

args = sys.argv
mon = datetime.now().month
yr = datetime.now().year

if len(args) == 1:
    pass
elif len(args) == 2:
    mon = int(args[1])
elif len(args) == 3:
    yr = int(args[2])
    mon = int(args[1])
else:
    print("Please make sure it is in this format '14_cal.py [month] [year]'.")
    exit(0)

if mon < 1 or mon > 12:
    print("ERROR: Invalid month")
    exit(0)

calendar.TextCalendar(6).prmonth(yr, mon)
Пример #8
0
# Example file for working with Calendars

# import the calendar module
import calendar

# create a plain text calendar
calendar_object = calendar.TextCalendar(calendar.MONDAY)
calendar_string = calendar_object.formatmonth(2019, 1, 0, 0)
print(calendar_string)

# create an HTML formatted calendar
html_calendar_object = calendar.HTMLCalendar(calendar.MONDAY)
calendar_string = html_calendar_object.formatmonth(2019, 1)
print(calendar_string)

# loop over the days of a month
# zeroes mean that the day of the week is in an overlapping month
for iterator in calendar_object.itermonthdays(2019, 8):
    print(iterator)

# The Calendar module provides useful utilities for the given locale,
# such as the names of days and months in both full and abbreviated forms
for name in calendar.month_name:
    print(name)

for day in calendar.day_name:
    print(day)

# Calculate days based on a rule: For example, consider
# a team meeting on the first Friday of every month.
# To figure out what days that would be for each month,
Пример #9
0
#
#                         All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Doug
# Hellmann not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Print entire year calendar.

"""

__module_id__ = "$Id$"
#end_pymotw_header

import calendar

print calendar.TextCalendar(calendar.SUNDAY).formatyear(2007, 2, 1, 1, 2)
Пример #10
0
 - 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
import calendar
from datetime import datetime

today = datetime.today()

month, year = today.month, today.year

cal = calendar.TextCalendar(firstweekday=6)

print(sys.argv)
if len(sys.argv) == 1:
    calendar.prmonth(today.year, today.month)

elif len(sys.argv) == 2:
    calendar.prmonth(today.year, int(sys.argv[1]))

elif len(sys.argv) == 3:
    calendar.prmonth(int(sys.argv[2]), int(sys.argv[1]))

else:
    print("usage: filename month year")
    sys.exit(1)
Пример #11
0
#Author: ALJ (AMDG) 10/30/20

import calendar
import time

#Question 1
calendar.TextCalendar().pryear(2020)

#Question 2
calendar.TextCalendar(6).pryear(2020)

#Question 3
print(calendar.month(2020, 9))

#Question 4
#calendar.LocaleTextCalendar(6, "SPANISH").pryear(2020)
#calendar.LocaleTextCalendar(6, "ENGLISH").pryear(2020)
#calendar.LocaleTextCalendar(6, "MARATHI").pryear(2020)
##calendar.LocaleTextCalendar(6, "PIG LATIN").pryear(2020)

#Question 5
print(calendar.isleap(2019))
print(calendar.isleap(2020))
print(calendar.isleap(2016))
#This returns true or false, true if it is a leap year and false if it isn't.
#It expects the year as an input
Пример #12
0
import time
import calendar
from datetime import datetime
from datetime import date

#Displaying the current time and date
localtime = time.asctime(time.localtime(time.time()))
print("Current time: ",  localtime)

#Displaying month calender
#calendar starts with sunday as the first day of the week
cal_month = calendar.TextCalendar(calendar.SUNDAY)
display_cal = cal_month.formatmonth(2019, 12)
print("\n" + display_cal)

#Displaying the current time and date formatted
now = datetime.now()
cur_date = now.strftime("%d-%m-%y  %H:%M:%S")
print("Date and time: ", cur_date)
Пример #13
0
def month_year(input_month=now_month, input_year=now_year):
    c = calendar.TextCalendar(calendar.SUNDAY)
    display_calendar = c.formatmonth(input_year, input_month)
    print(display_calendar)
Пример #14
0
from datetime import datetime

# renderedCalendar = calendar.TextCalendar()
# date = input("Enter the year, month: ")
# print(date)
"""
if len(sys.argv) == 1:
elif len(sys.argv) == 2:
elif len(sys.argv) == 3:
else:
print("Invalid command:")
"""
args = sys.argv
#print(args)

month = datetime.today().month
year = datetime.today().year

if len(args) == 1:
    pass
elif len(args) == 2:
    month = int(args[1])
elif len(args) == 3:
    month = int(args[1])
    year = int(args[2])
else:
    print("Error: Must be in format[month] [year]")
    exit()

calendar.TextCalendar().prmonth(month, year)
Пример #15
0
import calendar

c=calendar.TextCalendar(calendar.MONDAY)
dates=c.prmonth(2020,7)
print('='*100)
dates_=c.prmonth(2020,8)
Пример #16
0
 def __get_calendar(s, locale, fwday):  # 日曆文字化
     if locale is None:
         return calendar.TextCalendar(fwday)
     else:
         return calendar.LocaleTextCalendar(fwday, locale)
Пример #17
0
def get_calendar(locale, fwday):
    # instantiate proper calendar class
    if locale is None:
        return calendar.TextCalendar(fwday)
    else:
        return calendar.LocaleTextCalendar(fwday, locale)
Пример #18
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
import calendar
from datetime import datetime


curr_date = datetime.now()
clndr = calendar.TextCalendar()
arg = sys.argv


def numCheck(arg):
    if arg.isdigit():
        return int(arg)
    else:
        return False


if (len(arg) == False):
    print('Looking for input in thr form of: "year(optional), month')
    exit()

Пример #19
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 datetime import datetime

# set for current month and year

mo = datetime.today().month
yr = datetime.today().year

# if extra 2 arguments were passed in, set year to third argument

if len(sys.argv) > 2:
    yr = int(sys.argv[2])

# if extra 1 argument passed in, set month to second argument

if len(sys.argv) > 1:
    mo = int(sys.argv[1])

# initialize calendar and print month
c = calendar.TextCalendar(calendar.SUNDAY)
c.prmonth(theyear=yr, themonth=mo)
Пример #20
0
# rules for description O: Output   I: input
import calendar                                                # We use the calendar functions modules
calend_text = calendar.TextCalendar()                           # Create a Calendar in Text format
calend = calendar
inpresult = 0
ly = 0
rly = 0
firstWeekDay = 0
# How to find the Weekday any day from 1900 to 2108
# The strategy is based in the knowledge of the especial years which hold a specific feature:
#   be a leap year which first weekday of the years is a Monday. they happen any 28 years.
#   we use the year 1912 as the inicial BASE YEAR for calculation.
print("\n          How to find the   WEEKDAY NAME   of any day from 1912 to 2080   MENTALLY  . \n")
print("     The strategy is based in the knowledge of specials years which hold an specific feature:")
print("     Be an   LEAP YEAR   which   FIRST WEEKDAY  of the years is a Monday..")
print("     These situation only happen every 28 years for an 100 year interval. ")
print("     We use the year   2080   as the initial   BASE LEAP YEAR   to do the calculations \n")
print("     This allow us to find out the FIRST WEEKDAY of the year between the years 1912 - 2080  easily")
print("             So  ...  Lets star.   GIVE ME AN DATE   and lets try find the   WEEKDAY NAME for that date \n")

anoBiRef = int(1901)
anoRange = [anoBiRef, 2080]

while True:                                                 # I: Repeat until input is complete
    inpDia = int(input('Dia: '))                            # I:(inpDia)
    inpMes = int(input('Mes: '))                            # I:(inpMes)
    inpAno = int(input('Ano: '))                            # I:(inpAno)
    if anoBiRef >= inpAno or inpAno >= anoRange[1]:         # T: if year input is in range(1912, 2100)
        print(" The year must be between 1900 and 2080 \n")
        continue                                             # F: back to WHILE statement
    elif 0 >= inpMes or inpMes >= 12:                        # T: if month input is in range(1 - 12)