def _parse_en_file(self): db = MySqlConnector('127.0.0.1', 'fcc_amateur', 'root', 'a') logging.info("Parsing EN.dat") try: en_file = open(f"{self._FILE_DIR}/license/EN.dat") except FileNotFoundError: logging.error("EN.dat not found") return line_count = 0 while True: line_string = en_file.readline().replace('\n', '') line_count += 1 if line_count % self._log_line_interval == 0: logging.info(f"Parsing line {line_count}") line_string = line_string.replace("\\", "\\\\").replace("'", "\\'") line = line_string.split('|') if len(line) <= 1: db.commit() break try: db.execute_query(f"""INSERT INTO en_entities ( fcc_id, call_sign, entity_type, licensee_id, entity_name, first_name, middle_initial, last_name, name_suffix, phone, email, street_address, city, state, zip, po_box, address_attn_line, fcc_reg_number) VALUES ('{line[1]}', '{line[4]}', '{line[5]}', '{line[6]}', '{line[7]}', '{line[8]}', '{line[9]}', '{line[10]}', '{line[11]}', '{line[12]}', '{line[14]}', '{line[15]}', '{line[16]}', '{line[17]}', '{line[18]}', '{line[19]}', '{line[20]}', '{line[22]}') ON DUPLICATE KEY UPDATE `fcc_id`={line[1]} """, False) if line_count % 500 == 0: logging.debug("Committing!") db.commit() except Exception as ex: logging.error(f"Error on line: ```{line_string}```", ex) raise ex en_file.close()
def _parse_ad_file(self): db = MySqlConnector('127.0.0.1', 'fcc_amateur', 'root', 'a') logging.info("Parsing AD.dat") try: ad_file = open(f"{self._FILE_DIR}/application/AD.dat") except FileNotFoundError: logging.error("AD.dat not found") return line_count = 0 while True: line_string = ad_file.readline().replace('\n', '') line_count += 1 if line_count % self._log_line_interval == 0: logging.info(f"Parsing line {line_count}") line_string = line_string.replace('\\', '') line = line_string.split('|') if len(line) <= 1: db.commit() break if line[2] != '': line[2] = f"'{line[2]}'" else: line[2] = 'NULL' try: db.execute_query(f"""INSERT INTO ad_application_detail ( unique_identifier, uls_file_number, application_purpose, application_status, receipt_date) VALUES('{line[1]}', {line[2]}, '{line[4]}', '{line[6]}', {self._mysql_date_str(line[10])}) ON DUPLICATE KEY UPDATE `unique_identifier`={line[1]} """, False) if line_count % 500 == 0: logging.debug("Committing!") db.commit() except Exception as ex: logging.error(f"Error on line: ```{line_string}```", ex) raise ex ad_file.close()
def _parse_vc_file(self): db = MySqlConnector('127.0.0.1', 'fcc_amateur', 'root', 'a') logging.info("Parsing VC.dat") try: ad_file = open(f"{self._FILE_DIR}/application/VC.dat") except FileNotFoundError: logging.error("VC.dat not found") return line_count = 0 while True: line_string = ad_file.readline().replace('\n', '') line_count += 1 if line_count % self._log_line_interval == 0: logging.info(f"Parsing line {line_count}") line_string = line_string.replace('\\', '') line_string = line_string.replace("'", "\\'") line = line_string.split('|') if len(line) <= 1: db.commit() break if line[5] != '': line[5] = f"'{line[5]}'" else: line[5] = 'NULL' try: db.execute_query(f"""INSERT INTO vc_vanity_call_sign ( unique_identifier, uls_file_number, order_preference, requested_call_sign) VALUES('{line[1]}', '{line[2]}', '{line[4]}', {line[5]}) ON DUPLICATE KEY UPDATE `unique_identifier`={line[1]}, `order_preference`={line[4]} """, False) if line_count % 500 == 0: logging.debug("Committing!") db.commit() except Exception as ex: logging.error(f"Error on line: ```{line_string}```", ex) raise ex ad_file.close()
def _parse_hd_file(self): db = MySqlConnector('127.0.0.1', 'fcc_amateur', 'root', 'a') logging.info("Parsing HD.dat") try: hd_file = open(f"{self._FILE_DIR}/license/HD.dat") except FileNotFoundError: logging.error("HD.dat not found") return line_count = 0 while True: line_string = hd_file.readline().replace('\n', '') line_count += 1 if line_count % self._log_line_interval == 0: logging.info(f"Parsing line {line_count}") line = line_string.split('|') if len(line) <= 1: db.commit() break try: db.execute_query(f"""INSERT INTO hd_license_header ( fcc_id, call_sign, license_status, grant_date, expired_date, cancellation_date, reserved) VALUES('{line[1]}', '{line[4]}', '{line[5]}', {self._mysql_date_str(line[7])}, {self._mysql_date_str(line[8])}, {self._mysql_date_str(line[9])}, '{line[11]}') ON DUPLICATE KEY UPDATE `fcc_id`={line[1]} """, False) if line_count % 500 == 0: logging.debug("Committing!") db.commit() except Exception as ex: logging.error(f"Error on line: ```{line_string}```", ex) raise ex hd_file.close()
def _parse_am_file(self): db = MySqlConnector('127.0.0.1', 'fcc_amateur', 'root', 'a') try: am_file = open(f"{self._FILE_DIR}/license/AM.dat") except FileNotFoundError: logging.error("AM.dat not found") return line_count = 0 while True: line_string = am_file.readline().replace('\n', '') line_count += 1 if line_count % self._log_line_interval == 0: logging.info(f"Parsing line {line_count}") line = line_string.split('|') if len(line) <= 1: db.commit() break try: db.execute_query(f"""INSERT INTO am_amateur ( fcc_id, call_sign, operator_class) VALUES('{line[1]}', '{line[4]}', '{line[5]}') ON DUPLICATE KEY UPDATE `fcc_id`={line[1]} """, False) if line_count % 500 == 0: logging.debug("Committing!") db.commit() except Exception as ex: logging.error(f"Error on line: ```{line_string}```", ex) raise ex am_file.close()