免费无限空间网盘!!Python使用Requests向免费无限存储国外国内都可以访问网盘给自己的文件夹添加文件

我们在上一篇博文中详细介绍了这个网站,那么今天我们就来用程序来实现如何将本地的文件上传到我们的网盘。因为这个网盘在国外的环境下也可以访问,所以这也可以当做我们的一个传输的中介进行国外网站程序的下载。

关于send.cm使用方法的博客

最终目标

在这里插入图片描述

实现程序

我们首先使用访问我们的网站,接着我们使用我们的密钥进行访问,然后最后用POST上传程序,最后用我们的函数返回网址(下次等我有时间之后我会详细说明)

# 程序名称 : SMDisk.py
# 运行版本 : Python 3.7
# 运行系统 : Windows 10
# 运行需求 : Pyanywhere 本地
# 制作日期 : 2021年3月4日
# 制作人 : ZesenYuan

import requests
import json

def test_file_address(path):
	# 禁止上传的文件格式
	endswith = ["php","pl","cgi","py","sh","shtm","xap","swf","phtml","asax","cer","asa","cgi","php5","php6","php7","pht"]
	# 将列表转换成元组
	endswith_tuple = tuple(endswith)	
	# 获取是否在我们的元组中
	bool_endswith = path.endswith(endswith_tuple)

	# 检测判断
	if bool_endswith == "True":
		endswith_real = "False"
		return endswith_real
	else:
		endswith_real = "True"
		return endswith_real

# 定义一个默认的密钥进行访问
def upload_file_api(file,key = "xxxx"):
	print("检测格式中...")
	endswith = test_file_address(file)
	# 检测我们是否为禁止上传的文件类型
	if endswith == "True":
		print("文件支持...")
	else:
		print("不支持的格式!")
		exit()

	# 定义一个会话,多次访问这个软件
	file_api_session = requests.session()
	# 在访问时候加上我们的密钥
	file_api = file_api_session.get("https://send.cm/api/upload/server?key=" + key)
	print("正在检测密钥...")
	# print(file_api.text)

	# 将我们的响应值转换成文本
	file_api = file_api.text

	# 我们的访问值是json文件格式,所以我们将其转换成Json
	file_api_json = json.loads(file_api)
	print("密钥正确...")

	# 我们取出我们相应的ID值和请求时间,结果
	api_result = file_api_json.get("result")
	api_time = file_api_json.get("server_time")
	api_id = file_api_json.get("sess_id")
	# print(api_result,api_time,api_id)

	# 解析相关代码,构造请求Data表单
	files = {'file':open(file,'rb')}
	upload_data={"sess_id":api_id}
	print("准备文件成功...")

	# 上传代码
	print("开始上传...")
	upload_file = file_api_session.post(api_result,upload_data,files=files)
	upload_file_text = upload_file.text
	print("上传成功...")

	# 转换成我们的Json文件
	upload_file_text_json = json.loads(upload_file_text)
	# 获取列表中的第一项
	upload_file_text_json = upload_file_text_json[0]

	# 获取我们服务器的响应值
	file_status = upload_file_text_json.get("file_status")
	if file_status == "OK":
		# 获取我们的存储链接
		file_code = upload_file_text_json.get("file_code")
		# 组合我们的存储链接
		finally_address = "https://send.cm/"+file_code
	else:
		finally_address = None

	print("最终链接组成成功...")

	# 返回最终的结果
	return finally_address,api_time

website = upload_file_api("C:\\Users\\Administrator\\Desktop\\IDM-Send专用版本.exe")
print(website)

之前我有一个详细讲关于OS检测后缀名的程序,那么建议访问查看其原理

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地摊主老袁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值