forked from wagtail-nest/wagtail-font-awesome-svg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrape.py
39 lines (30 loc) · 1.05 KB
/
scrape.py
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
32
33
34
35
36
37
38
39
import os
from bs4 import BeautifulSoup
import glob
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
for directory in [
"brands",
"regular",
"solid",
]:
for src_filename in glob.glob(f"fontawesome-free-5.14.0-web/svgs/{directory}/*.svg"):
with open(src_filename, "r") as src_file:
soup = BeautifulSoup(src_file.read(), "html.parser")
tag = soup.find("svg")
tag.name = "symbol"
del tag['xmlns']
filename = os.path.basename(src_filename)
tag['id'] = f"icon-{filename[:-4]}"
target_filename = os.path.join(
BASE_DIR,
"wagtailfontawesomesvg",
"templates",
"wagtailfontawesomesvg",
directory,
filename,
)
target_dir = os.path.dirname(target_filename)
if not os.path.exists(target_dir):
os.mkdir(target_dir)
with open(target_filename, "w") as target_file:
target_file.write(str(tag))