from docx import Document
import os
import sys
import re


def f():

    document = Document("template.docx")
    headings1 = []
    headings2 = []
    list_paragraph = []
    texts = []
    descriptions = []

    for paragraph in document.paragraphs:
        if paragraph.style.name == "Heading 1":
            headings1.append(paragraph.text)
        elif paragraph.style.name == "Heading 2":
            headings2.append(paragraph.text)
        elif paragraph.style.name == "List Paragraph":
            list_paragraph.append(paragraph.text)
        elif paragraph.style.name == "Normal" and paragraph.style.name != "Bold":
            descriptions.append(paragraph.text)

    #filter(None, descriptions)
    #descriptions.remove("plouf")



    #    if elem == "TESTCASE:":
    #        descriptions.remove(elem)
    # if elem == " ":
    #    descriptions.remove(elem)
    # if elem == "":
    #    descriptions.remove(elem)
    #    if elem == "DESCRIPTION:":
    #        descriptions.remove(elem)

    # elif paragraph.style.name == "Normal":
    #     texts.append(paragraph.text)

    # for h, t in zip(headings, texts):
    #    print(h, t)
    print(headings1)
    print(headings2)
    #print(descriptions)

    cpt = 0

    champs_descriptions = []
    champs_module = []

    for i in range(0, len(descriptions) ):

        if "DESCRIPTION" in descriptions[i]:
            champs_descriptions.append(descriptions[i+1])
            #print(descriptions[i+1])

        elif "TESTCASE" in descriptions[i]:
            replaced = re.sub('[TESTCASE:]', '', descriptions[i])
            champs_module.append(  replaced.strip() )
            #print(descriptions[i])

    for i in range(0, len(champs_descriptions) ):
         print(champs_descriptions[i] ,  "   " , champs_module[i] )


s = "Example String"

s = "TESTCASE: default.v"
replaced = re.sub('[TESTCASE:]', '', s)
#replaced = re.sub('[ES]', 'a', s)
print(replaced)

f()