def handle_remove_command(): ''' Handles the parsing of the remove command. This allows the user to manually remove a session log from the database. ''' verify_username = raw_input('What is your Slack username (Ex: stephen)?: ') if verify_username is None: print('You must provide your name to sign session timestamps!') return None verify_data = user.get_user(verify_username) if verify_data is None: print('Unable to find your name ' + str(verify_username) + '.') return None # get the uuid of the person verifying verify_uuid = str(verify_data[0]) req_name = raw_input( 'Name of the user to remove a session log from (Ex: stephen)?: ') if req_name is None: print('You must provide the name of the user!') return None user_data = user.get_user(req_name) if user_data is None: print('Unable to find ' + str(req_name) + '. Are you sure they exist?') return None start_date = raw_input('The date of the session log (Ex: YYYY-MM-DD)?: ') if start_date is None: print('You must provide a valid start date, such as 2016-11-16') return None # attempt to format their input try: s_year, s_month, s_day = _format_date(start_date) except Exception as e: print(e) print( 'Unable to convert date to representation... Are you sure it was entered correctly?' ) return None # delete session log user_session.delete_user_session_log(user_data[0], start_date) print('Successfully deleted ' + str(req_name) + '\'s session log for ' + str(start_date) + ' if it existed!')
def handle_add_command(): ''' Handles the parsing of the add command. This allows the user to manually add a session log to the database. ''' verify_username = raw_input('What is your Slack username (Ex: stephen)?: ') if verify_username is None: print('You must provide your name to sign session timestamps!') return None verify_data = user.get_user(verify_username) if verify_data is None: print('Unable to find your name ' + str(verify_username) + '.') return None # get the uuid of the person verifying verify_uuid = str(verify_data[0]) req_name = raw_input( 'Name of the user to add a session log for (Ex: stephen)?: ') if req_name is None: print('You must provide the name of the user!') return None user_data = user.get_user(req_name) if user_data is None: print('Unable to find ' + str(req_name) + '. Are you sure they exist?') return None start_date = raw_input('The date of the session log (Ex: YYYY-MM-DD)?: ') if start_date is None: print('You must provide a valid start date, such as 2016-11-16') return None # attempt to format their input try: s_year, s_month, s_day = _format_date(start_date) except Exception as e: print(e) print( 'Unable to convert date to representation... Are you sure it was entered correctly?' ) return None worked_hours = raw_input( 'Number of hours for this session log (Ex: 2.5)?: ') if worked_hours is None: print('You must enter their worked hours!') return None # attempt to format their input try: worked_hours_ms = float(worked_hours) * 3600000 except Exception as e: print(e) print( 'Unable to convert hours to representation... Are you sure it was entered correctly?' ) return None # add to their session log user_session.create_user_session_log(user_data[0], worked_hours_ms, start_date, start_date, verify_uuid) print('Successfully added ' + str(worked_hours) + ' to ' + str(req_name) + '\'s session log for ' + str(start_date))
def handle_verify_command(): ''' Handles the parsing of the verify command. This allows the user to sign session timestamps. ''' verify_username = raw_input('What is your Slack username (Ex: stephen)?: ') if verify_username is None: print('You must provide your name to sign session timestamps!') return None verify_data = user.get_user(verify_username) if verify_data is None: print('Unable to find your name ' + str(verify_username) + '.') return None # get the uuid of the person verifying verify_uuid = str(verify_data[0]) req_name = raw_input( 'Name of the user to verify timestamps for (Ex: stephen)?: ') if req_name is None: print('You must provide the name of the user!') return None user_data = user.get_user(req_name) if user_data is None: print('Unable to find ' + str(req_name) + '. Are you sure they exist?') return None start_date = raw_input( 'The starting date to verify for the user (Ex: YYYY-MM-DD)?: ') if start_date is None: print('You must provide a valid start date, such as 2016-11-16') return None end_date = raw_input( 'The ending date to verify for the user (Ex: YYYY-MM-DD)?: ') if end_date is None: print('You must provide a valid end date, such as 2016-11-16') return None # attempt to format their input try: s_year, s_month, s_day = _format_date(start_date) e_year, e_month, e_day = _format_date(end_date) except Exception as e: print(e) print( 'Unable to convert dates to representation... Are you sure they are entered correctly?' ) return None # convert to timestamp that SQL knows start_date = datetime.datetime(s_year, s_month, s_day, 0, 0, 0).strftime('%Y-%m-%d %H:%M:%S') end_date = datetime.datetime(e_year, e_month, e_day, 0, 0, 0).strftime('%Y-%m-%d %H:%M:%S') # get all their session logs session_info = user_session.get_session_logs(user_data[0], start_date, end_date) # if they have session logs if session_info is not None and len(session_info) > 0: # build a list of the not verified ones not_verified = [] for log_id, user_id, work_time, start, end, approved in session_info: if approved == 'None': not_verified.append( (log_id, user_id, work_time, start, end, approved)) # if they have not verified ones if len(not_verified) > 0: print('\nDisplaying unapproved session timestamps for ' + str(req_name) + ' between ' + str(start_date) + ' and ' + str(end_date) + ': \n') not_verified_ids = [] for log_id, user_id, work_time, start, end, approved in not_verified: hours = '%.2f' % (work_time / 3600000.0) not_verified_ids.append(log_id) print('Log ID #' + str(log_id) + ' shows ' + str(hours) + ' hours of work starting on ' + str(start) + '.') # allow the user to verify _handle_verify_session(verify_uuid, not_verified_ids) else: print('No unapproved session timestamps found for ' + str(req_name) + ' between ' + str(start_date) + ' and ' + str(end_date) + '.') else: print('No found session information for ' + str(req_name) + ' in the time period of ' + str(start_date) + ' and ' + str(end_date))
def handle_report_command(): ''' Handles the parsing of the report command. This allows the user to print session information about a user and get detailed information about them. ''' req_name = raw_input( 'Name of the user to generate the report for (Ex: stephen)?: ') if req_name is None: print('You must provide the name of the user!') return None user_data = user.get_user(req_name) if user_data is None: print('Unable to find ' + str(req_name) + '. Are you sure they exist?') return None start_date = raw_input( 'The starting date to query for the user (Ex: YYYY-MM-DD)?: ') if start_date is None: print('You must provide a valid start date, such as 2016-11-16') return None end_date = raw_input( 'The ending date to query for the user (Ex: YYYY-MM-DD)?: ') if end_date is None: print('You must provide a valid end date, such as 2016-11-16') return None # attempt to format their input try: s_year, s_month, s_day = _format_date(start_date) e_year, e_month, e_day = _format_date(end_date) except Exception as e: print(e) print( 'Unable to convert dates to representation... Are you sure they are entered correctly?' ) return None # convert to timestamp that SQL knows start_date = datetime.datetime(s_year, s_month, s_day, 0, 0, 0).strftime('%Y-%m-%d %H:%M:%S') end_date = datetime.datetime(e_year, e_month, e_day, 0, 0, 0).strftime('%Y-%m-%d %H:%M:%S') # get all their session logs session_info = user_session.get_session_logs(user_data[0], start_date, end_date) if session_info is not None and len(session_info) > 0: # sort the logs to verified/not not_verified = [] verified = [] for log_id, user_id, work_time, start, end, approved in session_info: if approved == 'None': not_verified.append( (log_id, user_id, work_time, start, end, approved)) else: verified.append( (log_id, user_id, work_time, start, end, approved)) # determine the time that was verified verified_time = 0 for log_id, user_id, work_time, start, end, approved in verified: verified_time = verified_time + work_time # determine the time that was not verified not_verified_time = 0 for log_id, user_id, work_time, start, end, approved in not_verified: not_verified_time = not_verified_time + work_time print('\nUser report for ' + str(req_name) + ' between ' + str(start_date) + ' and ' + str(end_date) + ': \n') verified_hours = '%.2f' % (verified_time / 3600000.0) not_verified_hours = '%.2f' % (not_verified_time / 3600000.0) print( str(len(not_verified)) + ' transactions were NOT VERIFIED totalling ' + str(not_verified_hours) + ' hours.\n') print( str(len(verified)) + ' transactions were VERIFIED totalling ' + str(verified_hours) + ' hours.\n') # determine if they've reached their goal goal_hours = user.get_goal_total(user_data[0]) reached_goal = False failed_by_hours = goal_hours - float(verified_hours) if failed_by_hours <= 0: reached_goal = True print('The monthly goal hours for ' + str(req_name) + ' is ' + str(goal_hours)) if reached_goal: print(str(req_name) + ' has reached their monthly goal!') else: print( str(req_name) + ' was ' + str(failed_by_hours) + ' hours short of their goal!') send_report = raw_input( 'Would you like to me to send this report to the user [Yes/No]?: ') if send_report is not None and (send_report.lower() == 'yes' or send_report.lower() == 'y'): send_user_report(user_data, start_date, end_date, verified_hours, not_verified_hours, goal_hours) else: print('No found session information for ' + str(req_name) + ' in the time period of ' + str(start_date) + ' and ' + str(end_date))
def handle_session_command(): ''' Handles the parsing of the session command. This allows the user to print session information about a user. ''' req_name = raw_input( 'What is the name of the user you wish to list session information (Ex: stephen)?: ' ) if req_name is None: print('You must provide the name of the user!') return None user_data = user.get_user(req_name) if user_data is None: print('Unable to find ' + str(req_name) + '. Are you sure they exist?') return None start_date = raw_input( 'The starting date to query for the user (Ex: YYYY-MM-DD)?: ') if start_date is None: print('You must provide a valid start date, such as 2016-11-16') return None end_date = raw_input( 'The ending date to query for the user (Ex: YYYY-MM-DD)?: ') if end_date is None: print('You must provide a valid end date, such as 2016-11-16') return None # attempt to format their input try: s_year, s_month, s_day = _format_date(start_date) e_year, e_month, e_day = _format_date(end_date) except Exception as e: print(e) print( 'Unable to convert dates to representation... Are you sure they are entered correctly?' ) return None # convert to timestamp that SQL knows start_date = datetime.datetime(s_year, s_month, s_day, 0, 0, 0).strftime('%Y-%m-%d %H:%M:%S') end_date = datetime.datetime(e_year, e_month, e_day, 0, 0, 0).strftime('%Y-%m-%d %H:%M:%S') # get all their session logs session_info = user_session.get_session_logs(user_data[0], start_date, end_date) if session_info is not None and len(session_info) > 0: print('\nDisplaying session info for ' + str(req_name) + ' between ' + str(start_date) + ' and ' + str(end_date) + ': \n') # iterate and print for log_id, user_id, work_time, start, end, approved in session_info: hours = '%.2f' % (work_time / 3600000.0) if approved == 'None': approved = False print('Log ID #' + str(log_id) + ' shows ' + str(hours) + ' hours of work starting on ' + str(start) + '. [Approved=' + str(approved) + ']') else: print('No found session information for ' + str(req_name) + ' in the time period of ' + str(start_date) + ' and ' + str(end_date))