python_weather/spark/upload_data.py

27 lines
598 B
Python

from hdfs import HdfsError
from client import hdfs_client
from data.data import datas, hdfs_path
def try_upload(filename):
try:
hdfs_client.upload(hdfs_path=hdfs_path, local_path=filename)
print(f"文件 {filename} 上传成功")
except HdfsError as e:
if "already exists" in str(e):
print(f"文件 {filename} 已存在")
return
raise e
def upload_data():
print("上传数据文件")
hdfs_client.makedirs(hdfs_path=hdfs_path)
for file in datas:
try_upload(file)
if __name__ == "__main__":
upload_data()