Files
material-api/web/scripts/unpack_history_data.py
2024-07-10 16:09:59 +08:00

54 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import zipfile
from pathlib import Path
def main(zip_path=r'C:\Users\Administrator\Desktop\材料管理系统模版\造价站近两年价格数据.zip'):
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
for file_info in zip_ref.infolist():
filename = file_info.filename.encode('cp437').decode('gbk')
is_excel = filename.endswith('.xlsx') or filename.endswith('.xls')
is_fuzhou = '福州' in filename
# 地材
# if is_excel and is_fuzhou and '地材汇总/' in filename and '福州市交通工程地方材料价格信息汇总表(数据处理)' not in filename\
# and '混凝土价格' not in filename:
# year, month = get_month(filename)
# print(year, month, filename)
# 调查表
if is_excel and is_fuzhou and '11地市调查表/' in filename and '福建省' not in filename and '通闽公司' not in filename and '-' not in filename:
year, month = get_month(filename)
print(year, month, filename)
target_file_path = f'./{year}-{month}-调查表-福州{Path(filename).suffix}'
with open(target_file_path, 'wb') as f:
f.write(zip_ref.read(file_info))
# 公路局
# if is_excel and is_fuzhou and '4.福州公路' in filename:
# print(filename)
# 交通局
# if is_excel and is_fuzhou and '1.福州交通局' in filename:
# print(filename)
# 网络价格
# if is_excel and is_fuzhou and '网络价格(' in filename and '通闽公司' not in filename and '5.福州' not in filename:
# print(filename)
# 改性剂
# if is_excel and '改性剂和沙钢' in filename :
# print(filename)
# 三明钢铁
# if is_excel and '2.三明钢铁' in filename:
# print(filename)
def get_month(filename):
if '年信息价/' in filename:
year = filename.split('年信息价')[0].split('/')[-1]
month = filename.split('月发布)')[0].split('')[-1]
return year, month
elif '月份地材汇总/' in filename:
year = filename.split('年地材/')[0].split('/')[-1]
month = filename.split('月份地材汇总')[0].split('')[-1]
return year, month
if __name__ == '__main__':
main()