Skip to content

Commit

Permalink
fix extrator and writer file
Browse files Browse the repository at this point in the history
  • Loading branch information
PhamMinhTan1122 committed Sep 4, 2023
1 parent b40aa86 commit e9bbbd6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="main.py")
parser.add_argument("-d", "--docx", help="filename.docx path(s)")
parser.add_argument("-x", "--xlsx", default="./template.xlsx", help="filename.xlsx path(s)")
parser.add_argument("-x", "--xlsx", default="./template.xlsx", help="filename.xlsx path(s) [default: template.xlsx]")
parser.add_argument("--answer-table", default=False, action=argparse.BooleanOptionalAction, help="--annswer-table if your file has answer table format")
args = parser.parse_args()
# Check input user
Expand Down
5 changes: 3 additions & 2 deletions module/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ def extract_data(docx_filename, excel_file_name, answer_table: bool):
wb.save(excel_file_name)
# Return the data_list as the output of this function
return data_list

def extra_options(data_list, index):
string = ''
match = re.match(r"([A-D]\.) (.*)", data_list[index])
if match:
string = match.group(2)
else:
print("WRONG FORMAT: ", data_list[index])
suggestion = re.sub(r"([A-D])\. *", r"\1. ", data_list[index])
print("PLEASE FIX:", data_list[index], "to", suggestion, "in your docx file")
return string
def extra_questions(data_list, index):
string = ''
match = re.match(r"(^\d+).\s+(.*)$", data_list[index])
if match:
# index_question = int(match.group(1))
string = match.group(2)
return string
return string
1 change: 1 addition & 0 deletions module/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def write_to_excel(data_list, excel_filename):
if len(data_list) >= i + 4:
# Write the question and its options to the worksheet cells
ws[f"A{row}"] = extra_questions(data_list, i) # The question
ws[f"B{row}"] = "Multiple Choice"
ws[f"C{row}"] = extra_options(data_list, i + 1)# Option A
ws[f"D{row}"] = extra_options(data_list, i + 2) # Option B
ws[f"E{row}"] = extra_options(data_list, i + 3) # Option C
Expand Down
Binary file modified template.xlsx
Binary file not shown.

0 comments on commit e9bbbd6

Please sign in to comment.