File size: 1,132 Bytes
3f92a54
 
 
 
66622b8
3f92a54
 
 
 
 
f994297
 
3f92a54
 
 
66622b8
 
 
f994297
 
66622b8
f994297
 
 
 
3f92a54
 
1f114f5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/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) * "=")