uu_pixiv_api / server /resource.py
rogerxavier's picture
Update server/resource.py
f994297 verified
raw
history blame
1.13 kB
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from .utils import headers
class Resource:
def __init__(self, url: str):
self.url = url
self.cutted_str: str
self.cutted_str_save_file = 'subscribe_data_encoded.txt' # 添加一个文件路径存储前得到的 cutted_str
self.previous_cutted_str:str
self._get_resource()
def _get_resource(self) -> None:
try:
request = requests.get(self.url, headers=headers)
self.cutted_str = request.text
with open(self.cutted_str_save_file,'w')as f:
f.write(self.cutted_str)
except Exception as e:
with open(self.cutted_str_save_file,'r')as f:
self.previous_cutted_str=f.read()
print(f"请求失败,使用之前的cutted_str",self.previous_cutted_str)
def get_encoded_data(self) -> str:
try:
return self.cutted_str + ((4 - len(self.cutted_str) % 4) * "=")
except Exception as e:
return self.previous_cutted_str + ((4 - len(self.previous_cutted_str) % 4) * "=")