I have developed a script for some operations on docx files. That script takes 5 to 20 seconds to execute the output because of the huge process inside the docx. So on that time the user will get confuse wheter the script is running or not. For that I decided to put an animation and I am done with it. The problem is repetition.
It looks like
I don't want to print the "Please Wait..." as a repeated one. My need here is that "please wait..." should print once until the progress done after that the "process wait..." should disappear. I'm using python 3.
Here my Code:
import glob
from docx import Document
import sys
import time
import threading
class Spinner:
busy = False
delay = 0.1
@staticmethod
def spinning_cursor():
while 1:
for cursor in 'Please Wait...': yield cursor
def __init__(self, delay=None):
self.spinner_generator = self.spinning_cursor()
if delay and float(delay): self.delay = delay
def spinner_task(self):
while self.busy:
sys.stdout.write(next(self.spinner_generator))
time.sleep(self.delay)
def start(self):
self.busy = True
threading.Thread(target=self.spinner_task).start()
def stop(self):
self.busy = False
time.sleep(self.delay)
i = 0
j=0
spinner = Spinner()
spinner.start()
for name in glob.glob('Test_Plan/*.docx'):
doc=Document(name)
for t in doc.tables:
for ro in t.rows:
if ro.cells[0].text=="ID" :
i=i+1
print("Total Number of Tables: ", i)
spinner.stop()
for name in glob.glob('Test_Plan/*.docx'):
doc=Document(name)
for table in doc.tables:
for ro in table.rows:
if ro.cells[0].text=="Automated Test Case" and (ro.cells[2].text=="yes" or ro.cells[2].text=="Yes"):
j=j+1
print("Total Number of YES Automations: ", j)
k = 0
for name in glob.glob('Test_Plan/*.docx'):
doc=Document(name)
for t in doc.tables:
for ro in t.rows:
if ro.cells[0].text=="Automated Test Case" and (ro.cells[2].text=="no" or ro.cells[2].text=="No"):
k=k+1
print("Total Number of NO Automations: ", k)