from countword import count_word
from createcloud import create_cloud
from scanfiles import scan_files
import csv


if __name__ == "__main__":
    filepath = 'files'        # txt 文本存放路径
    scan_files(filepath)
    file_no = input("Please select a file by the number in range:")
    while file_no != 'E':
        if not file_no.isnumeric():  # 判断是否是数字
            print("Input error!")
            file_no = input("Please reselect a file by the number in range:")
        else:   # 读取序号对应的文件名
            with open('filename.csv', 'r', encoding='utf-8') as csvfile:
                reader = csv.reader(csvfile)
                for i in reader:
                    if file_no == i[0]:
                        print('Your choice:', i[1], end='\n')
                        filename = filepath + '\\' + i[1]
                        create_cloud(count_word(filename))
                        scan_files(filepath)
                else:          # 判断file_no是否在范围内
                    file_no = input("Please select a file by the number in range:")
