-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutil.py
More file actions
36 lines (26 loc) · 783 Bytes
/
util.py
File metadata and controls
36 lines (26 loc) · 783 Bytes
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
import re
from bs4 import BeautifulSoup
from unicodedata import normalize
import unidecode
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},:]+')
def slugify(text, delim=u'-'):
"""Generates an ASCII-only slug."""
result = []
for word in _punct_re.split(unidecode.unidecode(text).lower()):
word = normalize('NFKD', word)
if word:
result.append(word)
return delim.join(result)
def log(*args, **kwargs):
print(*args,
**kwargs,
# file=sys.stderr,
)
def css_find(res, selector):
soup = BeautifulSoup(res.text, "html.parser")
return soup.css.select(selector)
def css_find1(res, selector):
tags = css_find(res, selector)
if tags[:1]:
return tags[0]
return None