upload_to_webdav.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import handleManager
  2. import tkinter
  3. from tkinter import filedialog
  4. from webdav3.client import Client # 使用pip install webdavclient3 安装
  5. # 加载后
  6. def after_load(event):
  7. return True
  8. # 卸载前
  9. def before_unload(event):
  10. return True
  11. # 判断流程能否处理
  12. def support(event):
  13. return True
  14. webdav_connection_options__jianguo = {
  15. 'webdav_hostname': "https://dav.jianguoyun.com/dav/",
  16. 'webdav_login': "cn_lym@foxmail.com",
  17. 'webdav_password': "atj4hxt8rdeh79aj",
  18. 'disable_check': True, # 有的网盘不支持check功能
  19. }
  20. # todo 连接放全局上下文
  21. client = Client(webdav_connection_options__jianguo)
  22. upload_target_dir = 'spider_cloud/'
  23. def upload(file_path, file_name='____file__name'):
  24. if file_name == '____file__name':
  25. file_name = file_path.split('/')[-1] # 获取要上传的文件名
  26. # 第一个参数为webdav中的路径,可自定义
  27. client.upload(upload_target_dir + file_name, file_path)
  28. # 注:若webdav中已经有同名称文件则会进行覆盖
  29. return upload_target_dir + file_name
  30. 'oss-cn-hongkong.aliyuncs.com'
  31. def handle(faas__request_wrap):
  32. # 取出参数和输入上下文
  33. params = faas__request_wrap[handleManager.const_key_params]
  34. context = faas__request_wrap[handleManager.const_key_context]
  35. # 拿到任务,调用异步执行,后置操作放结果到 mq
  36. if not params['task']:
  37. raise RuntimeError('no task define')
  38. task = params['task']
  39. headers = task['headers']
  40. result = {
  41. 'process_result': {
  42. 'spider': context
  43. },
  44. 'content': content,
  45. 'next-command': next_command
  46. }
  47. return content