import json
import requests
"""
https://sm.ms/
sm.ms 图床API封装
"""
class UploadToSM:
def __init__(self):
self.headers = {'Authorization': 'xxxxxxxxxxxxxx'}
self.base_url = 'https://smms.app'
def update(self, files):
'''上传文件'''
upload_url = f'{self.base_url}/api/v2/upload'
responce = requests.post(upload_url, files={"smfile": files}, headers=self.headers).json()
print(json.dumps(responce, indent=4))
return responce
def profile(self):
profile_url = f'{self.base_url}/api/v2/profile'
responce = requests.post(profile_url, headers=self.headers).json()
print(json.dumps(responce, indent=4))
return responce
def upHistory(self, page_no:int):
'''上传历史记录'''
upload_url = f'{self.base_url}/api/v2/upload_history?page={page_no}'
responce = requests.get(upload_url, headers=self.headers).json()
print(json.dumps(responce, indent=4))
return responce
def delete(self, hash_str:str):
"""删除文件"""
delete_url = f'{self.base_url}/api/v2/delete/{hash_str}'
responce = requests.get(delete_url, headers=self.headers).json()
print(json.dumps(responce, indent=4))
return responce
UploadToSM().profile()
标签:url,self,json,responce,upload,headers,图床,API,ms
From: https://www.cnblogs.com/cnxue/p/17139277.html