from docx import Document
import os
import sys
import re

from textwrap import TextWrapper
#from docx import opendocx, getdocumenttext


def getText():

    document = Document('template.docx')
    for para in document.paragraphs:
        print(para.text)

    #for para in doc.paragraphs:
    #    fullText.append(para.text)

    fullText = []
    for para in document.paragraphs:
        fullText.append(para.text)
    print(fullText[5])    


    for paragraph in document.paragraphs:
        for run in paragraph.runs:
            if run.bold:
                print(run.text)    

    wholedoc=""
    for para in document.paragraphs:
        wholedoc += para.text

    print(wholedoc)

    print("///////////////////////////")

    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("")
   
         
    #for elem in descriptions:
    #    if elem == "Test sequence:":
    #        descriptions.remove(elem)
    #    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)

   #  print(list_paragraph)
   # docu = opendocx('toto.docx')
   # extractedText = getdocumenttext(docu)
    

#>>> string = "abc=123,xyz=456"
#>>> dict(x.split('=') for x in string.split(','))
#{'xyz': '456', 'abc': '123'}


    #return '\n'.join(fullText)    

    #f = open()

   # m = re.compile('Test sequence(.*?)TESTCASE , re.DOTALL ).findall(string)

def main():
    getText()
   
    
if __name__ == "__main__":
    status = main()
    sys.exit(status)
