-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
32 lines (26 loc) · 791 Bytes
/
utils.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
import errno
import logging
import os
import re
def get_logger():
logger = logging.getLogger('app')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
pattern = '%(asctime)s - %(levelname)s - %(message)s'
formatter = logging.Formatter(pattern)
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger
def get_background_url_from_tag(tag):
css = tag.get('style')
pattern = 'background-image: url\((.+)\)'
rgx = re.search(pattern, css)
return rgx.group(1)
def check_if_path_exists(path):
if not os.path.exists(os.path.dirname(path)):
try:
os.makedirs(os.path.dirname(path))
except OSError as exc:
if exc.errno != errno.EEXIST:
raise