Advertisement
Guest User

calendar.py

a guest
Apr 26th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.78 KB | None | 0 0
  1. from colored import fg, attr
  2. import random
  3.  
  4.  
  5. class Calendar:
  6.     def __init__(self):
  7.         self.month_list = [
  8.             'JANUARY',
  9.             'FEBRUARY',
  10.             'MARCH',
  11.             'APRIL',
  12.             'MAY',
  13.             'JUNE',
  14.             'JULY',
  15.             'AUGUST',
  16.             'SEPTEMBER',
  17.             'OCTOBER',
  18.             'NOVEMBER',
  19.             'DECEMBER'
  20.         ]
  21.         self.current_month = 0
  22.         self.current_week = 0
  23.         self.current_year = 0
  24.         self.month_schedule = self.make_month_schedule()
  25.  
  26.     @staticmethod
  27.     def decorate_event_name(name, color):
  28.         return f"{fg(color)}{attr('bold')}{name}{attr('reset')}"
  29.  
  30.     def decorate_month(self):
  31.         return attr('bold') + " ".join(self.month_list[self.current_month]) + attr('reset')
  32.  
  33.     @staticmethod
  34.     def make_weekly_events():
  35.         tournaments = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
  36.         events = random.sample(tournaments, random.randint(2, 4))
  37.         return events
  38.  
  39.     def make_week_schedule(self):
  40.         week = [0, 0, 0, 0, 0, 0, 0]
  41.         events = self.make_weekly_events()
  42.         rand = random.sample(range(0, 6), len(events))
  43.         for index, event in enumerate(events):
  44.             week[rand[index]] = self.decorate_event_name(event, 'cyan')
  45.  
  46.         return week
  47.  
  48.     def make_month_schedule(self):
  49.  
  50.         month = [self.make_week_schedule(), self.make_week_schedule(),
  51.                  self.make_week_schedule(), self.make_week_schedule()]
  52.  
  53.         return month
  54.  
  55.     def make_calendar(self):
  56.         calendar = f"""{self.decorate_month()} - {attr('bold')}YEAR {self.current_year}{attr('reset')}\n\n"""
  57.  
  58.         for index, week in enumerate(self.month_schedule):
  59.             if index == self.current_week:
  60.                 decor = 'bold'
  61.             else:
  62.                 decor = 'dim'
  63.  
  64.             week_display = f"""{attr(decor)}WEEK {index + 1}:{attr('reset')} """
  65.             for event in week:
  66.                 if event != 0:
  67.                     week_display = week_display + f'[  {event}  ]'
  68.                 else:
  69.                     week_display = week_display + f'[     ]'
  70.  
  71.             calendar = calendar + week_display + '\n'
  72.  
  73.         return calendar
  74.  
  75.     def next_week(self):
  76.         if self.current_week != 3:
  77.             self.current_week += 1
  78.         else:
  79.             self.current_week = 0
  80.  
  81.             if self.current_month == 11:
  82.                 self.current_month = 0
  83.                 self.current_year += 1
  84.             else:
  85.                 self.current_month += 1
  86.  
  87.             self.month_schedule = self.make_month_schedule()
  88.  
  89.     def select_event(self, val):
  90.         for event in self.month_schedule[self.current_week]:
  91.             if event != 0 and val.lower() in event.lower():
  92.                 print('Here')
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement