print a 1 yr calendar

This commit is contained in:
Coding with Peter 2023-07-10 10:07:21 -07:00
parent 650ad9539c
commit 291bec8e91
2 changed files with 119 additions and 5 deletions

View File

@ -1330,11 +1330,18 @@ def create_sandboxes():
sandboxes = [ ('JH','45324'), ('PK','38183'), ('GM','5167'), ('BS','19231'),
('ST','303'), ('KW','5145')]
sandboxes = [ ('PH', '2'), ]
sandboxes = [ ('CD','51701'), ('LC','45193'), ('JC','70'), ('DG','133'), ('JH','2816'),('SM','18812'), ('GM','211'),
('RM','45341'), ('DP','251'), ('BT','58059'), ('TT','36834') ]
sandboxes = [ ('MA','8'), ('WA','15'), ('BA','18'), ('CC','51701'), ('LC','45193'), ('PC','4100'), ('ED','82'), ('KE','101'),
('OF','41897'), ('SG','115'), ('JG','37654'), ('DG','133'), ('DK','168'), ('JM','204'), ('GM', '211'),
('RM','45341'), ('CR','5655'), ('CS','272'), ('BS','19231'), ('SS', '274') ]
report = []
for (N,usrid) in sandboxes:
#names = input("what are the initials of people? Separate with spaces ").split()
coursename = f"{N} Sandbox SU23 Humanizing STEM"
coursecode = f"{N} SU23 Sandbox STEM"
coursename = f"{N} Sandbox SU23 (GOTT4)"
coursecode = f"{N} SU23 Sandbox (GOTT4)"
print(f"Creating course: {coursename} for {N}, id: {usrid}")
u2 = url + "/api/v1/accounts/1/courses"
data = {
@ -1349,6 +1356,8 @@ def create_sandboxes():
id = course_data['id']
print(f"created course id {id}")
report.append( f"{coursename} https://ilearn.gavilan.edu/courses/{id}" )
# Add teacher
u3 = url + f"/api/v1/courses/{id}/enrollments"
#usrid = input("id of %s? " % N)
@ -1374,7 +1383,12 @@ def create_sandboxes():
#print(json.dumps(json.loads(r4.text),indent=2))
#print()
#x = input("enter to continue")
print("\n\n")
print("\n".join(report))
print("\n")
def course_term_summary_2():
lines = codecs.open('cache/term_summary.txt','r','utf-8').readlines()

100
tasks.py
View File

@ -1317,6 +1317,105 @@ def update_auth():
#print(json.dumps(r,indent=2))
def print_a_calendar():
import datetime
cur_week = datetime.date.today().isocalendar()[1]
print(f"Current week number: {cur_week}")
import time
from time import gmtime, strftime
#d = time.strptime("3 Jul 2023", "%d %b %Y")
#print(strftime(d, '%U'))
import calendar
# Specify the year
year = 2023
if 0:
# Create a calendar for the entire year
cal = calendar.Calendar()
# Iterate over each month of the year
for month in range(1, 13):
# Print the month name
month_name = calendar.month_name[month]
print(f"\n{month_name} ({year})")
# Print the weekday abbreviation
weekdays = ['w ', 'M ', 'T ', 'W ', 'Th', 'F ', 'Sa', 'S ']
print(' '.join([ f"{day:<3}" for day in weekdays] ))
# Get the month's calendar
month_calendar = cal.monthdatescalendar(year, month)
# Iterate over each week in the month
for week in month_calendar:
# Extract the week number and days of the week
week_number = week[0].isocalendar()[1]
week_days = [day.day if day.month == month else '' for day in week]
# Print the week number and days
print(f"{week_number:<4}", end=' ')
print(' '.join([ f"{day:<2}" for day in week_days]))
### ### ### ###
def generate_custom_calendar(year, semesters):
# Create a calendar for the entire year
cal = calendar.Calendar()
# Iterate over each month of the year
for month in range(1, 13):
# Print the month name
month_name = calendar.month_name[month]
print(f"\n{month_name} {year}")
# Print the weekday abbreviation
weekdays = ['w ', 'M ', 'T ', 'W ', 'Th', 'F ', 'Sa', 'S ', 'sem' ]
print(' '.join([f"{day:<3}" for day in weekdays]))
# Get the month's calendar
month_calendar = cal.monthdatescalendar(year, month)
# Iterate over each week in the month
for week in month_calendar:
# Extract the week number and days of the week
week_number = week[0].isocalendar()[1]
week_days = [day.day if day.month == month else '' for day in week]
#print("week: ", week)
# Determine the column value for the 'sem' column
sem_value = ' '
for (label, start_week, num_weeks) in semesters:
if week_number >= start_week and week_number < start_week + num_weeks:
sem_value = (week_number - start_week) + 1
# Print the week number, days, and the 'fa23' column value
print(f"{week_number:<4}", end=' ')
print(' '.join([f"{day:<2}" for day in week_days]) + f" {sem_value:<2}")
# Example usage
semesters = [ "su23,06/12,6", "fa23,08/28,16" ]
l_semesters = []
for sem in semesters:
column_label, start_date, num_weeks = sem.split(',')
start_dt = datetime.datetime.strptime(start_date + "/" + str(year), "%m/%d/%Y")
start_wk = start_dt.isocalendar()[1]
l_semesters.append( (column_label, start_wk, int(num_weeks)) )
generate_custom_calendar(year, l_semesters)
if __name__ == "__main__":
@ -1331,6 +1430,7 @@ if __name__ == "__main__":
10: ['dumb rename images mistake',file_renamer] ,
11: ['list auth', list_auth],
12: ['update auth', update_auth],
13: ['print a calendar', print_a_calendar]
}
if len(sys.argv) > 1 and re.search(r'^\d+',sys.argv[1]):