def check_creationtimefile()

in functions/source/Keep-job-alive/keepjobalive.py [0:0]


def check_creationtimefile():
    """
    Creates an 2 list of MRN and PRs.Checks the rows of  FileTime.csv
    If the difference of creation_time and current_time is larger than 10 days,
    it will add MRN and PR them to MRNS and PRS list

    ----------

    Returns
    -------
    list
    """

    key = os.environ['CREATIONTIME_JOBS']
    bucket = os.environ['FEEDBACK_BUCKET']

    s3_client = boto3.client('s3')
    csv_obj = s3_client.get_object(Bucket=bucket, Key=key)
    body = csv_obj['Body']
    csv_string = body.read().decode('utf-8')
    dataframe = pd.read_csv(StringIO(csv_string))
    mrns = []
    prs = []

    # getting the current local time
    current_time = time.localtime(time.time())
    # converting to time stamp
    timestamp = time.mktime(current_time)
    # getting the date from time stamp
    my_date = date.fromtimestamp(timestamp)
    for i in dataframe.index:
        
        if dataframe.loc[i, 'status'] == 'incomplete':
        
            # getting the date from creation_time
            creation_time = pd.Timestamp(pd.to_datetime(df.loc[i,
            'CreationTime'])).to_pydatetime().date()
            
            # finding the number of days difference between
            # current time and creation time
            time_diff = (my_date - creation_time).days
            # if the time difference is larger than 10 days
            if time_diff > 9:
                MRNS.append(dataframe.loc[i, 'MRN'])
                PRS.append(dataframe.loc[i, 'PR'])
    return MRNS, PRS