def constructFileName(corp_debtor_name, applicant_or_ipname,
                      dannouncement_or_dateresplan_obj, SOURCE):
    corp_debtor_name_temp = corp_debtor_name.replace(' ', '').replace(
        '.', '').replace('-', '').replace(',', '').replace('&', '').replace(
            '/', '').replace('(', '').replace(')',
                                              '').replace('"',
                                                          '').replace("'", '')
    if len(corp_debtor_name_temp) >= 10:
        corp_debtor_name_temp_ = corp_debtor_name_temp[:10]
    else:
        corp_debtor_name_temp_ = corp_debtor_name_temp
    applicant_name_or_ip_name_temp = applicant_or_ipname.replace(
        ' ', '').replace('.', '').replace('-', '').replace(',', '').replace(
            '&', '').replace('/', '').replace('(',
                                              '').replace(')', '').replace(
                                                  '"', '').replace("'", '')
    if len(applicant_name_or_ip_name_temp) >= 10:
        applicant_name_or_ip_name_temp_ = applicant_name_or_ip_name_temp[:10]
    else:
        applicant_name_or_ip_name_temp_ = applicant_name_or_ip_name_temp
    date_announcement_or_ldaterp_temp = str(
        dannouncement_or_dateresplan_obj).replace('-', '')
    fileName = corp_debtor_name_temp_ + applicant_name_or_ip_name_temp_ + date_announcement_or_ldaterp_temp
    #print(fileName)
    if akmutility.ispublicannounecment(SOURCE):
        results = dbpersistence.checkIfPARecordAlreadyExists(
            corp_debtor_name, applicant_or_ipname,
            dannouncement_or_dateresplan_obj, SOURCE, CURSOR)
    else:
        results = dbpersistence.checkIfIRPRecordAlreadyExists(
            corp_debtor_name, applicant_or_ipname,
            dannouncement_or_dateresplan_obj, SOURCE, CURSOR)
    if len(results) == 0:
        fileName = fileName + PDF_EXTN
        resultsFile = dbpersistence.checkifFileExists(fileName, SOURCE, CURSOR)
        if len(resultsFile) > 0:
            corp_debtor_name_temp_ = corp_debtor_name_temp[:18]
            applicant_name_or_ip_name_temp_ = applicant_name_or_ip_name_temp[:
                                                                             18]
            fileName = corp_debtor_name_temp_ + applicant_name_or_ip_name_temp_ + date_announcement_or_ldaterp_temp
            fileName = fileName + PDF_EXTN
            #print(fileName)
        return fileName
    else:
        duplicateIndex = []
        #print(results)
        for result in results:
            file_Name = result[0].replace(PDF_EXTN, '')
            #print(fileName)
            index = file_Name.find(DUPLICATE_LABEL)
            #print(index)
            if index == -1:
                duplicateIndex.append(0)
            else:
                indexfound = (int)(file_Name[index + 2:])
                duplicateIndex.append(indexfound)
            #print(duplicateIndex)
        maxValue = max(duplicateIndex) + 1
        fileName = fileName + DUPLICATE_LABEL + str(maxValue) + PDF_EXTN
    return fileName
def dbInsert_v0(basic_data_cells, SOURCE):
    if akmutility.ispublicannounecment(SOURCE):
        last_date_submission = basic_data_cells[1].text.strip()
        # get all the different data from the table's tds
        [
            date_announcement_obj, last_date_submission_obj, corp_debtor_name,
            applicant_name, name_ip, address_ip, pa_pdf_link, remarks
        ] = getfieldvalues_pa(basic_data_cells)

        # save into database
        dbpersistence.insert_pa_db(date_announcement_obj, last_date_submission,
                                   last_date_submission_obj, corp_debtor_name,
                                   applicant_name, name_ip, address_ip,
                                   pa_pdf_link, SOURCE, remarks, MY_DB, CURSOR)
    else:
        # get all the different data from the table's tds
        [
            corp_debtor_name, rp_name, date_inv_rplan_obj, date_iss_em_obj,
            last_date_submission_rplan_obj, pa_pdf_link, remarks
        ] = getfieldvalues_irp(basic_data_cells)

        # save into database
        dbpersistence.insert_irp_db(corp_debtor_name, rp_name,
                                    date_inv_rplan_obj, date_iss_em_obj,
                                    last_date_submission_rplan_obj,
                                    pa_pdf_link, SOURCE, remarks, MY_DB,
                                    CURSOR)
def getlastpage(SOUP, SOURCE):
    LAST_PAGE_URL = SOUP.find("li", {"last"})
    #print(LAST_PAGE_URL)
    LP_HREF = LAST_PAGE_URL.find('a').get('href')
    #print(LP_HREF)
    if akmutility.ispublicannounecment(SOURCE):
        PAGE_INDEX = LP_HREF.find("&page=")
    else:
        PAGE_INDEX = LP_HREF.find("?page=")
    #print(PAGE_INDEX)
    LAST_PAGE = int(LP_HREF[PAGE_INDEX + 6:])
    #print(LAST_PAGE)
    return LAST_PAGE
def getkeyvalues(basic_data_cells, SOURCE):
    if akmutility.ispublicannounecment(SOURCE):
        date_announcement = basic_data_cells[0].text.strip()
        date_announcement_obj = akmutility.formatdate_dmy(date_announcement)
        last_date_submission = basic_data_cells[1].text.strip()
        if len(last_date_submission) > 0:
            last_date_submission_obj = akmutility.formatdate_dmy(
                last_date_submission)
        else:
            last_date_submission_obj = ''
        corp_debtor_name = basic_data_cells[2].text.strip()
        corp_debtor_name = akmutility.format_single_quote(corp_debtor_name)
        return str(date_announcement_obj) + str(
            last_date_submission_obj) + corp_debtor_name
    else:
        corp_debtor_name = basic_data_cells[0].text.strip()
        corp_debtor_name = akmutility.format_single_quote(corp_debtor_name)
        rp_name = basic_data_cells[1].text.strip()
        rp_name = akmutility.format_single_quote(rp_name)
        date_inv_rplan = basic_data_cells[2].text.strip()
        date_inv_rplan_obj = akmutility.formatdate_dmonthyear(date_inv_rplan)
        return corp_debtor_name + rp_name + str(date_inv_rplan_obj)