def process(file): """Attributes needed for the DMARC processing Keyword arguements: file -- location of the DMARC file that has been already received and saved on the local server """ """Unzip the first attached DMARC report""" app = unzip(file, "./") app.extract() unzipped_filenames = app.get_unzipped_filenames() """Parse the DMARC records""" app = parse_dmarc(unzipped_filenames[0], config) app.parser() app.get_report_metadata() app.get_policy_published() app.get_records()
def one_test_expect_assert(comp_data): print( "--- Testing an input stream, which we expect will result in an assertion failure. ---" ) print(f"INPUT STREAM: {comp_data}") try: raw_str = unzip(comp_data) except AssertionError: print("SUCCESS!") print() return except: print( "ERROR: The function throw an exception, but it was not an assertion failure" ) print() return print("ERROR: The function did not throw any sort of exception!") print() return
def one_test(comp_data): print(f'INPUT STREAM: {comp_data}') raw_str = unzip(comp_data) print(f'OUTPUT DATA: "{raw_str}"') print(f'Length comparisons: {len(comp_data)} -> {len(raw_str)}') print()
from getfiles import * from unzip import * filelist = getGzipList(r'H:\BaiduYunDownload\7月份数据', '.gz', '.gzip', '.tgz') for filename in filelist: unzip(reStr, filename)
#从参数获取保存压缩包的路径 #压缩包所在的文件路径 为脚本运行时的第一个参数 basePath = sys.argv[1] #压缩包解压路径 #压缩包的扩展名列表 typelist = '.gz', '.gzip', '.tgz' #压缩文件列表 ziplist = [] #csv文件列表 csvlist = [] #匹配csv文件名的正则表达式 reStr = r'Baoji-cell|Xian-cell|Xianyang-cell|Hanzhong-cell|Tongchuan-cell|Shangluo-cell|Yulin-cell|Yanan-cell|Weinan-cell|Ankang-cell' #mysql连接字符串 mysql_uri = 'mysql+pymysql://root:[email protected]:50014/temp?charset=utf8' #获取指定文件夹basePath 下的所有 '.gz', '.gzip', '.tgz' 文件 保存到ziplist ziplist = getGzipList(basePath, '.gz', '.gzip', '.tgz') #遍历压缩包文件名列表 ziplist for zip in ziplist: #根据正则表达式reStr 匹配 解压缩相应的文件 并把已解压缩的文件路径保存到unzipfiles unzipfiles = unzip(reStr, zip) #遍历unzipfiles 判断csvfile中包含 cell 还是包含 wifi 来判断录入相应的表 for csvfile in unzipfiles: if 'cell' in csvfile: tablename = 'mr_cell' #读取scv文件csvfile,把表格写进mysql中tablename表中 inmysql(mysql_uri, tablename, csvfile)