switch to faster base64 implementation
(60 ms savings on https://askiiart.net/blog/marlin-boot-animations.html, though that has very little graphics)
This commit is contained in:
parent
c541151dff
commit
4edf55cf08
3 changed files with 13 additions and 4 deletions
|
@ -16,6 +16,14 @@ And also fixes any relative links to be absolute.
|
|||
|
||||
## Usage
|
||||
|
||||
Install dependencies first of course
|
||||
|
||||
```sh
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Then run it:
|
||||
|
||||
```sh
|
||||
python3 owug.py 'https://example.com' 'out.html'
|
||||
```
|
||||
|
|
6
owug.py
6
owug.py
|
@ -1,7 +1,7 @@
|
|||
import sys
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
import base64
|
||||
from pybase64 import b64encode_as_string
|
||||
|
||||
|
||||
def absolute_url(url, base_domain):
|
||||
|
@ -33,7 +33,7 @@ for favicon in favicons:
|
|||
url = absolute_url(favicon.attrs['href'], domain_thing)
|
||||
|
||||
mime_type = requests.head(url).headers['Content-Type']
|
||||
as_base64 = base64.b64encode(requests.get(url).content).decode()
|
||||
as_base64 = b64encode_as_string(requests.get(url).content)
|
||||
new_url = f'data:{mime_type};base64,{as_base64}'
|
||||
|
||||
favicon.attrs['href'] = new_url
|
||||
|
@ -43,7 +43,7 @@ imgs = soup.find_all('img')
|
|||
for item in imgs:
|
||||
url = absolute_url(item.attrs['src'], domain_thing)
|
||||
mime_type = requests.head(url).headers['Content-Type']
|
||||
as_base64 = base64.b64encode(requests.get(url).content).decode()
|
||||
as_base64 = b64encode_as_string(requests.get(url).content)
|
||||
new_url = f'data:{mime_type};base64,{as_base64}'
|
||||
item.attrs['src'] = new_url
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
bs4
|
||||
requests
|
||||
html5lib
|
||||
html5lib
|
||||
pybase64
|
Loading…
Reference in a new issue