Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ACE appointment class module"""
- from datetime import datetime
- from openpyxl import Workbook
- import pandas as pd
- import openpyxl
- import os
- from rich import inspect
- class appointment():
- def __init__(self,day,month,year,subject,tutor_name,screen_name):
- self.day = day
- self.month =month
- self.year = year
- self.subject = self.santize_subject(subject)
- self.tutor_name=tutor_name
- self.tutor_screen_name = screen_name
- self.day_of_the_week = self.get_day_of_the_week()
- def get_day_of_the_week(self):
- """ returns the day of the week from the date of the appointment"""
- date = pd.Timestamp(str(self.year)+"-"+str(self.month)+"-"+str(self.day))
- return date.day_name()
- def santize_subject(self,subject):
- if type(subject) is None:
- return "[SUBJECT NOT RECORDED]"
- else:
- return subject
- def check_within_date_range(self,earliest_date,latest_date):
- app_date = datetime(self.year,self.month,self.day)
- if earliest_date < app_date < latest_date:
- return True
- else:
- return False
- def check_for_file(file_name):
- """checks if a supplies file exists in the current directory"""
- if os.path.exists(file_name):
- return True
- else:
- return False
- def read_excel_data(file_name):
- """reads an excel file to create appointments and places them into a list."""
- curr_path = os.getcwd()
- file_to_check = curr_path+"\\"+file_name
- appointment_list = []
- if check_for_file(file_to_check):
- workbook = openpyxl.load_workbook(file_to_check)
- worksheet = workbook["sheet 1"]
- row = 2
- while row < 17916:
- row = str(row)
- date_day = worksheet[str("A"+row)].value.day
- date_month = worksheet[str("A"+row)].value.month
- date_year = worksheet[str("A"+row)].value.year
- subject = worksheet[str("B"+row)].value
- tutor = worksheet[str("C"+row)].value
- screen_name = worksheet[str("D"+row)].value
- appointment_list.append(appointment(date_day,date_month,date_year,subject,tutor,screen_name))
- row = int(row)+1
- return appointment_list
- def search_by_data_range_and_subject(appointments_list,starting_date,ending_date):
- results = {}
- for appoint in appointments_list:
- if appoint.subject in results.keys():
- results[appoint.subject] += 1
- else:
- results.update({appoint.subject: 1})
- return results
- def write_a_series_appointment_data_to_excel(list_of_data,filename = "appointment_data.xlsx",worksheet_name = "data"):
- wb = Workbook()
- col_to_write = 1
- for item in list_of_data.keys():
- write_to_excel_file(list_of_data[item],wb,item,col_to_write)
- col_to_write += 2
- wb.save(filename)
- wb.close()
- def write_to_excel_file(source_data,workbook : Workbook,section_header : str,start_col : int):
- wb = workbook
- col = start_col
- row = 2
- subject = 1
- num_of_apointments = 2
- ws01 = wb.active
- ws01.title="raw data"
- _ = ws01.cell(column=start_col,row=row-1,value = section_header)
- while row<len(source_data.keys()):
- for item,val in source_data.items():
- _ = ws01.cell(column=start_col,row=row,value = item)
- _ = ws01.cell(column=start_col+1,row=row,value = val)
- row += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement