1 Star 0 Fork 185

kuanina/群晖助手

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
file_helper.py 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
ChallengerV 提交于 2021-02-27 20:58 . 群晖文件助手计划任务文件
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# coding: utf-8
import requests
import os
import sys
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
token = "your token"
base = "http://dsm.flutter.fit"
save_path = (os.path.split(os.path.realpath(__file__))[0] + "/wechat_file/").encode("utf-8")
def report(file):
url = base + "/file/report?token="+token + "&file_id=" + str(file['id'])
data = requests.get(url = url).json()
if data['code']==1:
print("download success:" + save_path + file['file_name'].encode("utf-8"))
def download(file):
print("downloading:"+file['file'])
url = file['file']
data = requests.get(url = url)
if not os.path.exists(save_path):
os.makedirs(save_path)
if data.status_code == 200:
with open(save_path + file['file_name'].encode("utf-8"),"wb") as code:
code.write(data.content)
report(file)
else:
print("download failed")
if __name__ == "__main__":
url = base + '/file/files?token='+token
response = requests.get(url = url).json()
if response['code']==1 :
if len(response['data']) == 0:
print("no file to download")
for file in response['data']:
download(file)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Dart
1
https://gitee.com/kuanina/dsm_helper.git
[email protected]:kuanina/dsm_helper.git
kuanina
dsm_helper
群晖助手
master

搜索帮助