#!/usr/bin/env python3
import re
import sys

if __name__ == '__main__':
    packages = {}
    #查找文件(需指定)
    fileName = '1.txt' 
    #获取当前文件夹路径
    curPath = sys.argv[0].replace('run','')
    #提取包名+去重
    file = open(curPath + fileName)
    for line in file:
        regular = re.compile(r'com.\S.\S*')
        strList = re.findall(regular,line)
        if len(strList) > 0:
            for packName in strList:
                if not (packName in packages):
                    packages[packName] = True
        
    #将提取包名写入packName.txt
    try:
        packNameFile = open(curPath + 'packName.txt','w',encoding = 'utf-8')
        for v in packages.keys():
            packNameFile.write(v + '\n')
        print('提取成功 数量:' + str(len(packages.keys())))
    finally:   
        if packNameFile:
            packNameFile.close()
    


    