69 lines
1.5 KiB
Python
69 lines
1.5 KiB
Python
|
import base64
|
||
|
import json
|
||
|
import datetime
|
||
|
from datetime import datetime as dt
|
||
|
|
||
|
import requests
|
||
|
from bs4 import BeautifulSoup
|
||
|
|
||
|
try:
|
||
|
from load import config
|
||
|
except ImportError: config = None
|
||
|
try:
|
||
|
from .utils import *
|
||
|
except ImportError:
|
||
|
from utils import *
|
||
|
|
||
|
|
||
|
headers = {
|
||
|
'user-agent':(
|
||
|
"Mozilla/5.0 (Windows NT 10.0; WOW64) "
|
||
|
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||
|
"Chrome/62.0.3202.9 Safari/537.36"
|
||
|
)
|
||
|
}
|
||
|
|
||
|
|
||
|
def date_parser_helper(days:int, parse:str="%d.%m.20%y"):
|
||
|
return dt.strftime(
|
||
|
dt.now() +
|
||
|
datetime.timedelta(days=days),
|
||
|
parse
|
||
|
)
|
||
|
|
||
|
|
||
|
def docs_parse():
|
||
|
|
||
|
output = {
|
||
|
"data":{},
|
||
|
"another_teacher":None
|
||
|
}
|
||
|
|
||
|
page = requests.get(config.link, headers=headers)
|
||
|
page.encoding = 'utf-8'
|
||
|
|
||
|
soup = BeautifulSoup(page.text, "lxml")
|
||
|
|
||
|
# Это в идеале нужно переписать...
|
||
|
url = image_parser(soup)
|
||
|
with requests.get(url=url, allow_redirects=True, stream=True) as r:
|
||
|
output['image'] = True
|
||
|
output['date'] = 'невозможно получить!'
|
||
|
output['data']['all'] = base64.b64encode(r.content).decode('utf-8')
|
||
|
|
||
|
|
||
|
with open(config.data_file, 'w') as f:
|
||
|
json.dump(output, f, ensure_ascii=False)
|
||
|
f.close()
|
||
|
|
||
|
|
||
|
def get_about_replacements() -> dict:
|
||
|
with open(config.data_file, 'r') as f:
|
||
|
data = json.loads(f.read())
|
||
|
f.close()
|
||
|
return data
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
docs_parse()
|